Display list performance

Started by
5 comments, last by Aks9 12 years, 10 months ago
Hi,

I am creating a simple 3D game, but I found a problem:

When I place 30 trees of ~1000 triangles (1 tree = 2 display lists (branches + trunk)), FPS are already below 50 - which is pretty bad :(

So, my question is:

Are display lists just a bad technique, or I am doing something wrong? Should I use VBOs instead?

Thanks for answers.

Advertisement
1. nowadays u should use VBO, because display lists are deprecated
2. your problem in this case is that u have so many draw calls and probably drawing always the trunk and branches of each tree instead of first only the trunks and then the branches,
try to render all trees in 1 display list
60 display lists is not a great number of calls to have any problem in drawing. I handled several thousands of calls per frame.

You are probably doing something wrong. Can you post your drawing code? Are you using only glCallList() for drawing?

If you are creating your lists in a draw call, that's the reason for a significant performance drop.

I'm using Lib3ds to load 3ds models.

Here is how it creates display list for mesh.

glNewList(mesh->user.d, GL_COMPILE);
Lib3dsVector *normalL=(Lib3dsVector *)malloc(3*sizeof(Lib3dsVector)*mesh->faces);
Lib3dsMaterial *oldmat = (Lib3dsMaterial *)-1;
Lib3dsMatrix M;
lib3ds_matrix_copy(M, mesh->matrix);
lib3ds_matrix_inv(M);
glMultMatrixf(&M[0][0]);

lib3ds_mesh_calculate_normals(mesh, normalL);

glBegin(GL_TRIANGLES);
for (int j=0; j<mesh->faces; ++j)
{
Lib3dsFace *f=&mesh->faceL[j];

Lib3dsMaterial *mat=0;
int tex_mode = 0;
if (f->material[0]) mat=lib3ds_file_material_by_name(file, f->material);

if( mat != oldmat )
{
if (mat)
{
if (mat->two_sided) glDisable(GL_CULL_FACE); else glEnable(GL_CULL_FACE);
if (mat->use_wire ) glEnable(GL_ALPHA_TEST); else glDisable(GL_ALPHA_TEST);
}
oldmat = mat;
}

int i;
if (f->user.i>0)
{
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,f->user.i);
}

glNormal3fv(f->normal);
for (i=0; i<3; ++i)
{
glNormal3fv(normalL[3*j+i]);
float scale=1;
if (mesh->texels>0)
{
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,mesh->texelL[f->points][0]*scale, mesh->texelL[f->points][1]*scale);
}
glVertex3fv(mesh->pointL[f->points].pos);
}


}
glEnd();
free(normalL);
glEndList();
1. move all loading code out of the display list setting (it shouldn't make trouble, but I don't know what is called inside all those functions)

2. also move out texture related functions except texture coordinate setting. (why are you using glActiveTextureARB() if only GL_TEXTURE0 is used? Also glEnable(GL_TEXTURE_2D) is superfluous here.)

Try to enclose only loop and glNormal/glTexCoord/glVertex function calls inside glNewList/glEndList. What version of OpenGL are you using? Why there is aways ARB suffix? All those functions are in core since GL 1.3 or so.


1. move all loading code out of the display list setting (it shouldn't make trouble, but I don't know what is called inside all those functions)

2. also move out texture related functions except texture coordinate setting. (why are you using glActiveTextureARB() if only GL_TEXTURE0 is used? Also glEnable(GL_TEXTURE_2D) is superfluous here.)

Try to enclose only loop and glNormal/glTexCoord/glVertex function calls inside glNewList/glEndList. What version of OpenGL are you using? Why there is aways ARB suffix? All those functions are in core since GL 1.3 or so.


OMG!! I moved glBindTexture outside list and FPS increased from 50 to 500 :D :D


Thank you for advice. Too bad I can't give you more than one +rep.
I'm glad I could help. The reputation is not important. :cool:

This topic is closed to new replies.

Advertisement