Search code examples
opengl-esvertex-buffer

Multiple draw calls with single vertex/index buffer?


I want to imlement simple bullet trail (in OpenGL-ES 2-3) system that will allow use different textures or materials for different trails, so it means, that that trails meant to be rendered in different draw calls and each vertex can be modified right before rendering.

Actually, I don't know, how much draw calls will be done in each update, and how much vertices will be passed to this draw call, so I trying to use single vertex buffer and single index buffer for all trails, and fill vertex buffer regions with different trails data every frame. Index buffer filled with simple (0, 1, 2, 3, 3, 4, 4, 5, 6....) values once and won't change anymore.

Could you advice some best practices, how to do this? Can I make draw calls with different render states and different vertex regions for each batch? What indices regions should I use for every draw call? Must index offset take in account vertex offset or maybe indices are applied to vertex region instead of whole buffer, so I can set index buffer offset to 0 for every draw call? Or, maybe, I make it totally wrong, and should do something else?

Thanks!


Solution

  • Ok, so how I made it work:

    1. I still use single big buffer for all batches

    2. For every batch I map just part of buffer (new part for every batch) and change data in this part.

    3. Indices must take in account offset of this part. So, when you render part of buffer with 4th, 5th, 6th, 7th vertices, you have to use part of index buffer with {4, 5, 6, 7} data.