How to manage drawing loop when changing render targets

Posted by George Duckett on Game Development See other posts from Game Development or by George Duckett
Published on 2012-04-18T10:38:35Z Indexed on 2012/06/17 15:26 UTC
Read the original article Hit count: 260

Filed under:
|
|

I'm managing my game state by having a base GameScreen class with a Draw method.

I then have (basically) a stack of GameScreens that I render.
I render the bottom one first, as screens above might not completely cover the ones below.

I now have a problem where one GameScreen changes render targets while doing its rendering. Anything the previous screens have drawn to the backbuffer is lost (as XNA emulates what happens on the xbox). I don't want to just set the backbuffer to preserve its contents as I want this to work on the xbox as well as PC.


How should I manage this problem?

A few ideas I've had:

  1. Render every GameScreen to its own render target, then render them all to the backbuffer.
  2. Create some kind of RenderAction queue where a game screen (and anything else I guess) could queue something to be rendered to the back buffer. They'd render whatever they wanted to any render target as normal, but if they wanted to render to the backbuffer they'd stick that in a queue which would get processed once all rendertarget rendering was done.
  3. Abstract away from render targets and backbuffers and have some way of representing the way graphics flows and transforms between render targets and have something manage/work out the correct rendering order (and render targets) given what rendering process needs as input and what it produces as output.

I think each of my ideas have pros and cons and there are probably several other ways of approaching this general problem so I'm interested in finding out what solutions are out there.

© Game Development or respective owner

Related posts about XNA

Related posts about rendering