I'm trying to switch between the rendering of two different scenes as fast as possible using OpenGL.
For all my OpenGL related stuff I wrote a wrapper-class which provides a quite easy way of adding and updating data. Based on the added data it automatically creates the variable naming for the shader. In the past I always used just one instance of this OpenGL class but now I'm trying to use two of them. (Each instance has its own shader program.)
When I do something like:
OpenGLInstance1.AssignModel(*MyModel1);
it automatically adds data and writes into the shader code:
// per vertex attributes
layout (location = 0) in vec3 position;
layout (location = 1) in vec3 normals;
layout (location = 2) in uvec4 BoneIDs;
layout (location = 3) in vec4 Weights;
// per instance attributes
layout (location = 4) in mat4 CameraMatrix; //dynamic
layout (location = 8) in mat4 ProjectionMatrix; //dynamic
When I try to do this a second time with an other OpenGL-Class instance and Model:
OpenGLInstance2.AssignModel(*MyModel2);
I get:
// per vertex attributes
layout (location = 12) in vec3 position;
layout (location = 13) in vec3 normals;
layout (location = 14) in uvec4 BoneIDs;
layout (location = 15) in vec4 Weights;
// per instance attributes
layout (location = 16) in mat4 CameraMatrix; //dynamic
layout (location = 20) in mat4 ProjectionMatrix; //dynamic
But since the GL_MAX_VERTEX_ATTRIBS gives a maximum number of attributes of 16, this is not possible.
Question 1
Each VAO (vertex array object) has some VBO (vertex buffer object) assigned. Is the location indexing of the VBO just in the scope of each VAO (starting again from zero for each VAO) or is it independent of the VAO?
Question 2
Do you have a suggestion how to work around this problem while keeping the implementation as generic, reusable and scalable as possible? (Just some general hints, I don't want to bother you with details.)