Author Topic: Performance Tuning in OpenGL (Sorting and the best DataStructures)  (Read 2481 times)

0 Members and 1 Guest are viewing this topic.

mnemon

  • Associate
  • Posts: 2
Hi everybody,
As im writing a Renderer in OpenGL i stumble across the follwoing problem.
According to the following Article below i would like to optimize my scene by Sate Sorting:

http://ati.amd.com/developer/gdc/PerformanceTuning.pdf

Example:
Lets consider objects as pairs of (material, geometry) with a given position.
Then a list of these pairs.
So i first sort my objects in terms of material (that is shader, texture a.s.o) then i sort in terms of VBO-Data (Geometry). Afterwards i have a list like f.E.:

metal torso  at position 1
metal torso at posiiton 2
metal arm at ...
flesh head at ...
flesh hand at ...

now i in the renderloop i could just render the scene.
but then, at every position where i want to render a metal torso pair in code it would look like (pseudocode):

glenable(metal)
render torso at pos 1
gldisable(metal)
glenable(metal)
render torso at pos 2
gldisable(metal)

but wouldnt it be better to have code look like:

glenable(metal)
render torso at pos1
render torso at pos2
gldisable(metal)

i hope you see what i mean.

do you think there is much performance-loss if i disable a gl-State and enable the same state one call later?

or do i have to split-up the rendering for my 3D Objects to get the code like in the second example.

I coded something that achieved a glcommandstream like in the second example, tha looks ugly.
Im trying to get all my things into a resonable object-oriented structure. So my 3D Objects (Material,Geometry - Pairs) are LeafNodes in a Transfroms-Scene-Graph. And those objects now have this split rendering.
For other leanodes like  Lights f.E. this doesnt make sense.

Maybe you can tell how you achieve something like this. What kind of structure you use to get sorted data for maximum performance in your 3dapps.

Greetings
 Mnemon

JeGX

  • Global Moderator
  • Capo Crimine
  • *****
  • Posts: 2357
    • oZone3D.Net
Re: Performance Tuning in OpenGL (Sorting and the best DataStructures)
« Reply #1 on: July 30, 2007, 04:27:45 PM »
Hi Mnemon
As usual in perfomance tuning, you have to time your code and if possible compare the same 3d scene with other 3d engines.
The rest is very dependent of the goals of your rendering engine.

To measure code performance, use glFinish():

start = GetMilliseconds();
glFinish();

//
// Do your rendering stuff here
//

glFinish();
end = GetMilliseconds();

elapsed = end - start;

The second code snippet you gave is better than the first one.

What kind of 3d file format can your engine load (*.3ds, ...) ?


mnemon

  • Associate
  • Posts: 2
Re: Performance Tuning in OpenGL (Sorting and the best DataStructures)
« Reply #2 on: July 31, 2007, 01:28:43 PM »
Well,
I thought the kind of state sorting as explained above is so basic that it has a very generic use.
Basically the question was, if glDisable calls can affect the fps if you enable exactly the same state one call later.

As Im writing this on a mac and dont hav 3ds max I wanted to implement the object loader maybe for .OBJ or something like this.

thx for the tip with glFinish.