Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (7 posts)

Rendertarget Lost after resize

Last post 6/16/2008 2:55 PM by Shawn Hargreaves. 6 replies.
  • 6/15/2008 3:34 PM

    Rendertarget Lost after resize

    Hi.

    I have a winform level editor.  I can minimize and move the window with no problem.  However, when I resize the window, my rendertarget's contents are lost (isContentLost=true) and the rendertarget's.gettexture() has all kinds of crazy colors.  The rendertarget needs to be persistent, because I am using it to 'paint' the surface of the terrain.

    Any ideas on how to prevent this?

     

    1 rtDetailLayer = new RenderTarget2D(Global.Device, _DrawLayerWidth, _DrawLayerHeight, 1, SurfaceFormat.Color, RenderTargetUsage.PreserveContents);  
    2  
    3 Global.Device.SetRenderTarget(0, rtDetailLayer);  
    4 Global.Device.Clear(Color.Black);  
    5  

     

    Thank you,

    Fader

  • 6/16/2008 4:58 AM In reply to

    Re: Rendertarget Lost after resize

    Rendertargets should be recreaed after a resize, or they get messed up. Just create the render target again in the resize event.
  • 6/16/2008 6:29 AM In reply to

    Re: Rendertarget Lost after resize

    If the RenderTarget stores some data that cannot be recreated directly, how do we save the data and recreate it again?
  • 6/16/2008 6:29 AM In reply to

    Re: Rendertarget Lost after resize

    I believe you can have a render target preserve its contents by specifying "RenderTargetUsage.PreserveContents" in the constructor when you create the render target as discussed here:

    http://msdn.microsoft.com/en-us/library/bb975911.aspx

     

  • 6/16/2008 7:57 AM In reply to

    Re: Rendertarget Lost after resize

    if you catch the resize event, you should be able to extract the rendertarget data before creating the new rendertarget. But I'm not sure on that.
  • 6/16/2008 8:26 AM In reply to

    Re: Rendertarget Lost after resize

    Take the rendertarget as a Texture2D, recreate a new spritebatch, and then draw a fulll screen quad (resized as necessary) onto the new rendertarget using the texture form the old.
  • 6/16/2008 2:55 PM In reply to

    Re: Rendertarget Lost after resize

    That won't work: if the graphics device is reset (which can happen for many reasons: resizing is one, or running a different fullscreen app, or locking your desktop) the contents of all dynamic resources (which include rendertargets) are lost. There is no way to recover this data, because it doesn't exist on the GPU any more. And there is no way to copy it out of the rendertarget just before the resize occurs, because there are many reasons why the data might be lost (eg. running a different app in fullscreen) where you don't get the content lost notification until after the data is already gone.

    Unfortunately, there is no way to store persistent data in a GPU rendertarget like this. By all means use the rendertarget as a cache, but you need to store enough information on the CPU side that you will be able to regenerate the GPU data from scratch if it gets lost.

    See here for more details about dynamic GPU resources and what does/doesn't get persisted.

     


Page 1 of 1 (7 posts) Previous Discussion Next Discussion