Reputation: 312
I couldn't find anything about this so here goes: What I'm trying to do is make a generic game engine, I want to be able to load any 3D object and apply any shader to that model.
I'm at the point where I need to know where the vertex attributes in the shader are so I can feed them to glVertexAttribPointer
, However, glVertexAttribPointer
takes as input the location of the attribute.
Different shaders could have different locations for the vertices. Is there a way to query the attributes in a shader and store them in a list in c++?
Post Answer: I've found the following answer that explains it in more detail.
Upvotes: 2
Views: 308
Reputation: 22168
You can query active shader attributes by using glGetActiveAttrib
. In combination with glGetAttribLocation
, you can build up such a lookup table.
But even with this lookup table, you'd have to use a different VAO for each combination of mesh and shader. I suggest you go the other way round and define which attribute location belongs to which attribute. You can either enforce that with glBindAttribLocation
during shader compilation, or you use layout qualifiers (layout(location = ...)
) in the shader. Using this, you will be able to use the same VAO with all of your shaders.
Upvotes: 5