Really, you're thinking about this like a C programmer. You're using C++, so solve it the way a C++ programmer would. With a traits class:
struct VertexArrayObjectTraits
{
typedef GLuint value_type;
static value_type Create();
static void Destroy(value_type);
};
Like a proper C++ traits class, we have each object declare it's own value_type
. This will allow you to adapt it to OpenGL objects that don't use GLuint
s, like sync objects (though the Create/Destroy interface wouldn't be good for them anyway, so you probably shouldn't bother).
So you write one traits class for each type of OpenGL object. Your Create
and Destroy
functions will forward the calls on to the C API appropriately.
After doing that, all you need is a RAII-wrapper around those interfaces:
template<typename T>
class OpenGLObject
{
public:
OpenGLObject() : m_obj(T::Create()) {}
~OpenGLObject() {T::Destroy(m_obj);}
operator typename T::value_type() {return m_obj;}
private:
typename T::value_type m_obj;
};
An OpenGLObject<VertexArrayObjectTraits>
would hold a VAO.