0
\$\begingroup\$

I'm trying to create a renderer generic enough so that it can dynamically set uniforms for a variable number of shaders.

For instance, say mesh A uses shader A; mesh B uses shader B.

"shader A" has the following uniforms:
- matrix4 "mat1"
- vector3 "pos"

"shader B" has the following uniforms:
- matrix4 "model"
- vector4 "color"
- texture "tex"

I don't want to put the OpenGL uniform setting code directly in the mesh's class. I'd like to pass the necessary data to the renderer, and have it take care of the OpenGL stuff.

The renderer should be generic enough to able to correctly set the uniforms for any mesh that uses shader A or B (or any other shader for that matter).

What is the best design pattern to accomplish variable uniform setting like this?

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.