r/GraphicsProgramming • u/nutellis • Oct 23 '17
How about using shaders as singletons ?
I want to have a getActiveShader() method so it will return the active shader(custom class) and use it with my playerComponent or anything that needs to be rendered. I was thinking to use singletons to do that so that the shader can be accessed on the fly from everywhere. I am a bit confused though and i am not really sure if i am on the right track here. Any thoughts on the subject? Using Opengl 3.3 .
0
Upvotes
4
u/Rusky Oct 23 '17
OpenGL already has the concept of an "active shader"-
glUseProgrampersists across draw calls. What would you be using your custom shader class for?Further, it's generally not a great idea to run a lot of custom rendering code per entity anyway. You want everything in the form of a "drawable" type, as pure data that you can sort and filter. This lets you more easily minimize state changes, run multiple rendering passes, etc.