1

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?

Jared
  • 129
  • 3
  • 13

1 Answers1

3

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.

Ani
  • 10,826
  • 3
  • 27
  • 46
  • So, set the render target to OutputRenderTarget, then render InputRenderTarget onto that via GPU rendering w/ quad or spritebatch? – Jared Apr 02 '12 at 22:31
  • ... is using spritebatch a possible way too – Jared Apr 02 '12 at 23:50
  • Correct. And sure, you can render the quad any way you wish. – Ani Apr 03 '12 at 15:23
  • Except, when I try to render OutputRenderTarget to Input via: – Jared Apr 03 '12 at 21:33
  • `setRenderTarget(input) spritebatch.draw(output) setRenderTarget(null)` it says I can't use the render target when it's set on the card. That's what I'm stuck at. – Jared Apr 03 '12 at 21:34
  • Which is why I asked this question, since I have a texture being set to a REFERENCE of the outputrendertarget, and need a clone of it. – Jared Apr 03 '12 at 21:41
  • Strange, that should work. Could you post the exact exception and some sample code? – Ani Apr 09 '12 at 17:36
  • I was initializing the rendertargets via `input = output = new RenderTarget2D(...)` which was causing the reference errors. – Jared Apr 10 '12 at 01:45