Sign in to follow this  
jm_hewitt

Vertex Buffer Objects draw arrays opposed to draw elements?

Recommended Posts

jm_hewitt    170
I have been using glDrawArrays for my vertex buffer objects for awhile. I recently needed to move to indices lists insteat and use glDrawElements of glDrawRangeElements. Can you store the index lists on the card? If so whats the appopriate call? Currently I store the data on the card in VBOs with glBufferDataARB() calls but my elements I have in the system memory. This seems like there will be a large performance hit because where before I simply called glDrawArrays(..,0, _count) I now send down all the veritces that need to be drawn. I tried to find sample code that uses glDrawElements and VBOs but my search turned up dry. I believe I originally used nehe's tutorial to add VBOs.

Share this post


Link to post
Share on other sites
jm_hewitt    170
I found an interesting chart at http://www.sci.utah.edu/~bavoil/VBO/

that showed display lists outperforming VBOs, but display lists wont need for me because I am switched to elements to allow multiple LOD on the same set of data.

Share this post


Link to post
Share on other sites
Promit    13246
You can use index arrays the same way you use vertex arrays. Only thing is, everywhere that you used GL_ARRAY_BUFFER_ARB for vertex buffers, use GL_ELEMENT_ARRAY_BUFFER_ARB for index buffers.

Share this post


Link to post
Share on other sites
jm_hewitt    170
clarify a little more, please.

setup calls to store on card:

// store index list on card
glGenBuffersARB(1, &_VBOelement);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, _VBOelement );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, _count*sizeof(int), elements, GL_STATIC_DRAW_ARB );

// store vertex list
glGenBuffersARB( 1, &_VBOvertex );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, _VBOvertex );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, numOfPoints*3*sizeof(float), vList_, GL_STATIC_DRAW_ARB );

// Generate And Bind The Normal Buffer
glGenBuffersARB( 1, &_VBOnormal );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, _VBOnormal );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, numOfPoints*3*sizeof(float), nList_, GL_STATIC_DRAW_ARB );


render call:


glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_NORMAL_ARRAY );

// Set Pointers To Our Data
glBindBufferARB( GL_ARRAY_BUFFER_ARB, _VBOvertex );
glVertexPointer( 3, GL_FLOAT, 0, (char *) NULL );
glBindBufferARB( GL_ARRAY_BUFFER_ARB, _VBOnormal );
glNormalPointer( GL_FLOAT, 0, (char *) NULL );
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, _VBOelement );

glDrawElements( _modeOfVBO, _count, GL_UNSIGNED_INT, &_VBOelement);

// Disable Pointers
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_NORMAL_ARRAY );


I can get it to work just fine when I call the draw functoin with the original list of indices to draw:
glDrawElements( _modeOfVBO, _count, GL_UNSIGNED_INT, elements);
but not with the buffer of data on card:
glDrawElements( _modeOfVBO, _count, GL_UNSIGNED_INT, &_VBOelement);

I asume I am missing a call to glBindBufferARB() to grab the VBOelement.....

[Edited by - jm_hewitt on July 7, 2004 3:51:18 PM]

Share this post


Link to post
Share on other sites
jm_hewitt    170
Quote:
Original post by _the_phantom_
doesnt the spec have an example of this?


I've always tried to read the spec sheets from sgi.com from the beginning and never made it down the bottom where examples are. Thanks. I corrected my code up top on the slight chance someone else has the problem. I had to call GL_ARRAY_BUFFER for the first to buffers, but GL_ELEMENT_ARRAY_BUFFER for the element buffer, I misnderstood as replacing all defines with the GL_ELEMENT. It now works great and now have find more value out of sgi's txt files.

Share this post


Link to post
Share on other sites
Promit    13246

glGenBuffersARB(1, &_VBOelement);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, _VBOelement );
glBufferDataARB( GL_ARRAY_BUFFER_ARB, _count*sizeof(int), elements, GL_STATIC_DRAW_ARB );

Needs to be

glGenBuffersARB(1, &_VBOelement);
glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, _VBOelement );
glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, _count*sizeof(int), elements, GL_STATIC_DRAW_ARB );


I think that should do it, actually. Send NULL for the indices to glDrawElements and it should work.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this