I'm making some test with OpenGL and I've got a problem with my application design. Currently, I've got something like that in pseudo code:
// Ask to draw a given scene.
renderer->drawScene( myScene, myCamera );
// Here is what I do in the renderer
for( auto& mesh : scene->getElements() )
{
this->draw(mesh);
}
// And here is what my draw method do.
// First geometry stuff.
context->setVertexFormat( mesh->geometry->vertexFormat );
context->setVertexBuffer( mesh->geometry->vertexBuffer ); // Use VAO is available.
context->setIndexBuffer( mesh->geometry->indexBuffer );
// Second, material stuff.
context->setProgram( mesh->material->program );
mesh->material->program->setParameter( "model", mesh->transform->position );
mesh->material->program->setParameter( "uCamera", camera.matrix );
context->setBlendMode(mesh->material->blendMode);
// Finally draw.
context->draw( mesh->material->drawingMode, mesh->geometry->indiceCount );
The problem is present with shader attributs, by exemple from main loop:
int main()
{
while()
{
// I want change texture offset for the mesh N°7, that will change it for every mesh.
myMesh7->material->program->setParameter("offset", 15.f);
renderer->DrawScene(myScene, myCamera);
}
}
How can I have a flexible design? A Shader/Program is shared with others meshes, so in the case where I would change "color" or "offset" attribute in my shader for only one mesh it's not possible. How can I handle that?
(I don't think it will be good to copy somewhere shader attributs per mesh)
Thanks for your help