glDrawElements+ Interleaved arrays ?

This topic is 2568 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi,

I have been working on my game project and got my self to a point where I cannot go further on the development before solving this.

I have noticed serious performances drop when too many elements are being rendered at the same time... The only thing left for me to solve this would be reducing the number of elements to draw at the same time, which will seriously affect the gameplay.

I don't want to do this before trying the last rendering optimization left to be implemented, which is the interleaved array.

I have spent too many hours trying to get it done, without any success, which almost turns me crazy. :eek:

i am originally using glDrawElements for rendering elements, and below is the code responsible for this:

 typedef struct _Quad2 { float tl_x, tl_y; float tr_x, tr_y; float bl_x, bl_y; float br_x, br_y; } Quad2; 

Color Filter:
 typedef struct _CFilter { GLubyte r; GLubyte g; GLubyte b; GLubyte a; } CFilter; 

Rendering arrays:
 CFilter *Filters; Quad2 *Vertices; Quad2 *TexCoords; GLushort *indices; int DataNbr; //how many quads to draw int ColorsNbr; //how many color data 

Setting the rendering arrays
 int MAX_QUADS=400; Filters= malloc(sizeof(CFilter)*MAX_QUADS*4); TexCoords = malloc( sizeof(TexCoords[0]) * MAX_QUADS); Vertices = malloc( sizeof(Vertices[0]) * MAX_QUADS); indices = malloc( sizeof(indices[0]) * MAX_QUADS * 6); //VOODOO MAGIC!!!! for( NSUInteger i=0;i<400;i++) { indices[i*6+0] = i*4+0; indices[i*6+1] = i*4+1; indices[i*6+2] = i*4+2; indices[i*6+5] = i*4+1; indices[i*6+4] = i*4+2; indices[i*6+3] = i*4+3; } 

This is the method responsible for sending calculated vertices and colors to the rendering arrays:

 -(void)AddToVertices:(Quad2)ver AndTexCoord:(Quad2)cord Filter:(CFilter)fil{ Vertices[DataNbr]=ver; TexCoords[DataNbr]=cord; DataNbr++; //Storing the same color data 4 times, so each vertex on each quad // would have the same value for (int i=0;i<4;i++) Filters[ColorsNbr+i]=fil; ColorsNbr=ColorsNbr+4; } 

Actual rendering code:
 if (DataNbr>0){ glBindTexture(GL_TEXTURE_2D,[MyIMG TextureName]); glColorPointer(4,GL_UNSIGNED_BYTE, sizeof(Filters[0]), Filters); glVertexPointer(2, GL_FLOAT, 0, Vertices); glTexCoordPointer(2, GL_FLOAT, 0, TexCoords); glDrawElements(GL_TRIANGLES, DataNbr*6, GL_UNSIGNED_SHORT, indices); DataNbr=0; ColorsNbr=0; } 

I would really appreciate your guidance on steps necessary to change this rendering system in order to use interleaved arrays, and that's to get some performances improvements.

Thank you very much.

Share on other sites
You would make a structure for your vertex. Examples are here
http://www.opengl.org/wiki/Vertex_Arrays

You won't necessarily see any performance improvement. That depends on where your bottleneck is.

Share on other sites

You would make a structure for your vertex. Examples are here
http://www.opengl.or...i/Vertex_Arrays

You won't necessarily see any performance improvement. That depends on where your bottleneck is.

I have checked out the link you provided, and am still confused, the reason of the confusion is that the Quad2D structure I am using for rendering is composed of a total of eight (8) float elements, while the structure in the link got only 3 float values (x,y and z) for the vertex, and 6 float values for the texture coordinates.

How to make my Quad2D values fit in the structure on the link you provided???

Share on other sites
The link shows a vertex structure. It is a vertex, not a quad. If you want a quad, then you need 4 vertices

 typedef struct _Quad2 { MyVertex Vertex[4]; } Quad2; 

Share on other sites

The link shows a vertex structure. It is a vertex, not a quad. If you want a quad, then you need 4 vertices

 typedef struct _Quad2 { MyVertex Vertex[4]; } Quad2; 

Silly me! I will try to implement this asap.
Thank you.

1. 1
2. 2
3. 3
4. 4
Rutin
18
5. 5

• 11
• 21
• 12
• 11
• 11
• Forum Statistics

• Total Topics
631405
• Total Posts
2999888
×