Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (498)
Games in Android Showcase (115)
games submitted by our members
Games in WIP (563)
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  
  GRID with glInterleavedArrays and GL_TRIANGLE_STRIP  (Read 688 times)
0 Members and 1 Guest are viewing this topic.
Offline alesky

Junior Member


Medals: 3
Exp: 15 years


mmm....


« Posted 2014-08-06 22:14:31 »

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
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

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


the floatBuffer generate is very big, its size is

1  
2  
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)





Offline ClaasJG

Junior Member


Medals: 4



« Reply #1 - Posted 2014-08-06 23:39:58 »

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.

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)

My english has to be tweaked. Please show me my mistakes.
Offline thedanisaur

Senior Member


Medals: 10
Exp: 1 year



« Reply #2 - Posted 2014-08-07 07:47:43 »

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.

Every village needs an idiot Cool
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline alesky

Junior Member


Medals: 3
Exp: 15 years


mmm....


« Reply #3 - Posted 2014-08-07 20:10:17 »

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


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
      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();
      }
Offline ClaasJG

Junior Member


Medals: 4



« Reply #4 - Posted 2014-08-07 20:14:51 »

But you are using glDisplayList?
I mean compatibility profile rules  Pointing

ClaasJG

My english has to be tweaked. Please show me my mistakes.
Offline alesky

Junior Member


Medals: 3
Exp: 15 years


mmm....


« Reply #5 - Posted 2014-08-07 23:29:50 »

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% 

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





Pages: [1]
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

radar3301 (12 views)
2014-09-21 23:33:17

BurntPizza (29 views)
2014-09-21 02:42:18

BurntPizza (19 views)
2014-09-21 01:30:30

moogie (20 views)
2014-09-21 00:26:15

UprightPath (27 views)
2014-09-20 20:14:06

BurntPizza (31 views)
2014-09-19 03:14:18

Dwinin (48 views)
2014-09-12 09:08:26

Norakomi (74 views)
2014-09-10 13:57:51

TehJavaDev (102 views)
2014-09-10 06:39:09

Tekkerue (50 views)
2014-09-09 02:24: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!