PDA

View Full Version : Vertex Array Object Rendering Questions



Teamworkguy2
09-30-2012, 08:59 PM
Windows 7 - 64bit - GTS 450 (driver verions 8.17.12.9610)
Open GL 4.2
Learning Area: VAO usage

1. What happens when you rebind the currently bound VAO with glBindVertexArray()? Is there a performance cost to rebinding the current VAO?
(I have heard that there is a large performance cost to bind a different VAO [http://www.opengl.org/wiki/Vertex_Rendering] but what about rebinding the same VAO).


2. When drawing with glDraw*Range*BaseVertex(), should 'start' and 'end' be calculated with or without 'basevertex' taken into account?
(spec [http://www.opengl.org/wiki/GLAPI/glDrawRangeElementsBaseVertex] doesn't seem to have information on this question).

In short, does the documentation mean that Open GL adds 'basevertex' to the 'start' and 'end' indices or do I need to add 'basevertex' to 'start' and 'end' manually before calling glDraw*Range() to help the driver optimize glDraw*Range() calls?

For example:
Imagine that the indices from different meshes are combined, many of the indices will have the same value, but different meanings, which is solved by keeping a baseIndex with each mesh and using it to call gl*Draw*BaseVertex.
Each mesh's index offset is saved so that multiple unrelated meshes can be rendered with one VAO.

vertices = {0,0,0, 0,0,0, 0,0,0, 0,1,-2, -1,-1,-2, 1,-1,-2}
indices = {0,1,2, 0,1,2 }
// Assuming glBind(GL_ELEMENT_ARRAY_BUFFER, ...) is bound and the correct VAO is bound with correct enabled vertex attributes
glDrawRangeElementsBaseVertex(GL_TRIANGLES, 0?, 2?, 3, GL_INT, NULL, 3); // Last parameter is 'basevertex'

Should 'start' and 'end' be 0 and 2 or should they be 3 and 5 since those are the actual vertex indices that they are trying to refer to?

Alfonse Reinheart
09-30-2012, 09:55 PM
What happens when you rebind the currently bound VAO with glBindVertexArray()? Is there a performance cost to rebinding the current VAO?

There's no way to know for certain. But I do know the cost of not rebinding the same VAO. That cost is 0. 0 is less than or equal to the cost of rebinding the VAO.

So don't do it.


When drawing with glDraw*Range*BaseVertex(), should 'start' and 'end' be calculated with or without 'basevertex' taken into account?

Allow me to quote from the page you linked to:


all values in the array indices​ must lie between start​ and end​, inclusive, prior to adding basevertex​.

Emphasis added.

Teamworkguy2
10-01-2012, 07:51 PM
Thanks for the enlightenment on question one.
Sorry about question two, I was not thorough enough when reading that page.
Thank you so much for your time and experienced advice.