The base OpenGL API quickly becomes cumbersome and unmaintainable for large projects, so I always find it necessary to abstract the OpenGL API. This is simple with buffers, shaders, windows, textures, etc. The problem comes when trying to merge these aspects. Take a hypothetical class, object.
Code:
The complication comes in when trying to use shaders. At minimum, this object class will need to know relevant attribute locations, texture locations and bindings, and any other necessary uniforms. One solution is to completely control the shader program within the object class, but this is quite inflexible, making things like lighting impossible, or at least inelegant.
How can I elegantly and efficiently abstract the OpenGL API, distinguishing objects and textures from shader programs? What sort of paradigm is, in your opinion, the most maintainable and flexible for use with OpenGL? If the answer is to just not abstract it, how do make your code readable and maintainable?
I appreciate all replies; I'm asking for opinions, as there is not one solution for every situation.
Code:
class object
{
public:
void attach_vertices(T points);
void attach_texture(texture t);
void draw();
};
The complication comes in when trying to use shaders. At minimum, this object class will need to know relevant attribute locations, texture locations and bindings, and any other necessary uniforms. One solution is to completely control the shader program within the object class, but this is quite inflexible, making things like lighting impossible, or at least inelegant.
How can I elegantly and efficiently abstract the OpenGL API, distinguishing objects and textures from shader programs? What sort of paradigm is, in your opinion, the most maintainable and flexible for use with OpenGL? If the answer is to just not abstract it, how do make your code readable and maintainable?
I appreciate all replies; I'm asking for opinions, as there is not one solution for every situation.