Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Let's say I set two render targets

GraphicsDevice.SetRenderTargets(rt0, rt1);

If I call

GraphicsDevice.Clear(Color.Transparent);

both render targets will be cleared.

Therefore, how can I clear a render target at a specific index? For example just 'rt1' and not 'rt0'.

I would like to avoid texture baking the contents of 'rt0' to another render target and copying them back to 'rt0'. This is because PreserveContents on the XBOX 360 can only hold one render target in memory.

EDIT:

Is there any way just clear the color for a render target? I would like to keep the depth for depth reading.

share|improve this question
    
Sorry i misread your question –  Kikaimaru Jul 22 '12 at 15:12

1 Answer 1

up vote 1 down vote accepted

To clear a specific render target you can either call SetRenderTarget() with only the one you want to clear, or use a pixel shader that outputs an opaque colour to one target and transparent to the other.

To avoid clearing depth use GraphicsDevice.Clear(ClearOptions.Target, Color.Transparent, 0.0f, 0);

share|improve this answer
    
I see so colour *= 1 for the target to keep its contents and *= 0 to lose the contents. How does the avoid clearing depth work what does the 0.0f parameter do? –  user1423893 Jul 22 '12 at 17:43
    
The MSDN documentation for GraphicsDevice.Clear() explains what the extra parameters do. In this case they do nothing since you're only clearing the colour buffer. msdn.microsoft.com/en-us/library/… –  Adam Jul 22 '12 at 21:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.