Hey everyone,
I recently started programming with openGL and managed to create a model class and draw textured models in virtual space.
Now I want to start drawing all the graphics that my game includes. I came up with several thoughts about where and when to draw, but I am highly uncertain about the difference in performance of each approach:
First Approach: Having a “Unit” Class, which has a “Model” variable. The Class has a draw() function, that draws the Model at the Position specified in Unit. Within the Game loop i call “draw()” for every Unit in a vector container (c++).
Issues with this: First of all, I have to access “Model” via Unit, wouldnt it be much faster to have a vector that only contains Model objects? Second: Since I want to use more than one shader, I would have to set the shader in each and every draw method, since I dont know too much about the order of Units in the vector.
Second Approach: Having Vector containers for each shader in the class of the gameloop: calling the shader and then looping through all the models that should be drawn with the shader. Reduces the Shader calls, but on the other hand makes it necessary to loop through all objects for each shader. Also makes all the render calls in the main loop and not all over the place, but i dont know if that makes any difference regarding performance?
Is there some kind of recommendet best practice? Id really appreciate your help!