1
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .