Original Post
Hello, I am currently working on an engine and I am responsible for implementing object outlining to show the user what was just selected. Everything works fine, but performance is negatively affected when an object is selected and thus outlined. Basically, what I am doing is the following:
glPushMatrix();
glClearStencil(0);
glClear(GL_STENCIL_BUFFER_BIT);
glEnable(GL_STENCIL_TEST);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
// render original into stencil
glMultMatrix(transMaatrix);
glCallList(mydisplaylist);
glStencilFunc(GL_NOTEQUAL, 1, -1);
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
glPopMatrix();
glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glLineWidth(3);
glMultMatrix(transmatrix);
// now begin a complete rendering loop rendering
// the object in wireframe ...
glBegin(GL_LINE_LOOP)
glVertex3fv(....
glEnd();
glEnable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
glDisable(GL_STENCIL_TEST);
All of this is compiled into its own display list and is called if there is a currently "selected" object. It works beautifully, just as I want. I like the fact that the outline width stays the same no matter where the user places the camera. However, I lose considerable performance when calling this display list. It seems to directly related to the number of vertices in the orginal object. I am aware, for a selected object I am rendering three times - once into the stencil, then using the wireframe against the stencil, and then finally the actual object. The GL state changes do slow things down slightly, but I am unaware of how to remove any of the state calls. Any suggestions or pointers to appropriate papers would be greatly appreciated. Thanks, jdaniel