Jump to content
  • Advertisement
Sign in to follow this  
HalcyonX

problem with display lists

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

For some reason, display lists are slowing down my application rather than speeding things up. If i run my app just by straight drawing the polygons, i get ~105 fps. With display lists enabled, however, things slow down to ~28. The display lists are only created once during the drawing of the first. I am keeping a Hashtable where the key is my object's id, and value what glGenLists() returns. During each call to my drawing method, i check to see if the object's id is in the Hashtable. If it is, i just call glCallList() on the value in the Hashtable. Otherwise, i create the display list and print some output to screen, telling me its creating a new list. When i run the app, the messages only print once, so im sure that im only creating the lists once. Yet, the fps is so much lower. Can anyone help? Below is the code of my drawing function. It takes a data structure containing the object that i want to draw, and draws it. BTW, im using C# for its portability and ease of use. So... hope u guys know C#. =P
public bool drawObject(GameObject obj) 
{
	// Used for loops
	Polygon currentPolygon;
	Vertex currentVert;

	if (obj.GetType().IsSubclassOf(typeof(Creature)))
	{
		foreach (Component part in ((Creature)(obj)).components)
		{
			drawObject(part);
		}
	}
	else
	{
		if (displayLists[obj.objectID] == null)
		{
			game.print("creating display list for " + obj.objectID);
			int list = Gl.glGenLists(1);

			Gl.glNewList(list, Gl.GL_COMPILE);

			// loop through all polygons of OBJ
			for (int i = 0; i < obj.model.polygons.Length; i++)
			{
				currentPolygon = obj.model.polygons;

				Gl.glColor4f(currentPolygon.color.r, currentPolygon.color.g, currentPolygon.color.b, currentPolygon.color.a);

				// Check to see that the current bound texture isnt already
				// the one we want.
				if (!currentTexture.Equals(currentPolygon.texName))
				{
					if (!loadTexture(currentPolygon.texName))
					{
						return false;
					}
					Gl.glBindTexture(Gl.GL_TEXTURE_2D, (int) textures[currentPolygon.texName]);
					currentTexture = currentPolygon.texName;
				}

				switch (currentPolygon.verticies.Length)
				{
					case 3:
						Gl.glBegin(Gl.GL_TRIANGLES);
						break;
					case 4:
						Gl.glBegin(Gl.GL_QUADS);
						break;
					default:
						Gl.glBegin(Gl.GL_POLYGON);
						break;
				}

				Gl.glNormal3f(currentPolygon.normal.x, currentPolygon.normal.y, currentPolygon.normal.z);
				
				for (int vertI = 0; vertI < currentPolygon.verticies.Length; vertI++)
				{
					currentVert = currentPolygon.verticies[vertI];

					if (currentVert.texCoords != null)
					{
						Gl.glTexCoord2f(currentVert.texCoords.x, currentVert.texCoords.y);
					}
					Gl.glVertex3f(currentVert.x, currentVert.y, currentVert.z);
				}

				Gl.glEnd();
			}

			Gl.glEndList();

			displayLists.Add(obj.objectID, list);
		}

		// Reset view
		Gl.glLoadIdentity();
		
		float x = game.camera.chaseObject.position.x;
		float y = game.camera.chaseObject.position.y;
		float z = game.camera.chaseObject.position.z;

		Glu.gluLookAt(x + game.camera.xMod, coolGame.Utilities.Util.forceIntoRange(y + game.camera.yMod, 0.01, double.MaxValue), z + game.camera.zMod, x, y, z, 0, 1, 0);

		// Translate and rotate according to OBJ's position and angle
		Gl.glTranslatef(obj.position.x, obj.position.y, obj.position.z);
		Gl.glRotatef(obj.angle.y, 0, 1, 0);
		Gl.glRotatef(obj.angle.x, 1, 0, 0);
		Gl.glRotatef(obj.angle.z, 0, 0, 1);
		
		// call display list to do the drawing
		Gl.glCallList((int)displayLists[obj.objectID]);
	}

	return true;
}


[Edited by - HalcyonX on July 21, 2005 8:24:12 PM]

Share this post


Link to post
Share on other sites
Advertisement
It's simple if you understand the dynamics of display lists.

A display list is basicly a list of opengl comands that can be executed at will.
this makes things easier, but it will not give mutch of a speed increase.
So to speed things up openGL "compiles" the display list by precalcylating things like vertex coordinates and so on.

Now this is ok if your rendering things at the same place all the time.
But your not, you are constantly moving the camera witch forces the display lists to recompile every frame.
I don't know if this accounts for the entire slowdown, but why use something that is slower.

Share this post


Link to post
Share on other sites
If I understand correctly, display lists are used to work with objects that won't change (as stated). If you have a table mesh, for example, you may use a display list to provide some speedup (don't think its too great, but it should be positive).

The problem could also have to do with hardware, I believe. Too little VRAM or slow VRAM (shared RAM) may not work with lists too well (if I recall correctly).

Share this post


Link to post
Share on other sites
ooh i see. I previously thought that display lists arent dynamic in that you cant change whats inside them. Didnt know that you cant even move them around. So in this case, i should use VBOs instead?

Share this post


Link to post
Share on other sites
Wait... i just looked into display lists again, and it seems like you *can* translate them around and draw them at different places. For instance, there is this tutorial on google that makes a display list of a snowman, and places 36 instances of it at different places using a for-loop, and still gained a huge performance increase.

Share this post


Link to post
Share on other sites
Display Lists are not dynamic internally so you can't modify them once created. But you CAN move then and whatever cuz that is done outside of the list. In fact, you can even change state setting that aren't done in the list and the list will be affected. For example, if inside the list, you never set a color, then the list goes with whatever the current color is. So if you want the same thing, but various colors, that is another advantage. The lists don't get recompiled by moving the camera though. The commands would still execute the same, going by what the current states and matrices are.

Share this post


Link to post
Share on other sites
yea I (or.. someone on the gamedev openGL forums.. hehe) found the problem. The way i had things set up, it was loading textures from files inside the display list... haha... stupid newbie mistake. =X With that fixed, its running much faster now.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!