/// <summary> /// Event Handler to handle a request by a surface to rendered by the device /// </summary> /// <param name="sender">The object that made the request</param> /// <param name="e">The arguments for the event</param> public void OnRenderSingleView(Object sender, RenderSingleViewEventArgs e) { // if the device has been lost, check it's state if( base.Device != null && this.isDeviceLost) { try { // test co-operation level to make sure it is ok to render base.Device.TestCooperativeLevel(); } catch (DeviceLostException) { // don't do anything if the device has been lost return; } catch (DeviceNotResetException) { base.RefreshPresentParameters(); // device can be resest so do so base.Device.Reset(base.PresentParameters); } // ok to move on this.isDeviceLost = false; } IRenderSurface renderSurface = (IRenderSurface)sender; // render to the surface if( base.Device != null) { this.SetupLights(); // set the render target base.Device.SetRenderTarget(0,renderSurface.RenderTarget); // set the depth stencil base.Device.DepthStencilSurface = renderSurface.DepthStencil; // set the camera base.Device.Transform.View = renderSurface.Camera.ViewMatrix; base.Device.Transform.Projection = renderSurface.Camera.ProjectionMatrix; // clear the backBuffer base.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, renderSurface.BackColor, 1.0f, 0); // setup the render quality for the viewport SetupDrawMode(renderSurface.DrawMode); // begin the scene base.Device.BeginScene(); // render the scene e.Scene.Render(base.Device,renderSurface.Camera.WorldMatrix, e.FrameNumber); // render viewport descriptive text if(renderSurface.NameVisible) { if (drawingFont == null) { drawingFont = new GraphicsFont(arialFont); drawingFont.InitializeDeviceObjects(base.Device); } // draw GraphicsFont in 2D drawingFont.DrawText(4, 4, Color.Black, renderSurface.Camera.Name); drawingFont.DrawText(6, 6, Color.White, renderSurface.Camera.Name); } base.Device.EndScene(); // if the their is a window to render too do so if( renderSurface.SwapChain != null) { renderSurface.SwapChain.Present(); } } }
/// <summary> /// Event Handler to handle a request by a surface to rendered by the device /// </summary> /// <param name="sender">The object that made the request</param> /// <param name="e">The arguments for the event</param> public void OnRenderSingleView(Object sender, RenderSingleViewEventArgs e) { // if the device has been lost, check it's state if (base.Device != null && this.isDeviceLost) { try { // test co-operation level to make sure it is ok to render base.Device.TestCooperativeLevel(); } catch (DeviceLostException) { // don't do anything if the device has been lost return; } catch (DeviceNotResetException) { base.RefreshPresentParameters(); // device can be resest so do so base.Device.Reset(base.PresentParameters); } // ok to move on this.isDeviceLost = false; } IRenderSurface renderSurface = (IRenderSurface)sender; // render to the surface if (base.Device != null) { this.SetupLights(); // set the render target base.Device.SetRenderTarget(0, renderSurface.RenderTarget); // set the depth stencil base.Device.DepthStencilSurface = renderSurface.DepthStencil; // set the camera base.Device.Transform.View = renderSurface.Camera.ViewMatrix; base.Device.Transform.Projection = renderSurface.Camera.ProjectionMatrix; // clear the backBuffer base.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, renderSurface.BackColor, 1.0f, 0); // setup the render quality for the viewport SetupDrawMode(renderSurface.DrawMode); // begin the scene base.Device.BeginScene(); // render the scene e.Scene.Render(base.Device, renderSurface.Camera.WorldMatrix, e.FrameNumber); // render viewport descriptive text if (renderSurface.NameVisible) { if (drawingFont == null) { drawingFont = new GraphicsFont(arialFont); drawingFont.InitializeDeviceObjects(base.Device); } // draw GraphicsFont in 2D drawingFont.DrawText(4, 4, Color.Black, renderSurface.Camera.Name); drawingFont.DrawText(6, 6, Color.White, renderSurface.Camera.Name); } base.Device.EndScene(); // if the their is a window to render too do so if (renderSurface.SwapChain != null) { renderSurface.SwapChain.Present(); } } }