Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: Pixel_Outlaw on January 13, 2008

Title: OpengL state changes what option would you use?
Post by: Pixel_Outlaw on January 13, 2008
My current project has hundreds of objects onscreen and they run great. Now my problem is letting these objects come in different colors. I've heard that calling material changes is costly and should be used sparingly. As it stands my objects are stored in display lists (I know shame shame should be using vertex arrays). Now the list is looped through each cycle and the objects are updated and drawn. Currently I set the material before updating and drawing all objects in the list. If I let the objects come in different colors it would mean that I could no longer just call the material once. Is it okay to set the material roughly 500 times per cycle? Is it OK to rotate each of the 400 shapes then reset the matrix after each object is drawn? Each of the 500 objects has 8 small triangles to render. I need to leave room for some heavy collision checking too so these small objects need to be rotated material set and then drawn. I'm just trying to do what would be right for them.
Title: Re: OpengL state changes what option would you use?
Post by: zawran on January 13, 2008
You could have all the sprites on the same texture layed out in a grid and then use UV coords to determine which part of the texture they are on. That would allow you to only use one texture. But whether the setting of the UV coords is slower then changing texture for each I am not sure. In my own sprite engine I am using a layer technique, where each layer has its own texture assigned to it. This texture can be one sprite, or several sprites layed out on one texture. So when rendering I render one layer (texture) at a time. An I set the UV coords for each. So far for what I have been using it for, it has worked just fine, but I have not used it for anything with thousands of sprites.
Title: Re: OpengL state changes what option would you use?
Post by: Jim on January 13, 2008
Unless you're dealing with millions of polygons it almost certainly won't make any difference.  First thing to do is see if it runs OK before trying to optimise.
There are two golden rules about optimisation
1) don't do it
2) don't do it yet

Jim
Title: Re: OpengL state changes what option would you use?
Post by: Pixel_Outlaw on January 13, 2008
Thanks Jim. I didn't know if it was normal to call rotations and material changes around 500 per times per cycle.
Title: Re: OpengL state changes what option would you use?
Post by: taj on January 13, 2008
Jims right but for future reference, look up  GLCOLORMATERIAL to avoid submitting the material over and over.