PDA

View Full Version : proper use of gldrawrangeelements



Vexator
09-08-2005, 11:01 AM
i want to render only a part of my model. this is from my render routine. it works fine if i use glDrawElements to draw everything, but glDrawRangeElements as shown below doesn't work. shouldn't this actually only render from index 12 to 48?! or what am i doing wrong?!


glEnableClientState( GL_VERTEX_ARRAY );
glBindBufferARB( GL_ARRAY_BUFFER, Vertices->Id );
glVertexPointer( 3, GL_FLOAT, 0, 0 );

glEnableClientState( GL_NORMAL_ARRAY );
glBindBufferARB( GL_ARRAY_BUFFER, Normals->Id );
glNormalPointer( GL_FLOAT, 0, 0 );

glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glBindBufferARB( GL_ARRAY_BUFFER, Coordinates->Id );
glTexCoordPointer( 2, GL_FLOAT, 0, 0 );

glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER, Indices->Id );
glDrawRangeElements( GL_TRIANGLES, 12, 48, 36, GL_UNSIGNED_INT, 0 );

glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_NORMAL_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );

glBindBufferARB( GL_ARRAY_BUFFER, 0 );
glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER, 0 );sry i know there have been ten thousand people asking sth like that before but i searched the forum and didn't find a hint :p

tamlin
09-08-2005, 12:20 PM
You have misunderstood start and end. They are the first and last indexed elements (referenced from the index array you specified) in the enabled arrays.

Google (http://www.google.com/search?q=glDrawRangeElements) is your friend.

Vexator
09-08-2005, 01:38 PM
thanks, but i read the reference page before i posted. i still don't get it. what would i have to do instead if i want to render a part of my model? thanks in advance!

Humus
09-08-2005, 06:10 PM
You need to pass an offset into the index buffer as the last parameter. The 12 and 48 parameters in your case tells what range within the vertex buffer you'll access through the indices in this call.

cppguru
09-08-2005, 09:32 PM
Seems you've misunderstood DrawRangeElements'purpose. It does not filter indices; it only informates driver which vertices are referred.

Spec:
glDrawRangeElementsEXT is a restricted form of glDrawElements. All vertices referenced by indices must lie between start and end inclusive. Not all vertices between start and end must be referenced, however unreferenced vertices may be sent through some of the vertex pipeline before being discarded, reducing performance from what could be achieved by an optimal index set. Index values which lie outside the range will cause implementation-dependent results.

Vexator
09-09-2005, 03:14 AM
d'oh.. k thank you now it is clear :)

zed
09-09-2005, 10:40 PM
sorry bout hijacking the thread
but i get no speed difference between drawrangeelements + draweleemtns when i use it in combination with VBO, with straight VAs there is an improvement.
btw this is tested in a benchmark