XNA Creators Club Online
Page 1 of 1 (2 items)
Sort Posts: Previous Next

Alternative to CreateOffscreenPlainSurface to read out from a RenderTarget surface/texture?

Last post 6/27/2009 6:31 AM by Ralf Kornmann. 1 replies.
  • 6/23/2009 2:57 AM

    Alternative to CreateOffscreenPlainSurface to read out from a RenderTarget surface/texture?


    I'm writing an app in XNA/C# where I need to process Data with the GPU.

    I put my data into a R32F texture since the data is a float[].
    I then create a Surface with a Usage.RenderTarget, and a RenderToSurface.
    I render a Sprite of the Texture, and I have a shader that processes each pixel.

    All work well so far...
    I then need to read the data back to CPU:
    I cannot use LockRectangle on the RenderSurface, because it has to be in Pool.Default and this is not allowed, so the only way I found was to use CreateOffscreenPlainSurface to create a new Surface that is in SystemMemory, copy the RenderSurface into that Surface using GetRenderTargetData, and LockRectangle on the PlainSurface then read the stream from LockRectangle.

    All goes well on my nVidia 8600GT, but when I run it on my Laptop (Intel GMA x3100), there is no R32F format for OffscreenPlainSurface.

    So, I'm wondering if there is another way to read the data back from a RenderToSurface directly, without the extra copy.
    The only other way I see right now is to convert the data to A8R8G8B8, rebuild it in the shader, then render in A8R8G8B8 and read that out...
    but that seems like a very unefficient way to work with floats!


    Any other suggestion would be very welcome!

    Regards

  • 6/27/2009 6:31 AM In reply to

    Re: Alternative to CreateOffscreenPlainSurface to read out from a RenderTarget surface/texture?

    Instead of creating a surface with the render target usage you can create a render target directly. The CreateRenderTarget function supports an additional parameter that allows you to make your target lookable. But using this feature can have a performaces impact too as the driver may be forced to store the target in a less optimal memory location.
Page 1 of 1 (2 items) Previous Next