thanks, I am glad you like it :)
just wanted to add that in my code I actually have one more enum in opengl_traits specializations GL_SIZE:
template<>
struct opengl_traits<unsigned int>
{
enum {GL_TYPE = GL_UNSIGNED_INT, GL_SIZE = 1};
};
template<>
struct opengl_traits<unsigned short>
{
enum {GL_TYPE = GL_UNSIGNED_SHORT, GL_SIZE = 1};
};
template<>
struct opengl_traits<float>
{
enum {GL_TYPE = GL_FLOAT, GL_SIZE = 1};
};
and in renderer class:
template <class T>
void vertexSource(const T* ptr, GLsizei stride = 0)
{
glVertexPointer(opengl_traits<T>::GL_SIZE, opengl_traits<T>::GL_TYPE, stride, ptr);
}
this of course doesn't look good at first but consider this :
template <class T>
class Vec3
{
T x, y, z;
};
template <class T>
struct opengl_traits<Vec3<T> >
{
enum
{
GL_TYPE = opengl_traits<T>::GL_TYPE,
GL_SIZE = 3
};
};
this ONE templated traits definition enabled Vec3<T> deduction support for all previously defined basic types, so now:
vector<Vec3<float> > vertices;
vertexPointer(&vertices[0]);
voila :)
in fact I have a few traits more, for 2/4 d vectors and colors
|