Archived

This topic is now archived and is closed to further replies.

fallingbrickwork

Big Performance Hit!!

Recommended Posts

Hi all, I am currently writing a simple `Space Invaders` type game and wanted a nice colourful space type background behind all the action. I thought of using a texture mapped QUAD... How wrong was I?! The frame rate of the game is fine until I turn on this QUAD. It then drops dramatically!! As the QUAD is sitting behind all the action it has to be very big to appear to fill the screen, is this what is slowing the frame rate?? Is it not a good idea to use very big QUADS?? How would you display a nice colourful background? I didn''t think using ONE large QUAD would have such an effect of the FPS! Many thanks, fallingbrickwork.

Share this post


Link to post
Share on other sites
It''s quite possible you''re fillrate limited. Just how significant is the performance hit?

I think adding a skybox to my program using immediate mode calls ate about 30 FPS (a 10% performance drop), but that wasn''t crucial since I hadn''t optimized yet. Anyway, point is that you''re gonna get a performance hit, and if it''s too extreme to be acceptable, you''ll have to find a better way to do it.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

Share this post


Link to post
Share on other sites
I''m not sure of the exact FPS performance drop, I''m purely looking at the results from a gamers point of view. It is a noticable drop in frame rate. As this is my first attempt at a complete game, I''m not sure whether what I am finding un-acceptable is just me being picky. You mention "I hadn''t optimized yet". How/What did you look at to try and squeeze a few more FPS out of your project? How else could I achieve a textured background? Would splitting the QUAD into 4 smaller textured QUADS help or would the overall performance hit equal-out in the end?

Cheers,
fbrickwork.

Share this post


Link to post
Share on other sites
Well, a triangle strip is faster than a quad. You should get used to using those first.
glBegin(GL_TRIANGLE_STRIP);
// input verticies in this order
// 1-2
// |/|
// 3-4
glEnd();
What''s the resolution on your texture? See how small you can get the image without losing too much quality.

How old is your graphics card? Comp speed? It does sound like you''re just slaughtered with the fillrate.

------------
MSN: nmaster42@hotmail.com, AIM: LockePick42, ICQ: 74128155
"It''s all part of the conspiracy of conspirators conspiring to conspire their own conspiracies..."

Share this post


Link to post
Share on other sites
you can draw your background at a greater z coordinate after you draw all opaque objects on screen, thus saving on fillrate.

Share this post


Link to post
Share on other sites
The resolution of the Texture is 256x256.

Does rendering foreground objects before background objects affect rendering performance or not?

How do I implement a `skybox`?

Am I right in saying that this is a large textured cube that sits around your game world?? If this is so, wouldn''t rendering a complete cube cause more of a performance hit than 1 QUAD?

Share this post


Link to post
Share on other sites
Also, as a furthar performance enhancement: providing the quad is the first thing you render, you can turn off Z-buffer writes and checking, then render the Quad. Then render everything else.

[edited by - MrWugga on September 3, 2002 5:28:40 AM]

Share this post


Link to post
Share on other sites
Hi all,

With regards to Mr.Wugga''s comment on `Turning off the z-buffer`, it sounds like a good idea. I was just searching good ole `google` on z-buffering etc and found this:

---------------------------------------------------------------
Z-Buffer and the Freedoms
Curiously, turning on Z-buffering allows the Freedoms to perform much faster than with it off. This is because when Z-buffering is on, OpenGL allows the system to draw primitives in any order it wants, and not in the order the user specified them. This liberty allows the Freedoms to distribute primitive drawing among its processors, providing much better performance.
---------------------------------------------------------------

What does anyone think about this? Is the above correct?
I''ll try turning off the z-buffer 2nite and see if I get any FPS increase.

Cheers.

Share this post


Link to post
Share on other sites
One thing that kills performance ( and how I got a 30fps increase using a skybox ) is clearing the colour buffer bit. Don''t do it.

Death of one is a tragedy, death of a million is just a statistic.

Share this post


Link to post
Share on other sites
If you have a solid background, then he''s right, don''t clear the colour bit. But you will still have to clear the depth. And make sure you turn depth testing back on after you draw your background.

Share this post


Link to post
Share on other sites
writing a large quad in the background can give you a huge performace drop. This happens because your card is fillrate limited (nr of pixels it can draw per sec)
It is well possible that drawing your little ships/whatever might actually take less time then drawing your background.(althrought you need to push more triangles/quads per frame for those, they take very little space on screen - so much fewer pixels are drawn)

And the ideas about not clearing buffers is good.
Simply the first thing you do when drawing a new frame is:
-turn z-buffer test off
-draw your background quad (set Z-value of it to be greater then any other object appearing on screen)
-turn z-buffer test on - so other objects get drawn correctly
-draw other objects here

As you can see there''s no z-buffer nor color buffer clearing.
It''s simple not needed because your first step is to draw your background image which fills both color and z-buffer.

Share this post


Link to post
Share on other sites
Thanks for all the great replies.

I spent last night turning off as many things as I could before drawing the background and then enabling them again after and (holding both hands up) I''d left the Stencil enabled from doing some tests earlier in the week. When I disabled this I got some of my FPS back. There is still a drop in frame rate but not as dramatic as before.

I think this is a lesson to be learned for all beginners:

`If you don''t need it......Don''t enable it!!!!`

I''m going to replace the QUAD with a TRIANGLE_STRIP in a last attempt to recover a few more FPS.

Is the `Fillrate limit` based on the total number of pixels the gfx card is rendering. i.e Would splitting the background down into 9 smaller QUADS actually produce the same Fillrate penalties
because the overall number of pixels will be the same? (Does this make sense?)

Share this post


Link to post
Share on other sites
if it''s game logic speed that has noticably slowed (not frame rate) then it may well be a case that your frame rate has just gone from, say, 600 to 200... which wouldn''t be surprising with a significant increase in fill rate demand...
while I don''y doubt your''ve noticed a difference,
I find it very hard to believe that a single full screen quad could drop the frame rate below 25ish (when it''s noticable) UNLESS you are running in software... Even my old 2mb s3 virge wouldn''t do that... (shudder)

Share this post


Link to post
Share on other sites
fill rate is the number of pixels drawn, redrawn (overdraw - which can be hard to understand) and other obvious things like blending (which roughly halves fill rate ontop of the overdraw)...
so 9 quads wouldn''t help..
what would help, though, would be to draw the backdrop after all other solid objects (non-blended) so the z-test can cull a lot of excess pixels that would otherwise been overdrawn (at slightly less cost)...

Share this post


Link to post
Share on other sites
try vertex/tex_coord array with triangle strip and
for optimization an octree, and for more FPS some
disabling vsync...
(a MAX OPENGL framerate=600FPS=nothing... 250 with some good quality 3ds...)

Share this post


Link to post
Share on other sites
MAX OPENGL FRAMERATE=600fps?

What?

The only thing that determines maximum framerate is how fast your machine is. With an empty drawing loop, I''ve gotten 4-digit framerates. queryPerformanceCounter was returning single digits.

Drawing the background last, using the z-buffer, will certainly work - if you are in orthogonal mode. Otherwise, it has to be drawn first, with z-buffering turned off. And it may not make a difference if you do draw it last. How much worse is drawing extra pixels then checking the z-buffer?

Share this post


Link to post
Share on other sites
by saying 600 to 200 I was trying to make a point, no matter how realistic it was... I''ve maintained over 400fps with fairly complex (fully drawn) scenes before...

quote:

How much worse is drawing extra pixels then checking the z-buffer?


I''d expect it''d depend on the hardware a fair bit. but there is definitly a difference. (I can''t say how significant though)

If you are running in software, and want to get as many pixels through as possible, when drawing the background, disable texture filtering and set the perspective hinting to per vertex (fastest) not per-pixel, this will significantly boost fill rate in software, but have virtually no effect in hardware.

Share this post


Link to post
Share on other sites