One large vertex OpenGL buffer or many small ones?

Let's say I have 5 objects (objects) with the Render() method. Each object must set its own vertices in the render buffer.

Which of the following two options is better?

  • Use one large pre-allocated buffer created with glGenBuffer , which each object will use (the buffer identifier passed as an argument to the Render methods) by writing its vertices to the buffer using glBufferSubData .
  • Each object creates and uses its own buffer.

If one large buffer is better, how can I correctly convert all the vertices in this buffer (from all entities) with the correct shaders and all?

+6
source share
2 answers

Having multiple VBOs is ok if they are of a certain size. What you want to avoid is to have many small callbacks and very often bind different buffers.

How large the buffers are to avoid excessive overhead depends on many factors, which are almost impossible to even give an empirical rule. Factors that come into play include:

  • Characteristics of equipment performance.
  • Driver efficiency.
  • The number of vertices relative to the number of fragments (triangle size).
  • The complexity of shaders.

As a rule, it makes sense to store similar / related objects that you usually draw simultaneously in the same vertex buffer.

Putting just one buffer seems extreme and can have negative consequences. Say you have a large β€œworld” where you only render a small subset in any given frame. If you go to extremes, you have all the vertices in one giant buffer, this buffer should be available for the GPU for every draw call. Depending on the architecture and method of allocating the buffer, this may mean:

  • Trying to save a buffer in dedicated GPU memory (e.g. VRAM), which can be problematic if it is too large.
  • Map memory to GPU address space.
  • Pin / connect memory.

If any of the above requirements needs to be applied to a very large buffer, but you end up using only a small portion of it to render the frame, there is significant waste in these operations. On a VRAM system, this can also prevent other distributions, such as textures, from being embedded in VRAM.

If rendering is performed with calls that can only access the subset of the buffer specified in the arguments, for example, glDrawArrays() or glDrawRangeElements() , the driver may not be able to make the entire buffer GPU available. But I would not count on it.

+8
source

It is easier to use one VBO buffer object (vertex buffer object) with glGenBuffer for each object you have, but these are not always the best things to do, it depends on usage. But in most cases, this is not a problem for 1 VBO for each object, and rendering is rarely affected.

Good information can be found at: Best OpenGL vertex specifications.

+1
source

Source: https://habr.com/ru/post/976192/


All Articles