Indexed VBOs?
Hi, i have a question about indexed VBOs... Let's say we have 4 Vertices building 2 Triangles = 2 Vertices are used for both Triangles. Now we have a vertex-Array with 4 Values, if we put those in a VBO and render them with glDrawElements we can draw our two Triangles without any problems. But now I want uv-coords too... any vertex should have it's one UV-Coord what means I would have 6 uvs... Now we got: vertexArray: 4 Values uvArray: 6 Values there comes the problem... I can't use drawElements anymore cause the length of my arrays is different... So is there anyway to index the arrays??? Or can i use different index-arrays for my uvArray and vertexArray??? Sure, I could write my 4 Vertices 6 times in the VBO-Array... but I realy hope there's an other way too.. Au'revoir, Aya~
I aim for my endless Dreams and I know they will come true!
You will have to use flat array where all vertex streams (position, texture coord, normal,...) use same index array. There is no (simple) way around it. And do't be afraid of a bit increased VA/VBO size becouse performance gain of reduced count of glDrawElements is worth it.
You should never let your fears become the boundaries of your dreams.
Hi,
ok.. but can anyone explain me what GL_ELEMENT_ARRAY_BUFFER is good for??
Au'revoir,
Aya~
ok.. but can anyone explain me what GL_ELEMENT_ARRAY_BUFFER is good for??
Au'revoir,
Aya~
I aim for my endless Dreams and I know they will come true!
It's used for storing index buffer in VBO the same way GL_ARRAY_BUFFER_ARB is used for vertices.
// verticesglGenBuffersARB( 1, &vboVerticesID );glBindBufferARB( GL_ARRAY_BUFFER_ARB, vboVerticesID );glBufferDataARB( GL_ARRAY_BUFFER_ARB, sizeof( CVertex ) * numVertices, vertices, GL_STATIC_DRAW_ARB );glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); // indicesglGenBuffersARB( 1, &vboIndicesID );glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, vboIndicesID );glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof( unsigned short ) * numIndices, indices, GL_STATIC_DRAW_ARB );glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0 );
You should never let your fears become the boundaries of your dreams.
Hi,
ok and how do i use this GL_ELEMENT_ARRAY_BUFFER_ARB-VBO when i draw it??? still with glDrawElements???
Au'revoir,
Aya~
ok and how do i use this GL_ELEMENT_ARRAY_BUFFER_ARB-VBO when i draw it??? still with glDrawElements???
Au'revoir,
Aya~
I aim for my endless Dreams and I know they will come true!
glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, vboIndicesID );glDrawElements( GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, BUFFER_OFFSET( 0 ) );glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
You *really* should read extension specification as it includes number of examples of VBO use, including this one.
You should never let your fears become the boundaries of your dreams.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement