I have an OpenGL renderer which has a Scene member variable. The Scene object can contain N SceneObjects. I use these SceneObjects for storing the vertex position and any transforms. My question is, where should shaders be stored in this arrangement? I guess they need to be in a central location because multiple objects can use the same shader. But then each object needs access to the shader because it needs to set attributes into the shader. Does anyone have any advice?
You should have a shader pool where all shaders are stored. Once the pool is filled, objects are bound with these shaders (think "bound" as object-references-shader.) Many
Then, for each
Whenever you load a new object, just bind it with the shader already found in the pool. If you're not preloading shaders and it's the first time you're using the shader, add it into the pool. You should also delete shaders from the pool if you're not going to use them anymore (i.e. counting references.)