glVertexAttribBinding()

Started by
0 comments, last by 21st Century Moose 11 years, 7 months ago
http://www.opengl.or...n#Vertex_format


my question: why? what's the benefit of Example 2 ?
what's the difference of binding a buffer vs binding a buffer to a binding point ?
and is the vertex buffer binding from glBindVertexBuffer a VAO state ?

to render multiple vbo's with the same vertex layout i could use

[font=courier new,courier,monospace]glVertexAttribFormat(...)[/font]
glVertexAttribBinding(..., 0);
glVertexAttribFormat(...)
glVertexAttribBinding(..., 0);
glBindVertexBuffer(0,...) / draw / glBindVertexBuffer(0,...) / draw ... right ?

can i do the same with VertexAttributePointer ?
glVertexAttribPointer(...) glBindBuffer(...) draw() glBindBuffer(...) draw()


Example1
[source lang="java"]
glBindBuffer(GL_ARRAY_BUFFER, buff);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<void*>(baseOffset + offsetof(position, Vertex)));
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<void*>(baseOffset + offsetof(normal, Vertex)));
glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), reinterpret_cast<void*>(baseOffset + offsetof(color, Vertex)));[/source]

Example2
[source lang="java"]
glBindVertexBuffer(0, buff, baseOffset, sizeof(sizeof(Vertex)));
glVertexAttribFormat(0, 3, GL_FLOAT, GL_FALSE, offsetof(position, Vertex));
glVertexAttribBinding(0, 0);
glVertexAttribFormat(1, 3, GL_FLOAT, GL_FALSE, offsetof(normal, Vertex));
glVertexAttribBinding(1, 0);
glVertexAttribFormat(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, offsetof(color, Vertex));
glVertexAttribBinding(2, 0);[/source]
Advertisement
For trivial cases where you've one vertex format per vertex buffer there's no benefit - it's just more code.

To see the benefit you should scoot over to http://www.opengl.org/registry/specs/ARB/vertex_attrib_binding.txt where the rationale behind this functionality is provided:
This extension allows the application to change the mapping between attributes and bindings, which can make it more efficient to update vertex buffer bindings for interleaved vertex formats where many attributes share the same buffer.

This extension also separates the vertex binding update from the vertex attribute format update, which saves applications the effort of redundantly specifying the same format state over and over.[/quote]

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This topic is closed to new replies.

Advertisement