GRID with glInterleavedArrays and GL_TRIANGLE_STRIP

Hallo guys

i have an highmap terrain generator and i would like to increase its preformance

my enigne in the beginning populate 3 bi-dimensional arrays

texture (x,y)
norma (x,y)
vertex (x,y)

inquerying the array by x and y i can get all the information of the vertex in the grid, becouse x and y is also the position of the vertex in the grid

in the beginnig i was using the GL_TRIANGLES to draw the grid and this is my algorithm


gl.glBegin(GL2.GL_TRIANGLES);

		for (int x = 0; x < vertex.length-1; x++) {
			for (int y = 0; y < vertex[0].length-1; y++) {

				//triangle down
				gl.glTexCoord2f(x/(float)(vertex.length-1), y/(float)(vertex[0].length-1));
				gl.glNormal3d(normal[x][y].getX(),normal[x][y].getY(),normal[x][y].getZ());
				gl.glVertex3d(vertex[x][y].getX(),vertex[x][y].getY(),vertex[x][y].getZ());

				gl.glTexCoord2f((x+1)/(float)(vertex.length-1), y/(float)(vertex[0].length-1));
				gl.glNormal3d(normal[x+1][y].getX(),normal[x+1][y].getY(),normal[x+1][y].getZ());				
				gl.glVertex3d(vertex[x+1][y].getX(),vertex[x+1][y].getY(),vertex[x+1][y].getZ());

				gl.glTexCoord2f((x+1)/(float)(vertex.length-1), (y+1)/(float)(vertex[0].length-1));
				gl.glNormal3d(normal[x+1][y+1].getX(),normal[x+1][y+1].getY(),normal[x+1][y+1].getZ());				
				gl.glVertex3d(vertex[x+1][y+1].getX(),vertex[x+1][y+1].getY(),vertex[x+1][y+1].getZ());

				//triangle up
				gl.glTexCoord2f(x/(float)(vertex.length-1), y/(float)(vertex[0].length-1));				
				gl.glNormal3d(normal[x][y].getX(),normal[x][y].getY(),normal[x][y].getZ());				
				gl.glVertex3d(vertex[x][y].getX(),vertex[x][y].getY(),vertex[x][y].getZ());

				gl.glTexCoord2f((x+1)/(float)(vertex.length-1), (y+1)/(float)(vertex[0].length-1));
				gl.glNormal3d(normal[x+1][y+1].getX(),normal[x+1][y+1].getY(),normal[x+1][y+1].getZ());				
				gl.glVertex3d(vertex[x+1][y+1].getX(),vertex[x+1][y+1].getY(),vertex[x+1][y+1].getZ());

				gl.glTexCoord2f(x/(float)(vertex.length-1), (y+1)/(float)(vertex[0].length-1));	
				gl.glNormal3d(normal[x][y+1].getX(),normal[x][y+1].getY(),normal[x][y+1].getZ());				
				gl.glVertex3d(vertex[x][y+1].getX(),vertex[x][y+1].getY(),vertex[x][y+1].getZ());

			}
		}

		gl.glEnd();

so to increase the performance i move all the data in a FloatBuffer but still i using the same algorithm to popoluate it
so means that i populate the FloatBuffer with GL_TRIANGLES


		gl.glInterleavedArrays(GL_T2F_N3F_V3F, 0, modeldata);
		gl.glDrawArrays(GL.GL_TRIANGLES, 0, modeldataElements);

the floatBuffer generate is very big, its size is


int length = maxX*maxY;	//total vertex
modeldata = FloatBuffer.allocate(length*(6*(2 texture cordinate)+6*(3 normal cordinate)+6*(3 vertex cordinate)));

for a grid of 100 x 100 i have = 100 x 100 x 48 = 480.000 elements
actually in my games im using grid of 100 x 800 = 3.840.000 elements

the result in terms of performance is not increased,
and with my big surprise for big grid the fixed pipiline call are faster that the use of the glDrawArrays

so now I would like to use the GL_TRIANGLE_STRIP, because in this way i can reduce the size of the FloatBuffer and may be in this way i can increase the performace

that mean that i have to find a different algorithm to populate the FloatBuffer

is there someone of u that populate a grid with GL_TRIANGLE_STRIP and the data stored in 3 arrray like this one?
texture (x,y)
norma (x,y)
vertex (x,y)

To shrink the buffer size you could use a ibo.

See http://www.lwjgl.org/wiki/index.php?title=The_Quad_with_DrawElements.

[quote]In a previous tutorial we’ve used “glDrawArrays” to draw a quad on the screen. The downside with DrawArrays is that you have to specify each vertex of a triangle in your model. A quad may have 4 corners but when a quad is divided in 2 triangles it has 6! With “glDrawElements” we can remove those duplicate vertex definitions. In return we’ll have to tell OpenGL which vertex to use for each triangle by using indices. Let’s see how that works.
[/quote]
alternative:

If you are just using a highmap you could send the high data as texture and calculate the data within a shader.

VG ClaasJG

//OFFTOPIC: (p.s.: https://www.opengl.org/sdk/docs/man3/xhtml/glPolygonMode.xml)

I just want to throw in that I had the same issue about a month back, I switched over to using glDrawElements, and didn’t bother with using GL_TRIANGLE_STRIP, I just used triangles. I can’t say that I saw a substantial performance increase, but I did notice that I didn’t take nearly as much of a hit when I increased the size of my terrain.

Honestly though, ClaasJG is right about using a texture in a shader for this.

ok guys thanks for the trick

first of all i create the alghortim for the triangle strip, I post it in case someone will found in future the same issue

what can i say that now that i running the highmap with the triangle strip it is faster that before
it increase the frames of 15-20 % for second

now i will try also with the glDrawArrays


		for(int y = 0; y < vertex[0].length-1; y++) {		
			gl.glBegin(GL2.GL_TRIANGLE_STRIP);
			for (int x = 0; x < vertex.length-1; x++) {

				gl.glTexCoord2f((x)/(float)(vertex.length-1), (y+1)/(float)(vertex[0].length-1));
				gl.glNormal3d(normal[x][y+1].getX(), normal[x][y+1].getY(), normal[x][y+1].getZ());
				gl.glVertex3d(vertex[x][y+1].getX(), vertex[x][y+1].getY(), vertex[x][y+1].getZ());

				gl.glTexCoord2f((x)/(float)(vertex.length-1), (y)/(float)(vertex[0].length-1));					
				gl.glNormal3d(normal[x][y].getX(), normal[x][y].getY(), normal[x][y].getZ());
				gl.glVertex3d(vertex[x][y].getX(), vertex[x][y].getY(), vertex[x][y].getZ());

				
			}
			gl.glEnd();
		}

But you are using glDisplayList?
I mean compatibility profile rules :point:

ClaasJG

no i’m not using the glDisplayList, i’m just calling the primitive for now during the display(GLAutoDrawable drawable) phase

anyway, I finished just 5 minutes ago the implementation with the the glDrawElements
actually i have the indexes in in arrays in indexdata[] becouse i’m using the GL_TRIANGLE_STRIP

the result is incredible for my
i have incremented the frame rate of the 600%


		gl.glInterleavedArrays(GL_T2F_N3F_V3F, 0, modeldata);
		
		for (int i = 0; i <  indexdata.length-1; i++) {		
			gl.glDrawElements(GL2.GL_TRIANGLE_STRIP, vertex.length*2, GL.GL_UNSIGNED_INT, indexdata[i]);
		}

This are the results of my test
with a grid of 634 x 355 = 225070 vertexs

1 version) using fixed pipeline functions GL_TRIANGLES i get 16 fps
2 version) using glDrawArrays GL.GL_TRIANGLES i get 10 fps
3 version) using fixed pipeline functions GL_TRIANGLE_STRIP i get 22 fps
4 version) using several glDrawElements GL.GL_TRIANGLE_STRIP i get 120 fps!!!

my final modification now will by to change the glDrawElements with the glMultyDrawElements
at this point i will make also a test with the glDisplayList