hr0nix

I've a func that do some work including rendering into rt. So, i need to save old rt at the beginning of my rendering, and then restore it at the end ( when smb call my func, he may have rendering to texture enabled, or just rendering to the backbuffer, and he don't wont to worry about restoring his rt after call of my func ). Is there any way to implement such a behaviour using XNA



Re: XNA Framework Render target save'n'restore

hr0nix

UP!



Re: XNA Framework Render target save'n'restore

Jon Watte

On the Xbox, there is only a single render target. "Render to texture" is done by rendering to this target, then using an ultra-fast memory copy into the texture area. Thus, if you really need to save the screen render target, you have to do something like:

1) copy current screen to texture
2) render your stuff
3) render texture back to screen, using full-screen quad

Remember that Z/Stencil matters as well as color, and may require additional work to save/restore.





Re: XNA Framework Render target save'n'restore

hr0nix

So the codepathes are different on PC and XBOX when rendering into texture



Re: XNA Framework Render target save'n'restore

hr0nix

And what if i want to save render target on PC.



Re: XNA Framework Render target save'n'restore

Eli Tayrien - MSFT

The codepaths are the same.





Re: XNA Framework Render target save'n'restore

Jon Watte

The PC version of XNA uses the same code path. Basically, you can't get access to the PC-specific multiple render target switching through the XNA API, in order to stay compatible.





Re: XNA Framework Render target save'n'restore

clayman

i've got a little confused. i search in the document, and i find:
"The GraphicsDevice can support multiple render targets. The number of render targets supported by a GraphicsDevice is contained in NumberSimultaneousRenderTargets."
in the remarks of SetRenderTarget().
so is this mean i can only use mrt on pc





Re: XNA Framework Render target save'n'restore

Jon Watte

MRT, as in multiple output channels, is different from multiple, switchable, render target buffers. Sorry about the language confusion.






Re: XNA Framework Render target save'n'restore

hr0nix

Probably you don't understand. I need to perform transparent rendering to texture in my library, and my user doesn't expect that currently active render targets will change after function call. He can render things into backbuffer, 2d or cubemap rt, so i need a way to get, save and then restore the render target currently set on device.

But it seems that i can't do that. I can use GetRenderTarget() to get a reference to a rt and then use reflection to determine it's type, but there is no way to get cubemap face for rendering if the active rt was cubemap. I really need it.





Re: XNA Framework Render target save'n'restore

hr0nix

UP!



Re: XNA Framework Render target save'n'restore

Malmer

Not sure it will help, but the common approach for working with RT's in XNA is like this:

1) Create a RenderTarget2D in a device supported format
2) While rendering call GraphicsDevice.SetRenderTarget( 0, renderTargetThatYouJustCreated )
3) When done rendering restore the old backbuffer by calling GraphicsDevice.SetRenderTarget( 0, null ).

Not sure how it will handle it if there was an other rendertarget set before calling #2. It might push it to a stack or it might simply replace it. Havn't tested.





Re: XNA Framework Render target save'n'restore

hr0nix

No stack - and that's my problem =) Plz MSFT help



Re: XNA Framework Render target save'n'restore

Jon Watte

You don't need a stack. If you want a stack, you can always implement that yourself using a list.

In the code sample, don't forget to call RealizeRenderTarget()! That's what actually makes sure that the render target contains the data that you rendered to it.






Re: XNA Framework Render target save'n'restore

hr0nix

OMG. Did you really understand me I can't implement my own render target stack, cause i can't find a way to get current render target face for cube render targets. In fact, all that i ask is "How to implement such a stack". I really need help of someone from microsoft.