JOGL and glNormal performance

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


	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


//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


		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!!!


//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? ???

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.

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!!! :slight_smile:
i hope that now you can read and answer reading the complete question
thanks

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

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

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.

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

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.