Сейчас я обращенную следующую странную проблему: Следующий фрагмент кода делает отлично, как и ожидалось:XNA 4.0 - странное поведение при назначении цели визуализации
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);
}
ничего не отображается - я получил фиолетовый экран! Это имеет какой-то смысл для вас!
P.S. Я знаю, что образец не имеет большого смысла (например, присваивание и прямое присвоение цели рендеринга). Реальный сценарий здесь намного сложнее, но я смог сузить суть проблемы до этого странного поведения, которое я могу продемонстрировать на этом очень простом примере!