public FrameDebuggerSelectionProcessor() { drawOptions = DebugDrawOptions.Create(); }
private void Render() { // If the form is not visible do not render anything. if (this.Visible == false) { return; } // Update the time from the previous frame to the current frame. this.renderTime.LastTickCount = this.renderTime.CurrentTickCount; this.renderTime.CurrentTickCount = DateTime.Now.Ticks; this.renderTime.TimeDelta = (float)(this.renderTime.CurrentTickCount - this.renderTime.LastTickCount) / (float)TimeSpan.TicksPerSecond; // Check if we need to reset the fps counter. if (this.renderTime.CurrentTickCount >= this.startTime + TimeSpan.TicksPerSecond) { // Update the fps counter. this.Text = string.Format("RenderView: {0} fps", this.framesPerSecond); // Reset the fps counter. this.framesPerSecond = 0; this.startTime = this.renderTime.CurrentTickCount; } // Increment the frame counter. this.framesPerSecond++; // Check if the form has resized and if so reset our render state to accomidate the size change. if (this.hasResized == true) { ResizeRenderTarget(); } // Cap input polling to 30 times per second. if ((this.renderTime.CurrentTickCount - this.lastInputPollTime) > (TimeSpan.TicksPerSecond / 30)) { // Only move the camera if the window is visible. if (this.Visible == true && this.Focused == true) { // Update input. this.lastInputPollTime = DateTime.Now.Ticks; this.inputManager.DrawFrame(this, this.device); // Check if we need to update debug draw options. if (this.inputManager.ButtonPressed(InputAction.MiscAction1) == true) { // Toggle joint bounding spheres. if (this.debugDrawOptions.HasFlag(DebugDrawOptions.DrawJointBoundingSpheres) == true) { this.debugDrawOptions &= ~DebugDrawOptions.DrawJointBoundingSpheres; } else { this.debugDrawOptions |= DebugDrawOptions.DrawJointBoundingSpheres; } } if (this.inputManager.ButtonPressed(InputAction.MiscAction2) == true) { // Toggle primitive bounding boxes. if (this.debugDrawOptions.HasFlag(DebugDrawOptions.DrawPrimitiveBoundingBox) == true) { this.debugDrawOptions &= ~DebugDrawOptions.DrawPrimitiveBoundingBox; } else { this.debugDrawOptions |= DebugDrawOptions.DrawPrimitiveBoundingBox; } } // Update the camera. this.camera.DrawFrame(this, this.device); } } // Set our render target to our swapchain buffer. this.device.ImmediateContext.OutputMerger.SetRenderTargets(this.depthStencilView, this.renderView); // Clear the backbuffer. this.device.ImmediateContext.ClearRenderTargetView(this.renderView, SharpDX.Color.CornflowerBlue); this.device.ImmediateContext.ClearDepthStencilView(this.depthStencilView, DepthStencilClearFlags.Depth | DepthStencilClearFlags.Stencil, 1.0f, 0); // Set depth stencil and rasterizer states. this.device.ImmediateContext.OutputMerger.SetDepthStencilState(this.depthStencilState, 0); this.device.ImmediateContext.Rasterizer.State = this.rasterState; // Set the viewport. this.device.ImmediateContext.Rasterizer.SetViewport(0, 0, this.ClientSize.Width, this.ClientSize.Height, 0.0f, 1.0f); // Set output target. this.device.ImmediateContext.OutputMerger.SetRenderTargets(this.depthStencilView, this.renderView); // The pixel shader constants do not change between primtive draw calls, update them now. this.shaderConsts.gXfViewProj = Matrix.Transpose(this.worldGround * this.camera.ViewMatrix * this.projectionMatrix); // Loop through all of the resources to render and draw each one. for (int i = 0; i < this.resourcesToRender.Length; i++) { // HACK: We can only render rModels for now. rModel model = (rModel)this.resourcesToRender[i]; // Set the bounding box parameters for this model. this.shaderConsts.gXfQuantPosScale = model.header.BoundingBoxMax - model.header.BoundingBoxMin; this.shaderConsts.gXfQuantPosOffset = model.header.BoundingBoxMin; // Update the shader constants buffer with the new data. this.device.ImmediateContext.UpdateSubresource(ref this.shaderConsts, this.shaderConstantBuffer); // Set the shader constants. this.device.ImmediateContext.VertexShader.SetConstantBuffer(0, this.shaderConstantBuffer); this.device.ImmediateContext.PixelShader.SetConstantBuffer(0, this.shaderConstantBuffer); // Draw the model. this.resourcesToRender[i].DrawFrame(this, this.device); } // Present the final frame. this.swapChain.Present(0, PresentFlags.None); }