public static void Draw() { // We can fill vertex buffer only when in Draw LoadInDraw(); //RasterizerState.CullClockwise.Apply(); RasterizerState.CullNone.Apply(); DepthStencilState.None.Apply(); BlendState.Opaque.Apply(); m_backgroundProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MyRenderCamera.FieldOfView, MyRenderCamera.AspectRatio, MyRenderCamera.NEAR_PLANE_DISTANCE, 100000); if (MyRender.CurrentRenderSetup.BackgroundColor != null) { MyRender.GraphicsDevice.Clear(ClearFlags.Target, new SharpDX.ColorBGRA(MyRender.CurrentRenderSetup.BackgroundColor.Value.R, MyRender.CurrentRenderSetup.BackgroundColor.Value.G, MyRender.CurrentRenderSetup.BackgroundColor.Value.B, MyRender.CurrentRenderSetup.BackgroundColor.Value.A), 1, 0); } else if (m_textureCube != null) { MyEffectBackgroundCube effect = MyRender.GetEffect(MyEffects.BackgroundCube) as MyEffectBackgroundCube; effect.SetViewProjectionMatrix(MyRenderCamera.ViewMatrixAtZero * m_backgroundProjectionMatrix); effect.SetBackgroundTexture(m_textureCube); effect.SetBackgroundColor(BackgroundColor); MyRender.GraphicsDevice.VertexDeclaration = MyVertexFormatPositionTexture3.VertexDeclaration; MyRender.GraphicsDevice.SetStreamSource(0, m_boxVertexBuffer, 0, MyVertexFormatPositionTexture3.Stride); effect.Begin(); MyRender.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, BOX_TRIANGLES_COUNT); effect.End(); MyPerformanceCounter.PerCameraDrawWrite.TotalDrawCalls++; } else { MyRender.GraphicsDevice.Clear(ClearFlags.Target, new SharpDX.ColorBGRA(BackgroundColor.X, BackgroundColor.Y, BackgroundColor.Z, 1), 1, 0); } }
public override void LoadContent() { MyRender.Log.WriteLine("MyBackgroundCube.LoadContent() - START"); MyRender.Log.IncreaseIndent(); MyRender.GetRenderProfiler().StartProfilingBlock("MyBackgroundCube"); Static = this; UpdateTexture(); m_loaded = false; // Projection matrix according to zoom level m_backgroundProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(1.0f, MyRenderCamera.AspectRatio, 50, 100000); MyRender.GetRenderProfiler().EndProfilingBlock(); MyRender.Log.DecreaseIndent(); MyRender.Log.WriteLine("MyBackgroundCube.LoadContent() - END"); }