I'm using glRenderMode(GL_SELECT) in order to select objects in my program. However, I quickly notice a massive performance hit using this method when I get a polygon count anything above something trivial. Is this a poor method? Am I doing something wrong? Here's a snapshot of my code:
// On a mouse click...
glSelectBuffer(...);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glRenderMode(GL_SELECT);
glLoadIdentity();
gluPickMatrix(...);
gluPerspective(...);
glInitNames();
glPushName(0);
// This part is taking a long time...
RenderPickingScene(...);
// determine what was clicked on
hits = glRenderMode(GL_RENDER);
ProcessesPickingHits(hits);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
void RenderPickingScene(...)
{
glPushMatrix();
glRotatef(ViewpointRotationX, -1.0f, 0.0f, 0.0f);
glRotatef(ViewpointRotationY, 0.0f, -1.0f, 0.0f);
glRotatef(ViewpointRotationZ, 0.0f, 0.0f, -1.0f);
glTranslatef(-ViewpointPositionX, -ViewpointPositionY, -ViewpointPositionZ);
glLoadName(...);
// Draw the object(s)
glPushMatrix();
glTranslatef(ObjectPositionX, ObjectPositionY, ObjectPositionZ);
glRotatef(ObjectRotationZ, 0.0f, 0.0f, 1.0f);
glRotatef(ObjectRotationY, 0.0f, 1.0f, 0.0f);
glRotatef(ObjectRotationX, 1.0f, 0.0f, 0.0f);
glBindBufferARB(GL_ARRAY_BUFFER, VertexName);
glVertexPointer(3, GL_FLOAT, 0, 0);
glBindBufferARB(GL_ARRAY_BUFFER, ColorName);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, 0);
glBindBufferARB(GL_ARRAY_BUFFER, NormalName);
glNormalPointer(GL_FLOAT, 0, 0);
glBindBufferARB(GL_ARRAY_BUFFER, TexCoordName);
glTexCoordPointer(2, GL_FLOAT, 0, 0);
// The object is just made up of quads
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, VBOName);
glDrawRangeElements(GL_QUADS, 0, IndexCurrentSize, IndexCurrentSize, GL_UNSIGNED_INT, NULL);
^--- THIS FUNCTION TAKES NEARLY 1 SECOND
glPopMatrix();
glPopMatrix();
}
The call to glDrawRangeElements() seems to take nearly 1 second to complete. The object I'm drawing is made up of 600 quads (a cube with faces that are 10x10). As long as I don't invoke the GL_SELECT render mode and draw the cube, I don't get this slow down. Any ideas? I'm using a Radeon 9800 Pro with the latest drivers. Last time I tried this, I didn't see the problem on my laptop which has an NVidia video card. I'm ready to try just about any suggestions.
[Edited by - Mantear on August 30, 2005 8:05:46 AM]