【发布时间】:2015-01-18 23:44:56
【问题描述】:
我目前面临以下奇怪的问题: 下面的代码 sn-p 按预期完美呈现:
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);
}
但是,如果我在函数末尾分配(并立即取消分配)渲染目标,如下所示:
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);
}
什么都没有被渲染 - 我有一个紫色的屏幕! 这对你有意义吗!
附: 我知道该示例没有多大意义(例如分配和立即取消分配渲染目标)。这里的实际情况要复杂得多,但我能够将问题的本质缩小到这种奇怪的行为,我可以在这个非常简单的示例中进行演示!
【问题讨论】: