I'm developing an OpenGL application and I'm trying to make ShaderPrograms and VAO's independent of each other. Saying independent I mean that both ShaderProgram and VAO can have different set of attributes.
While creating new ShaderProgram I explicitly bind list of known attributes to predefined locations even if shader does not use them.
BindAttributeLocation(program, StandardAttribute.Position, PositionAttributeName);
BindAttributeLocation(program, StandardAttribute.Color, ColorAttributeName);
BindAttributeLocation(program, StandardAttribute.Normal, NormalAttributeName);
BindAttributeLocation(program, StandardAttribute.TexCoord, TexCoordAttributeName);
BindAttributeLocation(program, StandardAttribute.Tangent, TangentAttributeName);
Pretty same thing I'm trying to do with VAO, but if mesh does not contain data for attribute I want to set default value:
vao.Bind();
if(mesh.Color == null) {
DisableVertexAttribArray(attribute);
VertexAttrib4f(attribute, 1, 1, 1, 1);
}
else {
EnableVertexAttribArray(attribute);
buffer.Bind();
BufferData(mesh.Color);
VertexAttribPointer(attribute, ...);
}
This code seems to be working (so far), but I'm not sure if this is a correct approach. Where do VertexAttrib4f stores data: in VAO, or is it context global state and I need to reset it after each draw call?