Having the exactly same issue here - the following code snipped works perfectly fine:
private void DoRenderSkybox (GameTime Time) {
this.Device.SetRenderTarget(this.GridTexture);
this.Device.SetRenderTarget(null);
// compute a temporary transformation matrix containing
// the combined world and projection transfromation
Matrix WorldViewProjection = this.Camera.View * this.Camera.Projection;
// set the render target to the back buffer in any case
this.Device.SetRenderTarget(null);
// assign the vertex - declaration and the vertex- and the index - buffer
this.Device.SetVertexBuffer(this.SkyboxVertices);
this.Device.Indices = this.SkyboxIndices;
// choose the appropriate technique for the current render pass
this.SceneEffect.CurrentTechnique = SceneEffect.Techniques["Skybox"];
this.SceneEffect.CurrentTechnique.Passes[0].Apply();
this.SceneEffect.Parameters["WorldViewProjection"].SetValue(WorldViewProjection);
// finally render the sykbox with disabled depth stencil buffering
this.Device.DepthStencilState = DepthStencilState.None;
this.Device.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, 36, 0, 12);
this.Device.DepthStencilState = DepthStencilState.Default;
//this.Device.SetRenderTarget(this.GridTexture);
//this.Device.SetRenderTarget(null);
}
However, if I assign (and right away unassign) the render target at the end of the function like so:
private void DoRenderSkybox (GameTime Time) {
//this.Device.SetRenderTarget(this.GridTexture);
//this.Device.SetRenderTarget(null);
// compute a temporary transformation matrix containing
// the combined world and projection transfromation
Matrix WorldViewProjection = this.Camera.View * this.Camera.Projection;
// set the render target to the back buffer in any case
this.Device.SetRenderTarget(null);
this.Device.Clear(Color.Black);
// assign the vertex - declaration and the vertex- and the index - buffer
this.Device.SetVertexBuffer(this.SkyboxVertices);
this.Device.Indices = this.SkyboxIndices;
// choose the appropriate technique for the current render pass
this.SceneEffect.CurrentTechnique = SceneEffect.Techniques["Skybox"];
this.SceneEffect.CurrentTechnique.Passes[0].Apply();
this.SceneEffect.Parameters["WorldViewProjection"].SetValue(WorldViewProjection);
// finally render the sykbox with disabled depth stencil buffering
this.Device.DepthStencilState = DepthStencilState.None;
this.Device.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, 36, 0, 12);
this.Device.DepthStencilState = DepthStencilState.Default;
this.Device.SetRenderTarget(this.GridTexture);
this.Device.SetRenderTarget(null);
}
nothing is being rendered - I got a purple screen! Does that make any sense to you!
P.S. I know the sample doesn't make much sense (like assigning and right away unassigning a render target). The real scenario here is much more complicated but I was able to narrow down the essence of the problem to this strange behaviour, which I can demonstrate in this very simple example!
EDIT:
Just found the solution by further examining the API:
Adding Params.RenderTargetUsage = RenderTargetUsage.PreserveContents;
into the PresentationParameter structure solves the problem.
It looks to me that the content of the backbuffer is - like with render targets being destroyed whenever you switch to another render target.