Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Hopefully this will be a simple answer, but as RenderTarget2Ds are Texture2Ds under the hood I was wondering how it handles swapping in and out.

Lets say you create a default one and assign it as the render target at the start of your Game.Render(). Then at a few points during your render process a new RenderTarget is swapped in, rendered to and then kept as a texture for later and the original one is then put back in. Some more rendering occurs and another entity swaps in its own RenderTarget, puts it in another texture and then swaps back to the default RenderTarget, and finally everything is rendered and done.

Now as the RenderTarget2D is a Texture2D without setting preserve mode on the RenderTarget will you be able to swap it out and swap it back in without losing your current contents of the RenderTarget?

I know there are some issues with the Preserve settings for RenderTargets on the Xbox, but if the render targets are being stored as a class member somewhere, are they subject to different rules?

I am sure the answer is, they obey the RenderTargetUsage behaviour, and will be subject to the same rules regardless of how they are stored in the game, but I just wanted to be sure.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Hopefully this will be a simple answer, but as RenderTarget2Ds are Texture2Ds under the hood I was wondering how it handles swapping in and out.

RenderTarget2Ds are not Texture2Ds under the hood. A RenderTarget2D is more of a backbuffer that saves the resulting Texture2D to a separate bit of GPU memory when its resolved.

Now as the RenderTarget2D is a Texture2D, without setting preserve mode on the RenderTarget2D will you be able to swap it out and swap it back in without losing your current contents of the RenderTarget?

No. Unless you have PreserveMode on all of the RenderTargets2D share the same bit of memory. When the RenderTargets2D is switched it is resolved into a bit of memory also on the GPU that is used when treating it as a Texture2D. However, the shared bit of memory is completely cleared each time.

I know there are some issues with the Preserve settings for RenderTargets on the Xbox, but if the render targets are being stored as a class member somewhere, are they subject to different rules? I am sure the answer is, they obey the RenderTargetUsage behaviour, and will be subject to the same rules regardless of how they are stored in the game, but I just wanted to be sure.

RenderTargets2D is a convenient abstraction for a ton of stuff happening in the GPU, so nothing you do is going to alter the behavior specified by the RenderTargetUsage enum. The issues with the PreserveContents setting is that its very slow compared to the others. Too slow for the XBox or WP7 in many cases.

share|improve this answer
    
Thanks for clearings things up. –  Grofit Jan 21 '12 at 15:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.