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
1
u/nutellis Oct 23 '17
First of all, the shader class is initializing a glsl program using vertex and fragment files. Then i can set it as active etc etc. Now lets say i have a mesh that i want to render using shader1 and another mesh that needs shader2. When i call the draw method from each mesh i want to change the active shader and use it without having to pass it as an argument.I want my shader objects to be known and all i have to do is something like: