OpenGL buffers - Stride vs Tightly packed

4.9k views Asked by At

What are the pros and cons for using strided vertex buffers vs tighly packed buffers for each attribute? What I mean is for instance:

Stride: xyzrgb xyzrgb xyzrgb

Tight: xyzxyzxyz rgbrgbrgb

At first glance it might look like you easily can change the size when using stride, but the content of the vertex buffer is deleted when you reallocate it with glBufferData().

For me it seems best to use the tight model since position, color, and texcoords might come from different arrays in the local memory and because there is no strided buffer data function; you must copy all the arrays into an interleaved buffer before uploading or use one glBufferSubData() per vertex per attribute (terrible idea I guess).

There seems to be common practice to use interleaved buffer (stride). Why is that? Anything I am missing here?

1

There are 1 answers

0
Full Frontal Nudity On BEST ANSWER

I think it is common to have an interleaved buffer because this is easier to create (involves less buffers, more intuitive) and is supposedly faster (because of memory access patterns or something similar), the big advantage of tightly packing is the ability to update only the data you need to update, resulting in faster updates. Most OpenGL tutorials teach about VBO by drawing static meshes, which don't need updates and so benefit from interleaved data.

General opinion seems to be: Interleave as much as possible, split when needed.

See: How does interleaved vertex submission help performance?

And: Performance gain using interleaved attribute arrays in OpenGL4.0

See also: http://www.opengl.org/wiki/Vertex_Specification_Best_Practices

Which states directly:

"How much interleaving attributes helps in rendering performance is not well understood. Profiling data are needed. Interleaved vertex data may take up more room than un-interleaved due to alignment needs."