Vertex-buffers and vertex-program

I modified my code to use vertex buffers instead of vertex arrays. But when combining glBindBuffer and glVertexAttribPointer performance drops from 28 to 5 frames on my geforce3, has 5 frames on a Ti4600 (didn’t test the array-version) and improved from 60 to 80 frames on an ATI 9500 pro card.

using vertex-buffers for static objects (ie not shaded objects) improved performance on all cards (terrain).

  glBindBufferARB(GL_ARRAY_BUFFER_ARB,m_pointsBuffer);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB,m_indicesBuffer);

glEnableVertexAttribArray(0);   // position
glEnableVertexAttribArray(2);   // normal
glEnableVertexAttribArray(8);   // texUV
glEnableVertexAttribArray(5);   // tangent
glEnableVertexAttribArray(6);   // bone
glEnableVertexAttribArray(1);   // weights

glVertexAttribPointer(0, 3, GL_FLOAT, false, vertexSize, (GLvoid*)((char*)NULL + 0));
glVertexAttribPointer(2, 3, GL_FLOAT, false, vertexSize, (GLvoid*)((char*)NULL + 12));
glVertexAttribPointer(8, 2, GL_FLOAT, false, vertexSize, (GLvoid*)((char*)NULL + 24));
glVertexAttribPointer(5, 3, GL_FLOAT, false, vertexSize, (GLvoid*)((char*)NULL + 32));
glVertexAttribPointer(6, 4, GL_BYTE,  false, vertexSize, (GLvoid*)((char*)NULL + 44));
glVertexAttribPointer(1, 3, GL_FLOAT, false, vertexSize, (GLvoid*)((char*)NULL + 48));

glDrawElements(GL_TRIANGLES,m_mesh.GetNumberOfIndices(), GL_UNSIGNED_SHORT, NULL);

/*              
// This is the original code, without arraybuffers
glVertexAttribPointer(0, 3, GL_FLOAT, false, vertexSize, vertices);
glVertexAttribPointer(2, 3, GL_FLOAT, false, vertexSize, vertices + 12);
glVertexAttribPointer(8, 2, GL_FLOAT, false, vertexSize, vertices + 24);
glVertexAttribPointer(5, 3, GL_FLOAT, false, vertexSize, vertices + 32);
glVertexAttribPointer(6, 4, GL_BYTE,  false, vertexSize, vertices + 44);
glVertexAttribPointer(1, 3, GL_FLOAT, false, vertexSize, vertices + 48);

glDrawElements(GL_TRIANGLES,m_mesh.GetNumberOfIndices(), GL_UNSIGNED_SHORT,(GLvoid*)m_mesh.GetIndices());
// until here
*/

glDisableVertexAttribArray(0);   //position
glDisableVertexAttribArray(2);   // normal
glDisableVertexAttribArray(8);   // texUV
glDisableVertexAttribArray(5);   // tangent
glDisableVertexAttribArray(6);   // bone
glDisableVertexAttribArray(1);   // weights

glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);

thanks
christian

How did you create the VBO’s? What driver version are you using?

Originally posted by jeremyz:
How did you create the VBO’s? What driver version are you using?

What I should was slightly simplified code. Replace the first to lignes with:

if (m_pointsBuffer == 0)
{
glGenBuffersARB(1, &m_pointsBuffer);
ASSERT(m_pointsBuffer);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_pointsBuffer);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_mesh.GetByteSizeOfVertexBuffer(), (GLvoid*)m_mesh.GetVertices(), GL_STATIC_DRAW_ARB);
}
if (m_indicesBuffer == 0)
{
glGenBuffersARB(1, &m_indicesBuffer);
ASSERT(m_indicesBuffer);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_indicesBuffer);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_mesh.GetByteSizeOfIndicesBuffer(), (GLvoid*)m_mesh.GetIndices(), GL_STATIC_DRAW_ARB);
}

glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_pointsBuffer);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_indicesBuffer);

m_pointsBuffer and m_indicesBuffer ARE static. I verified with break-points that they are created only once for every object. (the shown code is inside a class –> m_pointsBuffer are private variables)

Driverversion: 6.14.10.5303 –> 53.03

christian

Oh, I just noticed something.

What happens if you replace the line
glVertexAttribPointer(6, 4, GL_BYTE, false, vertexSize, (GLvoid*)((char*)NULL + 44));

with
glVertexAttribPointer(6, 4, GL_UNSIGNED_BYTE, true, vertexSize, (GLvoid*)((char*)NULL + 44));

You might be specifying an attribute format
that requires driver intervention on nvidia.

Originally posted by jeremyz:
[b]Oh, I just noticed something.

What happens if you replace the line
glVertexAttribPointer(6, 4, GL_BYTE, false, vertexSize, (GLvoid*)((char*)NULL + 44));

with
glVertexAttribPointer(6, 4, GL_UNSIGNED_BYTE, true, vertexSize, (GLvoid*)((char*)NULL + 44));

You might be specifying an attribute format
that requires driver intervention on nvidia.[/b]

Doesn’t change anything

[EDIT]
Sorry, didn’t notice the “true”.
Now everything works as expected!

THANKS A LOT!

[EDIT2]
“works as expected” is not 100% correct. But we can easily use floats instead of bytes and avoid the conversion.

[This message has been edited by close2 (edited 02-11-2004).]

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.