• Advertisement
Sign in to follow this  

Design a render queue

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

HI,

I want to design a game engine by myself, and now I'm start to design "render" part .

I know change the render state is very expensive. so use a render queue to split the render object in different queue is a good idea(truth?).

But i have no idea how to start this design.

How many kinds of queue i should use?

How can I determine this object is suitable for queue A or queue B?

Could you give me some suggestion?

Share this post


Link to post
Share on other sites
Advertisement
I think what you mean is called "state sorting": You sort your queue for render state.

Personally, I strongly believe to keep the engine as simple as possible until it actually runs with all the features you want (which is enough work, for starters). As a single-handed developer, you certainly don't want to waste time with premature optimization, do you? ;-)

Simply add all your objects to one queue and render them in that order. Concern yourself more with culling at this stage of development. Removing an object from the queue altogether because it is not currently visible may well proof to be way more effective than state sorting. Once your code is feature-complete, state sorting is easily added afterward.

So much for preaching, now let's have a look at how state sorting works:

The basic idea is to have a simple representation of the render state of each object (an unsigned int filled with flags, for example), and then sort your queue for this value. Theory says that all objects that require the same render state end up close together in the sorted queue and get rendered consecutively as a consequence.

Note, however, that unless you render lots of (nearly) identical objects it is quite common for all your object requiring different state (that's why I called this technique "premature optimization" previously). Certainly, the orientation and position do normally change with each object, and normally texture maps and shaders do, too. Some Objects may even require different parts to be rendered with different states (think of an otherwise opaque model with only some transparent parts).

Especially transparency introduces another problem to state sorting: It may be necessary to render transparent objects in a back-to-front order to avoid artifacts. But now you end up with two different orders to sort for: screen depth and state. And gone is your simple invocation of std::sort, or how ever it is called in the language of your choice!

To solve this problem, you could split the transparent parts from the object itself and put them in a second render queue. Now first render the opaque things, and after that the transparent parts. First queue sorted by state, second by depth. That would be similar to your queues A and B.

Hope that helped...

Share this post


Link to post
Share on other sites
http://www.amazon.com/Game-Engine-Gems-Volume-One/dp/0763778885/ref=sr_1_1?ie=UTF8&qid=1355767299&sr=8-1&keywords=game+engine+gems

Chapter 10, Camera Centric Engine Design.

Share this post


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

  • Advertisement