Skip to content

Instantly share code, notes, and snippets.

@drdrsh
Last active June 26, 2017 16:11
Show Gist options
  • Save drdrsh/b8d46e281135aa470cfcb3c089ef48ac to your computer and use it in GitHub Desktop.
Save drdrsh/b8d46e281135aa470cfcb3c089ef48ac to your computer and use it in GitHub Desktop.
A templated function to convert C++ types to OpenGL types
template <typename T> GLenum typeToGL() {
if (typeid(T) == typeid(float)) {
return GL_FLOAT;
};
if (typeid(T) == typeid(double)) {
return GL_DOUBLE;
};
if (typeid(T) == typeid(char)) {
return GL_BYTE;
};
if (typeid(T) == typeid(unsigned char)) {
return GL_UNSIGNED_BYTE;
};
if (typeid(T) == typeid(int)) {
return GL_INT;
};
if (typeid(T) == typeid(unsigned int)) {
return GL_UNSIGNED_INT;
};
if (typeid(T) == typeid(short)) {
return GL_SHORT;
};
if (typeid(T) == typeid(unsigned short)) {
return GL_UNSIGNED_SHORT;
};
return GL_INVALID_ENUM;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment