Avoiding more state changes

I thought we could maintain a copy of the OpenGL machine state (e.g. if tex units are enabled, or lights, or whatever), so unnecessary calls are avoided (we check if it’s already in the good state and if it isn’t we call the state change method).

What do you think of that ?

By the way, nice jme guys, do you do that ? :smiley: :wink:

We had to investigate this. But I don’t think one or two redundant state changes per frame aren’t that expensive. And we would do just more state maintaining.

Here’s what I call unnecessary calls :

as Niwak already mentioned, see : http://www.java-gaming.org/forums/index.php?topic=11748.msg93854#msg93854

hmm… This really looks like a good way to further increase performance. Will you do that?

Often the driver filters those.

For example, there is no performance difference between:


for(int i=0; i<n; i++)
{
   glBindTexture(GL_TEXTURE_2D, currentTex);
   glCallList(myList);
}

and


int last = currentTex;
for(int i=0; i<n; i++)
{
   if(currentTex != last)
      glBindTexture(GL_TEXTURE_2D, last = currentTex);
   glCallList(myList);
}

Note: benchmarked in code where SORTING the textures really had a great impact, so it was part of the bottlenecks

We DO indeed keep track of current states set on the card because even if the driver filters them out (which I’m not so sure they do, at least not always), there is still JNI overhead for such calls.

I said there was no performance-difference, so appearantly the JNI wasn’t significant (1100ns on a P4 2.4GHz - Java 1.5)

Further, you don’t need to speak in CAPITALS to make it clear. For more complex states (switching texture-units, setting lots of lighting-parameters) is ofcourse good to keep a local state, but beware, by the time you’re storing your states in (hash)maps/stacks, you’re probably starting to lose performance.

You mean like where you have SORTING in caps? :stuck_out_tongue:

In any case, I was responding to Amos, I barely even read your post. I think someone needs a thicker skin.

back to the topic, storing the last state and not calling a method because the current state is the same state as you want OGL to be in is not state sorting…no where near.

I’d suggest you google for the topic before making any modifications to your code as you seem to be a little naive to what state sorting is.

DP

darkprophet, don’t know who you’re talking to, assuming it’s to me

Absolutely. And ? Riven digressed a bit, that’s all. THe infos he provides are interesting, too.

Oh sure I had no intention to modify the render code straight ahead. My OpenGL knowledge is nowhere near good enough. Though I may not be as naive to that subject as you suppose.

But if you want to optimize Xith3D rendering pipeline, you are welcome to do that. ;D

Im fine thanks, have my own engine to worry about.

DP

Yeah sure ;D I know that : Once in a while I’m reading VE blogs.