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:
Quad 2D:
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.