PDA

View Full Version : Multiple buffer in one vbo



pommeC
02-19-2018, 04:53 AM
Hello, I remember with webgl I was able to put multiple buffer inside a vbo and and point my buffers with vertexAttribPointer but for opengl I don't know how to do. In the man page I can read :
Size "Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4. Additionally, the symbolic constant GL_BGRA is accepted by glVertexAttribPointer. The initial value is 4."

does it means I can only put 4 vertex data inside a vbo ?

thanks in advance.

Dark Photon
02-19-2018, 06:25 AM
Hello, I remember with webgl I was able to put multiple buffer inside a vbo and and point my buffers with vertexAttribPointer but for opengl I don't know how to do.

That works just fine in OpenGL as well. I assume by "buffers" you mean blocks of vertex attribute data used in a single draw call (e.g. glDrawArrays(), glDrawElements(), etc.).

Just provide the appropriate byte offset into the bound ARRAY_BUFFER object in the "pointer" parameter: glVertexAttribPointer (https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glVertexAttribPointer.xhtml).


In the man page I can read :
Size "Specifies the number of components per generic vertex attribute. Must be 1, 2, 3, 4. ...

That's just the number of components in the data for a single vertex attribute binding (e.g. 4 for a vec4).


does it means I can only put 4 vertex data inside a vbo ?

No. It means, in a single vertex attribute binding (to be used by a draw call), the maximum number of components the value you provide for that attribute can have is 4. This is basically the vector dimension of the attribute. For instance, for float components, 1 = float, 2 = vec2, 3 = vec3, 4 = vec4. This (in combination with the component type) limits how much data can be provided for a single vertex on that single attribute for a single draw call.

However...


you have more than 1 attribute you can provide per draw call (16+ is common here),
you can encode as many vertices as you want in each attribute list, and beyond that
you can store the attribute data for multiple draw calls in a single VBO alongside each other.


The latter is what I think you're calling "multiple buffers".