Search code examples
c#xnatexturestexture2drendertarget

C#/XNA - RenderTarget2D.GetData(), RenderTarget2D.SetData(): is it efficient for cloning textures per frame?


So, since the last question, I found that my solution is to duplicate the texture to prevent reference issues. However, I'm questioning:

    Color[] color = new Color[screen.Width * screen.Height];
    InputRenderTarget2D.GetData(Color);
    OutputRenderTarget2D.SetData(color);

For one, is this efficient when ran 60 times per second? Although it's setting 1 texture, I'm performance-paranoid and WANT to keep performance at its decent or best. Will it cause "majorly-noticable framedrops" and the like?

Second, will it boost performance that instead of creating a new Color array, I recycle one?


Solution

  • I believe this will harm performance because the GetData()/SetData() calls will transfer the rendertarget data to main memory. IMO, the better alternative would be to render InputRenderTarget2D to OutputRenderTarget2D using a quad of the same size. This will prevent CPU-GPU data transfer.