Skip to main content
gamedev.net
🔒 Locked

Static Index Buffer

Started by ajas95 2 replies 700+ views
Original Post
ajas95
ajas95
Okay, I've answered tons of RTFM questions in other forums here, I feel like I'm entitled to ask one at least once. Say I have a static mesh where I have a list of vertices and one set of texture coordinates, and I have a list of indicies (32 bit) each trio of which represents one triangle. What are the simplest OpenGL calls to make to be able to draw this as a vertex/index buffer? Basically, something to do this quickly:

vec4* vert_buffer;
unsigned int* tri_buffer;
float* uv_buffer;

glBegin(GL_TRIANGLES);
for(int i = 0; i < tri_count/3; i += 3)
{
    glTexCoord2fv(uv_buffer[tri_buffer]);
    glVertex4fv(vert_buffer[tri_buffer]);
    glTexCoord2fv(uv_buffer[tri_buffer[i + 1]]);
    glVertex4fv(vert_buffer[tri_buffer[i + 1]]);    
    glTexCoord2fv(uv_buffer[tri_buffer[i + 2]]);
    glVertex4fv(vert_buffer[tri_buffer[i + 2]]);
}
glEnd();
_the_phantom_
_the_phantom_
you could shove them into a VBO with a static_draw useage hint. The driver should then put the indices in VRAM. Then its just a case of making a Draw[Range]Element() call with the VBO bound and the indices pointer as '0' (zero)

just out of intrest, do you REALLY need 32bit indices?
shekharpk19
shekharpk19
Try out glVertexpointer , glNormalpointer and a glDrawElemets call .. you can completely avoid looping and calling glVertex* !!

THere is another thing called Compiled Vretex Arrays (CVA's) i havent tried them out .. so cant say anything more about them .. there is a lot of stuff in the net abou tthem

Or theres always display lists .. construct display lists once and just call the list whenever u need to draw them

Or as phantom said ..VBO's ....;)

_the_phantom_
_the_phantom_
aarrggh!! why do people keep metioning CVA [crys]
Forget CVA.
CVA is an unfinished spec and on anything remotely modern is likely to cause at best no effect and at worse a slow down.
CVA basically says to the drivers 'ok, I wont touch this data any more, so until I say otherwise cache the results of the T&L equations', which on pre-hardware acceleated systems (and some of the early chipsets in some cases) ment that if you drew a scene more than once you would only transform/light the vertex data for then scene once.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.