View Full Version : Simplifing code
02-26-2006, 05:17 PM
I have just inherited a bunch of C code that uses OpenGL. I know almost zero about GL and have been asked to see if I can speed up the code. As it now exists, glVertex3f is called about 250,000,000 times in a run of the program. The objects being displayed are rather complex so I expect many gl calls. Is there a way to build all of the necessary info for gl to exercize the display? In other words, can I replace a bunch of glVertex calls by one call to another GL routine?
02-26-2006, 07:20 PM
Yes you can. There are several things you can do.
1) You can use vertex arrays. If you are familiar with DX9 then this is a superset of DrawIndexedPrimitiveUP functionality. See OGL documentation of functions gl(Vertex|Normal|*)Pointer and glDrawElementsRange or glDrawArrays.
2) You can use Vertex Buffer Object extension. This is similiar to vertex array except that memory for vertices and indices is allocated by the driver and it is equivalent of DX vertex buffers. See documentation of corresponding extension http://oss.sgi.com/projects/ogl-sample/registry/ARB/vertex_buffer_object.txt and tutorial http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=45
For complex objects this will likely be significantly faster than ordinary vertex arrays however if you use formats that are not supported by your hw, like the doubles or elements that are not dword aligned (on ATI), the performance will be really bad.
3) You can use display list which record sequence of GL commands which can be further optimized by the driver and played back using a single call. See documentation of functions gl(Begin|End)List and gl(Gen|Call)Lists or this tutorial http://jerome.jouvie.free.fr/OpenGl/Tutorials/Tutorial16.php
Performance of this may highly depend on quality of the driver and type of commands recorded in the list.
02-27-2006, 06:50 AM
I'm surprised that anyone understood what I was asking for.
I'll need to do a lot of reading it looks like. I assume that DX9 is DirectX 9 which I can not use as progam must work on non Windows systems.
02-27-2006, 08:43 AM
I only mentioned paralels with the DirectX just to give you more information about working of various methods in case that you are familiar with that api.
02-27-2006, 09:06 AM
I've never coded graphics but have 40+yrs of scientific programming where I had to be very concerned about cpu time.
I'll lokk DX9 to get a better understanding of the api's.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.