This article will help you understand the building blocks of batch rendering.

Prerequisites: Basics of Graphics Pipeline. Understanding of OpenGL calls.

The usual way to draw multiple objects on screen is to submit a vertex buffer, set uniforms, issue a draw call, and repeat this process for all the objects.

With this approach, as the number of objects/meshes to be rendered increases the number of draw calls also increase. This might lead to performance bottlenecks when rendering large number of objects.

In the above process, we tend to underutilise the space on the GPU by storing less vertex data. What if we could store more vertex data and issue a single draw call. This is the gist of batch rendering!

The idea behind batch rendering is to bunch the vertex data together into a single vertex buffer and issue a single draw call.

While it is easy to implement a batch renderer with just vertex positions/colors (by setting them inside a vertex buffer itself), we need to do some more thinking while implementing a batch renderer that supports batching a dynamic vertex buffer, where different meshes use different textures.

Question to ask while implementing a batch renderer:

All the above questions can be solved by feeding necessary information required by the shader into the vertex buffer itself. Then in the shader, use that information as an attribute.

An example would be:

If I want to use different textures for batched meshes:

For dynamic geometry:

Basic idea: Dynamically change contents of vertex buffer. For this we can keep a maximum size allocated once, and keep changing the contents every frame.