Sign in to follow this  
Raveler

isometric engine performance issues

Recommended Posts

Raveler    132
Hello guys, I've been working on a low-end isometric engine for a while now. I never really payed attention to optimization, but I did keep in mind basic programming efficiency rules. However I recently hit some serious performance issues, and I really can't believe the FPS I'm getting considering I'm not really doing much yet. The code that seems to be causing the FPS problems is the drawing routine for the terrain:
	for (y = fY - 1; y >= 0; --y) {
		for (x = fX - 1; x >= 0; --x) {

			// get tile
			tile = getTile(x, y);

			// draw base tile
			tile->baseTile->draw();

			// draw transition tile
			tile->transitionTile->draw();

			// translate a bit left
			glTranslatef(float(-fTileSize), 0.0f, 0.0f);
		}

		// translate a bit down and back right
		glTranslatef(float(fTileSize * fX), float(-fTileSize), 0.0f);
	}


Stripped down baseTile->draw() code:
		// get texture
		TextureData *texture = getTexture();

		// enable base texture
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, texture->id);
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

		// start drawing base quad
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f);
			glVertex2i(0, 0);
			glTexCoord2f(1.0f, 0.0f);
			glVertex2i(fTileSize, 0);
			glTexCoord2f(1.0f, 1.0f);
			glVertex2i(fTileSize, fTileSize);
			glTexCoord2f(0.0f, 1.0f);
			glVertex2i(0, fTileSize);
		glEnd();

		// disable texture
		glDisable(GL_TEXTURE_2D);


TransitionTile is used for terrain transitions and is a little more difficult because it also uses alpha blending, but nothing really spectacular. getTexture() handles animation etc, but that's pretty straight-forward as well. For reference, I get 65 FPS on a P3-1,9ghz and 1 FPS on a P2-600 when drawing a 30x20 map. When I remove texturing I get 100 FPS. When I remove the GL_QUAD's I get 300 FPS. So it seems drawing 1200 quads is causing my problem. I can't really believe that drawing 1200 quads can cause my FPS to drop to 1 on a P3-600, so I suspect there's something else going on. The rest of my engine doesn't cause a noticable effect on the FPS. It's definitely the above code that's causing the problems. Anyone got an idea? Or am I just overrating my P3-600 and should I start optimizing?

Share this post


Link to post
Share on other sites
Kylotan    10010
The speed of OpenGL is largely going to be down to your graphics hardware rather than your processor. I am led to believe that the glBegin(GL_QUADS) method is pretty slow. Also, changing texture for each tile is going to be pretty slow too.

The first thing you should do is group tiles by texture, to minimise the number of texture changes. That's the golden rule. If possible, put multiple tiles on one texture to reduce these changes.

If it's still too slow you may need to move from glBegin to using vertex arrays. That way you render a batch of texture-sharing quads at the same time.

I also don't think you need to call glEnable(GL_TEXTURE_2D) all the time; just once at the start of the program should suffice I think.

Share this post


Link to post
Share on other sites
Raveler    132
Yeah, I know of these optimizations. I was just wondering if I was overlooking anything, because it's still pretty slow when taking the inefficiency into account. I mean, there were 486DX games with the same graphical features as my engine :).

Share this post


Link to post
Share on other sites
EDI    3679

one thing you'll want to watch out for is drawing only the tiles that exist in your immediate area. And by this I dont mean having the graphics, clipped, but instead ignoring enumerating over tiles not in the immediate area, this can be done a number of ways, but the way we do it, is by keeping track of the tile we are looking at in the center of our view, then determining our draw area by getting a sub-set of the map based on that center tile coord and a certain area displacement, say, 20 tiles in all directions.

this way, you are only ever enumerating that many tiles, even if your map is 1000x1000 tiles.

Quote:
Original post by Raveler
Yeah, I know of these optimizations. I was just wondering if I was overlooking anything, because it's still pretty slow when taking the inefficiency into account. I mean, there were 486DX games with the same graphical features as my engine :).


well they DID have exclusive access to the frame buffer, and only had to draw 8 bit graphics, with potentially far lower resolutions =D

Share this post


Link to post
Share on other sites
Kylotan    10010
Quote:
Original post by Raveler
Yeah, I know of these optimizations. I was just wondering if I was overlooking anything, because it's still pretty slow when taking the inefficiency into account. I mean, there were 486DX games with the same graphical features as my engine :).


Well, you said that you can't believe that drawing 1200 quads would drop your frame rate down to 1. Personally I can very easily believe that changing the texture 1200 times would drop your frame rate like that. The same thing goes for glBegin; the OpenGL gurus will tell you to drop that immediately. Generally these are slow operations relative to what the hardware is capable of.

[Edited by - Kylotan on March 30, 2005 10:36:28 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this