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