For my engine I need to render a bunch of different meshes, including an alpha pass.
Currently the way I do it is fairly straight-forward:
- I have one big vertex and index buffer in which I load in all my mesh data. During the render phase I use this to "instance" my geometry.
- I have frustum culling to neglect scenery that doesn't need to be drawn
- During the update part of the game-loop, I create a render-queue, which sorts the meshes so they can be drawn more efficiently
- At render-time, I bind the large mesh-buffer one time before drawing any meshes
- Drawing is done by going through the render-queue. I bind the correct texture_2D_Array for the mesh and I draw the mesh with glDrawElementsBaseVertex. Thus I just pass in the correct index to draw a certain mesh, using one and the same buffer (instancing)
- I disable the buffer at the end of the render loop
- After all opaque objects were rendered, I do the alpha pass in a similar way, also using the big buffer. Although in this case I cannot sort them mesh per mesh, since they are sorted by depth.
- I use one and the same shader-program for drawing all these meshes, and only one sampler2DArray at texture index 0. The array contains a diffuse map and an optional bumpmap.
I'm finding that with the current setup I'm not quite getting the performance I'd like to get. Therefore I'm hoping to receive some tips on how this sort of mesh-rendering problem is usually tackled by more experienced programmers. For example, is it common-practise to use just one shader-program for rendering all meshes? Or is there a much more efficient way that would remove the need to always re-bind the correct texture when switching between meshes?
Any suggestions are very welcome!