I have a mesh that is generated off a B-Spline surface (say, 30x30), and I store the mesh vertices (and associated normals) in 2D arrays. I currently draw the mesh to the screen using glBegin and glEnd (GL_TRIANGLE_STRIP). I need to be able to draw this mesh in two different “modes”: one mode is normal, where I specify one color at the start using glColor3f and specify vertices and normals as usual. The other mode I will call “color mode”, where I turn off lighting, do not specify any vertex normals, and I shade each mesh vertex a different color to match a particular (u,v) parametrization (in particular, I color the R component with the u value, the G component with the v value, and set the blue component to 0.5… though the details aren’t too important). This results in a surface with gradient color, since each vertex is a different color.
Now, at certain times during the execution of my program, I need to render the surface into the back buffer in “color mode”, set the camera up at a certain angle, and use glReadPixels to examine the color of a certain pixel. At these times, I need to do this several hundred times in a row (as many times as there are data in my set, e.g. 500). With my current setup, this is (obviously) incredibly slow; for each of the 500 iterations, I draw the entire mesh using glBegin and glEnd (so that would be 900 or so triangles). Additionally, I would like the mesh to eventually be finer (say, 50x50 or higher), which would make this even slower.
I had thought about using a display list to render the mesh in color mode, however every so often I will need to deform the mesh and, therefore, change what is in the display list, which can’t be done without deleting the display list and recompiling.
After doing some research, I came across VBOs. However, at the current stage of my program (in addition to other work I need to do), it would require a fairly time-consuming overhaul of the rendering functions to change everything to VBOs. I would like to know: would changing all the rendering to VBOs significantly increase the speed of this part of my program? If the loop executes about 500 times, with a 30x30 mesh, it can take as long as 5 or 6 seconds, and I would like to get this step to 0.5 seconds or less. Also, I’ve heard that glReadPixels is a blocking function, which is probably causing me some significant overhead as well. Would PBOs be the solution I need here?
Some example code which is the essence of this part of my program is below. I would like to know if it is worth my time to invest in implementing the VBOs/PBOs (will it reduce significantly, or only a small amount?), or if anyone has general comments as to how I can speed this part of my program up. Thanks!
EDIT - I should note that the surface will never change during this loop, but the camera angle will. (The surface/mesh might change after this loop, but never during).
for(int i=0; i<500; i++)
{
// set up camera according to data point i
// ...
// ...
surface->render(COLOR_MODE); // render 1000+ triangles using glBegin(GL_TRIANGLE_STRIP)
glReadPixels(..., GL_RGBA, ...);
// do something with information retrieved from glReadPixels
}