Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
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  
  JOGL and glNormal performance  (Read 641 times)
0 Members and 1 Guest are viewing this topic.
Offline alesky

Junior Member


Medals: 3
Exp: 15 years


mmm....


« Posted 2013-03-02 17:04:37 »

hi guys

i would like to understand more in deep how works jogl so that i can use the correct chose during my implementation.
during one of my exercise i find out a strange behavior that can change the performance of the program that i wrote.

this is the question
look at this code, that i use to draw a surface flat divided in square

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
   private void flatSurface(GL2 gl,int size,int sizeUnit) {

      gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, new float[]{0.2f, 0.2f, 0.2f, 1f},0);
      gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT, new float[]{0.1f, 0.1f, 0.1f, 1f},0);
      gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_DIFFUSE,new float[]{0.6f, 0.6f, 0.5f, 1f},0 );

      gl.glPushMatrix();
      gl.glTranslated(-size/2, 1, -size/2);

      for (float x = size; x >= 0; x=x-sizeUnit) {
         gl.glBegin(GL2.GL_QUAD_STRIP);
         gl.glNormal3d(0, 1, 0);
         for (float z = size; z >= 0; z=z-sizeUnit) {
            gl.glVertex3f(x, 0,z);
            gl.glVertex3f(x+sizeUnit, 0,z);            
         }
         gl.glEnd();      
      }
      gl.glPopMatrix();
   }


I just read that if the glNormal is called one time instead that repeat for each vertex performance are better.
Becouse there are less call to GL system.
i did the test and in my program the fps are increased

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
//optimized versione
gl.glNormal3d(0, 1, 0);
for (float z = size; z >= 0; z=z-sizeUnit) {
   gl.glVertex3f(x, 0,z);
   gl.glVertex3f(x+sizeUnit, 0,z);            
}

//original version
for (float z = size; z >= 0; z=z-sizeUnit) {
   gl.glVertex3f(x, 0,z);
   gl.glNormal3d(0, 1, 0);
   gl.glVertex3f(x+sizeUnit, 0,z);            
   gl.glNormal3d(0, 1, 0);
}


after that i studied the display list and moved the firs function in a display list to increase more the performance
1  
2  
3  
4  
      superficieList = gl.glGenLists(1);
      gl.glNewList(superficieList, GL2.GL_COMPILE);
      flatSurface(gl,dimensione,dimensioneUnita);  
      gl.glEndList();


so now performance are increased more but with big surprise i noted that:
with the display list i can increase more the performance if in the function that draw the surface i use the old code!!!
1  
2  
3  
4  
5  
6  
7  
//original version
for (float z = size; z >= 0; z=z-sizeUnit) {
   gl.glVertex3f(x, 0,z);
   gl.glNormal3d(0, 1, 0);
   gl.glVertex3f(x+sizeUnit, 0,z);            
   gl.glNormal3d(0, 1, 0);
}


this has not sense for me and my knowledge can not help my to undestand why.
can u help me to understand this beaviour? Huh



Online theagentd
« Reply #1 - Posted 2013-03-02 17:29:30 »

Using the float version of glNormal (glNormal3f()) should be a bit faster, but you want really good performance you should look into display lists or VBOs. Your data seems to be static, so you should be able to generate your geometry and store it in a display list or VBO, and use glTranslatef() to position your objects when rendering.

Myomyomyo.
Offline alesky

Junior Member


Medals: 3
Exp: 15 years


mmm....


« Reply #2 - Posted 2013-03-02 17:37:37 »

hi theagentd , thanks for the answer but for mistake i post only half of my question so i modified it and in meanwhile you was answering to my half post!!! Smiley
i hope that now you can read and answer reading the complete question
thanks

Using the float version of glNormal (glNormal3f()) should be a bit faster, but you want really good performance you should look into display lists or VBOs. Your data seems to be static, so you should be able to generate your geometry and store it in a display list or VBO, and use glTranslatef() to position your objects when rendering.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online theagentd
« Reply #3 - Posted 2013-03-02 17:42:36 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
//optimized versione
gl.glNormal3d(0, 1, 0);
for (float z = size; z >= 0; z=z-sizeUnit) {
   gl.glVertex3f(x, 0,z);
   gl.glVertex3f(x+sizeUnit, 0,z);            
}

//original version
for (float z = size; z >= 0; z=z-sizeUnit) {
   gl.glVertex3f(x, 0,z);
   gl.glNormal3d(0, 1, 0);
   gl.glVertex3f(x+sizeUnit, 0,z);            
   gl.glNormal3d(0, 1, 0);
}


You're wondering why the optimized version is slower than the original version?

Myomyomyo.
Offline alesky

Junior Member


Medals: 3
Exp: 15 years


mmm....


« Reply #4 - Posted 2013-03-02 17:46:25 »

yes with the display list it is always faster that without


but if a test
display list and optimized version, it is less faster that
display list with original version that has more call of glNormal

this is the point that is not clear


Online theagentd
« Reply #5 - Posted 2013-03-02 18:40:41 »

I believe that's because OpenGL expects a normal per vertex. If you don't specify it, your graphics driver might have to use a slower method for rendering, which might impact performance. If you were to render this with VBOs and shaders, you'd either specify this as a per-vertex attribute or a uniform variable. OpenGL does not support per-primitive attributes, or more specifically attributes that aren't per vertex.

Myomyomyo.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 783
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #6 - Posted 2013-03-02 18:49:07 »

OpenGL does not support [...] attributes that aren't per vertex.

http://www.opengl.org/sdk/docs/man/xhtml/glVertexBindingDivisor.xml Pointing

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Online theagentd
« Reply #7 - Posted 2013-03-02 19:15:26 »

I know, I know... The thing is that that's a OGL 3 feature intended for instancing and can't be used to specify per-face normals for example. Plus, the point that it's an OGL 3 feature means that display lists probably don't take advantage of the same capabilities.

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

TehJavaDev (17 views)
2014-08-28 18:26:30

CopyableCougar4 (26 views)
2014-08-22 19:31:30

atombrot (39 views)
2014-08-19 09:29:53

Tekkerue (36 views)
2014-08-16 06:45:27

Tekkerue (33 views)
2014-08-16 06:22:17

Tekkerue (22 views)
2014-08-16 06:20:21

Tekkerue (33 views)
2014-08-16 06:12:11

Rayexar (67 views)
2014-08-11 02:49:23

BurntPizza (45 views)
2014-08-09 21:09:32

BurntPizza (36 views)
2014-08-08 02:01:56
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!