Author Topic: OpengL state changes what option would you use?  (Read 3102 times)

0 Members and 1 Guest are viewing this topic.

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1390
  • Karma: 84
    • View Profile
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.
Challenge Trophies Won:

Offline zawran

  • Sponsor
  • Pentium
  • *******
  • Posts: 909
  • Karma: 67
    • View Profile
Re: OpengL state changes what option would you use?
« Reply #1 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.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: OpengL state changes what option would you use?
« Reply #2 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
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1390
  • Karma: 84
    • View Profile
Re: OpengL state changes what option would you use?
« Reply #3 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.
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: OpengL state changes what option would you use?
« Reply #4 on: January 13, 2008 »
Jims right but for future reference, look up  GLCOLORMATERIAL to avoid submitting the material over and over.
Challenge Trophies Won: