Last active
September 26, 2019 23:50
-
-
Save emctague/a60bfe0cf511e069599931c1de401bb6 to your computer and use it in GitHub Desktop.
OpenGL Attrib Pointers Template System
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Base case of OpenGL attrib pointer template tool. */ | |
template<typename P, typename T> | |
inline void attribPointers(int n = 0, size_t s = 0) { | |
glEnableVertexAttribArray(n); | |
glVertexAttribPointer(n, sizeof(T)/sizeof(float), GL_FLOAT, GL_FALSE, sizeof(P), (void*)s); | |
} | |
/** Applies all OpenGL attrib pointers given as type arguments (first argument is vertex class). */ | |
template<typename P, typename T, typename S, typename ...Args> | |
inline void attribPointers(int n = 0, size_t s = 0) { | |
attribPointers<P, T>(n, s); | |
attribPointers<P, S, Args...>(n + 1, s + sizeof(T)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Your vertex type | |
struct Vertex { | |
glm::vec3 position; | |
glm::vec3 normal; | |
glm::vec2 uv; | |
}; | |
// Wherever you need to define attribs, you do this: | |
attribPointers<Vertex, glm::vec3, glm::vec3, glm::vec2>(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment