OpenGL VAO VBO shader confusion

I am writing a renderer and am at the point to choose the final way to control the vao / vbo / shader. On the Internet, I found some very conflicting information about what is actually recommended. Now the idea is this:

-One VBO saves all cells in sequence.

-Per "shader mapping" creates a VAO to store a specific pointer mapping in the VBO. ("shader mapping" consistent across all different shaders with the same inputs)

then sort the objects using "shader mapping" and rendering using offsets in the main VBO, thereby minimizing shader and VAO switches. Something like:

for(shaders by mapping)
    bindVAO(); //set pointers
    for(shader)
        for(entity using shader)
            entity.setUniforms();
            drawArrays(entity.offset, entity.size);

      

Since this will involve a significant amount of refactoring, I would like to ask if this is the optimal solution. I'm also wondering if it is possible to have multiple interleaved formats in one VBO.

+3


source to share


1 answer


Reusing VAOs with different shaders is good practice.

However, switching VBOs and VAOs is usually very cheap compared to switching shaders. This means that in your case, the bottleneck is likely to be switching the shader anyway.

For the same reason, placing all of your grids in the same VBO will probably be overkill (but it doesn't hurt if you don't need to update it).



Also, depending on what you are doing, sorting the draw calls by depth / blend state or by depth (usually front to back) may be a better solution than sorting by each shader. But this needs to be measured carefully. (More on sorting here ).

Edit: To answer your second question, it might be possible to place vertices of different types in the same VBO, although I've never tried it. This is tricky because you need to be careful about vertex alignment. When called glDrawArrays(mode, first, count)

, for example, you need to compute first

to first * sizeof(YourCurrentVertexType)

equal the offset at which you put your data into the VBO. If anything, this is probably not a good idea. Some drivers may not appreciate this, and as I said above, it probably won't make a noticeable difference.

+4


source







All Articles