Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (575)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Avoiding more state changes  (Read 2219 times)
0 Members and 1 Guest are viewing this topic.
Offline Amos Wenger

Senior Duke




Everything's possible, but not everything's fun...


« Posted 2006-10-04 16:10:02 »

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 ?

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline Amos Wenger

Senior Duke




Everything's possible, but not everything's fun...


« Reply #1 - Posted 2006-10-04 16:48:13 »

By the way, nice jme guys, do you do that ?  Cheesy  Wink

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline Marvin Fröhlich

Senior Duke




May the 4th, be with you...


« Reply #2 - Posted 2006-10-04 18:00:33 »

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 ?

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Amos Wenger

Senior Duke




Everything's possible, but not everything's fun...


« Reply #3 - Posted 2006-10-04 18:14:56 »

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 ?

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 :
Quote
glGetFloatv(GL_CURRENT_COLOR,0x23049aec);
glClientActiveTextureARB(GL_TEXTURE0);
glActiveTextureARB(GL_TEXTURE0);
glBindBufferARB(GL_ARRAY_BUFFER,7037);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2,GL_FLOAT,0,0x0000);
glBindBufferARB(GL_ARRAY_BUFFER,0);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glDisable(GL_TEXTURE_GEN_Q);
glClientActiveTextureARB(GL_TEXTURE1);
glActiveTextureARB(GL_TEXTURE1);
glBindBufferARB(GL_ARRAY_BUFFER,7038);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2,GL_FLOAT,0,0x0000);
glBindBufferARB(GL_ARRAY_BUFFER,0);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glDisable(GL_TEXTURE_GEN_Q);
glBindBufferARB(GL_ARRAY_BUFFER,7039);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_FLOAT,0,0x0000);
glBindBufferARB(GL_ARRAY_BUFFER,0);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDrawElements(GL_TRIANGLES,6,GL_UNSIGNED_INT,0x649c000); Tex=(0,35) (1,16)
glClientActiveTextureARB(GL_TEXTURE1);
glActiveTextureARB(GL_TEXTURE1);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glDisable(GL_TEXTURE_GEN_Q);
glClientActiveTextureARB(GL_TEXTURE0);
glActiveTextureARB(GL_TEXTURE0);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_TEXTURE_GEN_R);
glDisable(GL_TEXTURE_GEN_Q);
glColor4fv( [1.000000,1.000000,1.000000,1.000000] );
as Niwak already mentioned, see : http://www.java-gaming.org/forums/index.php?topic=11748.msg93854#msg93854

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline Marvin Fröhlich

Senior Duke




May the 4th, be with you...


« Reply #4 - Posted 2006-10-04 19:25:44 »

hmm... This really looks like a good way to further increase performance. Will you do that?
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #5 - Posted 2006-10-04 19:34:06 »

Often the driver filters those.

For example, there is no performance difference between:
1  
2  
3  
4  
5  
for(int i=0; i<n; i++)
{
   glBindTexture(GL_TEXTURE_2D, currentTex);
   glCallList(myList);
}


and
1  
2  
3  
4  
5  
6  
7  
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

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline renanse

Junior Duke




Intelligence is light to a dark world.


« Reply #6 - Posted 2006-10-04 23:50:40 »

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.

Renanse  (ruh-NON-say)
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #7 - Posted 2006-10-05 21:30:43 »

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.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline renanse

Junior Duke




Intelligence is light to a dark world.


« Reply #8 - Posted 2006-10-06 01:16:36 »

You mean like where you have SORTING in caps? Tongue

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

Renanse  (ruh-NON-say)
Offline darkprophet

Senior Duke




Go Go Gadget Arms


« Reply #9 - Posted 2006-10-06 16:10:19 »

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

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Amos Wenger

Senior Duke




Everything's possible, but not everything's fun...


« Reply #10 - Posted 2006-10-06 16:32:03 »

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

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.
Absolutely. And ? Riven digressed a bit, that's all. THe infos he provides are interesting, too.

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.
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.  Grin

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Offline darkprophet

Senior Duke




Go Go Gadget Arms


« Reply #11 - Posted 2006-10-07 00:21:20 »

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

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

DP

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline Amos Wenger

Senior Duke




Everything's possible, but not everything's fun...


« Reply #12 - Posted 2006-10-07 12:18:49 »

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

Im fine thanks, have my own engine to worry about.
Yeah sure  Grin I know that : Once in a while I'm reading VE blogs.

"Once you start working on something, don't be afraid of failure and don't abandon it. People who work sincerely are the happiest"
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (33 views)
2014-10-17 03:59:02

Norakomi (25 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (26 views)
2014-10-15 16:18:58

TehJavaDev (50 views)
2014-10-14 00:39:48

TehJavaDev (50 views)
2014-10-14 00:35:47

TehJavaDev (40 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (74 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!