Change one render target without clearing the other

I have a case like this:

GraphicsDevice.SetRenderTargets(RenderTargetA, RenderTargetB);

... draw first texture to both targets 

GraphicsDevice.SetRenderTargets(RenderTargetA, RenderTargetC);

... draw second texture to both targets 

The problem is that when SetRenderTargets is called for the second time, RenderTargetA is cleared.

In the end I want RenderTargetA to have both textures on it, while RenderTargetB should only have the first and RenderTargetC should only have the second. I know this can be done with RenderTargetUsage.PreserveContents, but according to this, perserving the contents comes with some performance and combatibility tradeoffs.

Is there some method on GraphicsDevice or some other way I can use to just set the second render target without effecting the first?


No, GPUs may not guarantee that any content is preserved so we have to assume to none are, for consistency.

So if you want to do this, you will have to use PreserveContents, which indeed may be a performance/memory hit because some GPUs have to copy it to preserve it (sometime to the CPU, which is a bigger hit).

Let’s be realistic, no desktop GPU, even 12+ years old will in any way care about perserveContent performance wise, at all. So unless he target some mobile HW, he has nothing to worry about and can use it freely.

You’re right, thought I would just make sure I wasn’t missing something obvious :sweat_smile: