Sign in to follow this  

Optimization

This topic is 4243 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

Right now the graphics part of my 2D racing game is really slowing everything down. All I'm rendering is two textured background quads and a bunch of textured triangles in the form of a racetrack. The background is really slowing everything down a lot; without it I get an improvement of around 20 FPS. I will probably cut it down to just one quad to get a little more performance, but does anyone know of a good way to optimize a fairly detailed and large textured quad?

Share this post


Link to post
Share on other sites
What are the dimensions of your background-texture? (e.g. 256x256 or 512x512) Make sure both its width and height are power-of-2 values. Something like 800x600 (non-power-of-2) can seriously slowdown your app.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mr Awesome
Right now the graphics part of my 2D racing game is really slowing everything down. All I'm rendering is two textured background quads and a bunch of textured triangles in the form of a racetrack. The background is really slowing everything down a lot; without it I get an improvement of around 20 FPS. I will probably cut it down to just one quad to get a little more performance, but does anyone know of a good way to optimize a fairly detailed and large textured quad?


Sounds like something is off in your code. What are you doing to draw the textured quads each frame?

Share this post


Link to post
Share on other sites
The bottleneck is entirely in the graphics rendering. I'm currently using immediate mode to render everything. I tried a display list for the racetrack, but it didn't help one bit.

Share this post


Link to post
Share on other sites
Two textured quads would not stress any graphics card that has been made in the last several years. From what I can gather without seeing your code, you are doing something very expensive and inefficient (like transferring a large texture over the system bus) every frame.

Share this post


Link to post
Share on other sites
This is the only code getting called with respect to the background:

// Displays part of the image to the screen using the four vertices of a
// quad given as the texture's destination.
void Texture::Render(int srcLeft, int srcTop, int srcWidth, int srcHeight,
Vector2D topLeft, Vector2D topRight,
Vector2D bottomLeft, Vector2D bottomRight) const
{
// Texture Coordinates
float tLeft = srcLeft / static_cast<float>(m_Width);
float tRight = (srcLeft + srcWidth) / static_cast<float>(m_Width);
float tTop = srcTop / static_cast<float>(m_Height);
float tBottom = (srcTop + srcHeight) / static_cast<float>(m_Height);

// Prepare for rendering.
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glBindTexture(GL_TEXTURE_2D, m_TextureID);

// Render textured quad.
glBegin(GL_QUADS);
glColor3f(1.0f, 1.0f, 1.0f);

// Top-left
glTexCoord2f(tLeft, tTop);
glVertex2f (topLeft.x, topLeft.y);

// Top-right
glTexCoord2f(tRight, tTop);
glVertex2f (topRight.x, topRight.y);

// Bottom-right
glTexCoord2f(tRight, tBottom);
glVertex2f (bottomRight.x, bottomRight.y);

// Bottom-left
glTexCoord2f(tLeft, tBottom);
glVertex2f (bottomLeft.x, bottomLeft.y);
glEnd();

glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
}


I'm definitely not loading the texture more than once; I have a texture manager that makes sure of that. Could it be that the background picture is too high quality?

Also, for the racetrack, would a vertex array possibly give a performance boost?

Share this post


Link to post
Share on other sites
What is your graphics card? What is the screen resolution and color depth? What is the size of the texture and its color depth?

Share this post


Link to post
Share on other sites
"improvement of around 20 FPS" is pretty much meaningless as a metric. What is your FPS before and after?

Share this post


Link to post
Share on other sites
S3 Graphics ProSavageDDR

Screen: 800x600; 32 bits
Texture: 6400x2400; 32 bits

I guess the texture is huge, but I don't see how I could make it smaller without doing an ugly repeat. Maybe I could create a parallax effect so it wouldn't have to reach the edges of the screen.

Share this post


Link to post
Share on other sites
That is a friggin' huge texture for a skybox. What's actually IN the texture? Most skies are limited to low-frequency features.

Share this post


Link to post
Share on other sites
This is a 2D essentially sidescrolling game. The texture covers the background of the entire level. It is basically the Earth's surface as viewed from a very high altitude.

Share this post


Link to post
Share on other sites
Aren't many old-ish graphics cards limited to 1024x1024 for textures? If so, that'll really reduce the amount of people who can use your game. Why do you kneed such a high-res sky box?

Edit: Ahh.. I'd try breaking it up into chuncks then. It shouldn't be that much work, either.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mr Awesome
This is a 2D essentially sidescrolling game. The texture covers the background of the entire level. It is basically the Earth's surface as viewed from a very high altitude.

Then you should (a) break it into screen-sized chunks, and (b) scale it down to about 512x512 texels per screen.

Share this post


Link to post
Share on other sites
As Sneftel has said, giving the before and after FPS would help.

So at the moment, you are drawing a 6400x2400 quad, with a 1024x1024 texture, but only using 800x600, so your texture co-ordinates are 0,0-800/1024,600/1024. Then to scroll, you're translating the quad? Correct?

If that is what you're doing, you might change it a bit. Use an 800x600 quad, and alter the texture co-ordinates. You could also try to enable the scissor test.

Note however that your card is pretty old, and even in it's day it wasn't the best preformer. This could account for unexpectedly poor performance. Do you have the latest drivers for regardless?
Various S3 Savage information via Wikipedia

Edit: What's the rest of your system like too? CPU and Mem? I think this is a review involving your card, or a close relative, and it's getting about 60FPS at 800x600 16-bit in Quake 2. If I remember rightly, that was a time when the 32-bit performance of a card was noticably worse than 16-bit, if it offered 32-bit at all.

Share this post


Link to post
Share on other sites
Yes, my card is fairly poor as graphics cards go (I think). Without rendering, my FPS was 60, but then dropped to 30 and below when I rendered stuff. So actually there was a 50% drop in framerate when I started rendering stuff. I think 60 FPS is extremely slow for what I'm doing, but I'm definitely not an expert programmer.

However, I optimized the graphics a little by shrinking the textures to 256x256, flattening them to one texture, and only displaying an 800x600 quad on the screen at any one time. It actually looks better now, since you wouldn't expect the Earth's surface to appear to move with you at all from that distance. It really gives the effect of a racetrack suspended high in the atmosphere, which looks great and boosts my FPS back up to 40 (along with a small optimization on the track surface). Any other ideas for optimization?

Share this post


Link to post
Share on other sites
Well, there are two strategies you can use for backgrounds; one is occasionally better for old cards, the other is better for new cards. The first method is to render the background first, with Z-testing and Z-writing both disabled. That'll reduce the load on the Z-buffer. The second method is to render the background last, with Z-testing enabled and Z-writing disabled. That'll reduce the load on the framebuffer, and will also reduce the load on texture memory and pixel processors if the card does early Z testing (your card, I am nearly certain, does not). Try both these strategies. Also consider WHOSE card you should be optimizing for.

Share this post


Link to post
Share on other sites

This topic is 4243 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.

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