I am using GLSL shaders in a small Java OpenGL project I am making, and I am trying to come up with a well-written object-oriented way of organising my code. So far, I have a class called Model
, which can contain multiple meshes, each of which has its own texture and material (a material being a set of parameters to describe ambient, diffuse, specular, blending, etc.). In order to achieve this, I understand that I could pass uniform variables to the shader every time I need to change material. However, the drawing takes place in the model's draw()
method. Does that mean that each instance of the Model
class needs to have a particular shader associated with it?
Also, I have a Camera
class, which produces a matrix that will transform vertices simulate the camera's pitch, yaw, and position. This matrix then needs to uploaded to the shader as the view matrix. Doesn't that mean that I need to upload this matrix to every shader that I use? So if each Model
can have its own shader, how can I upload the camera's view matrix to all of them? And even so, isn't it inefficient for every single model to have its own shader? If you wanted to draw a certain model lots of times, then you would be use()
ing the shader and uploading a matrix to the shader every time you drew it.
I'm really struggling to come up with an object-oriented solution that links multiple shaders, multiple objects and multiple materials. Any help is appreciated.