Skip to main content
gamedev.net
🔒 Locked

2D issue

Started by u235 Jan 17, 2008 at 11:46 PM 4 replies 700+ views
Original Post
u235
u235
I am getting ready to start a fairly complex 2D game and I had a question I wanted to clear up before I call my design good and start coding. How big of an issue is culling non-visible objects in a 2D game? Obviously the answer to this question is dependent on the number of objects in the game, but as a general rule, is the performance gain worth the extra coding to cull non-visible objects? Thanks for the help. [Edited by - u235 on January 20, 2008 8:31:37 PM]
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
Hodgman
Hodgman
It really depends how big your world is, and how much of it you can see at once.

E.g. if you can see 90% of the world at once, then culling might not be needed. But if you have a huge world and can only see 1% at once, then culling is definitely a necessity!
Zipster
Zipster
As a general rule, you will almost always want to implement a culling system. Even something simple like a bounding box or bounding circle test (less than dozen lines of code?) against the viewport can yield huge performance gains if you have a lot of objects. Initially it can just cull objects from rendering, but over time as your game gets more complex you might want to cull other things like certain game logic, animation, sounds, etc. The fastest code is that which you don't execute :)
Boder
Boder
I questioned this too.

Assuming:
1) The only way to check for "culling" is bounding box with the screen/viewport
2) Their is no game logic change depending on rendering for the object

Will their be a performance gain if you do it on the CPU instead of just sending it to OpenGL?

I suppose it might depends on whether your using immediate mode or display lists, arrays, buffers, etc.
u235
u235
Thanks for the replies. I think I am going to implement something very simple and compare it to the results of no culling. If the performance gain warrants, I'll put a little more work into making something faster. Thanks again.
V/R,-AJThere are 10 kinds of people in the world: Those who understand binary and those who don't...
OrangyTang
OrangyTang
Quote:
Original post by Boder
Assuming:
1) The only way to check for "culling" is bounding box with the screen/viewport
2) Their is no game logic change depending on rendering for the object

Will their be a performance gain if you do it on the CPU instead of just sending it to OpenGL?

In general, yes I find it helps performance to cull manually. Even if your culling is a brute force per-sprite bounding box it'll mean you have to create and send less vertex data and potentially less shader and texture switches. The only time I'd consider not culling is if you're doing an arena shooter or similar where there's no scrolling and practically everything is visible at the same time.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.