Example #1
0
 /// <summary>
 /// Updates the and render.
 /// </summary>
 public void UpdateAndRender()
 {
     if (CanRender())
     {
         IsBusy = true;
         var t0 = TimeSpan.FromSeconds((double)Stopwatch.GetTimestamp() / Stopwatch.Frequency);
         RenderStatistics.FPSStatistics.Push((t0 - lastRenderTime).TotalMilliseconds);
         RenderStatistics.Camera = viewport.CameraCore;
         lastRenderTime          = t0;
         UpdateRequested         = false;
         ++updateCounter;
         renderContext.AutoUpdateOctree      = RenderConfiguration.AutoUpdateOctree;
         renderContext.EnableBoundingFrustum = EnableRenderFrustum;
         if (RenderConfiguration.UpdatePerFrameData)
         {
             viewport.Update(t0);
             renderContext.TimeStamp           = t0;
             renderContext.Camera              = viewport.CameraCore;
             renderContext.WorldMatrix         = viewport.WorldMatrix;
             renderContext.OITWeightPower      = RenderConfiguration.OITWeightPower;
             renderContext.OITWeightDepthSlope = RenderConfiguration.OITWeightDepthSlope;
             renderContext.OITWeightMode       = RenderConfiguration.OITWeightMode;
         }
         PreRender();
         UpdateSceneGraphRequested = false;
         try
         {
             if (renderBuffer.BeginDraw())
             {
                 OnRender(t0);
                 renderBuffer.EndDraw();
             }
             if (RenderConfiguration.RenderD2D && D2DTarget.D2DTarget != null)
             {
                 OnRender2D(t0);
             }
             renderBuffer.Present();
         }
         catch (SharpDXException ex)
         {
             var desc = ResultDescriptor.Find(ex.ResultCode);
             if (desc == global::SharpDX.DXGI.ResultCode.DeviceRemoved || desc == global::SharpDX.DXGI.ResultCode.DeviceReset ||
                 desc == global::SharpDX.DXGI.ResultCode.DeviceHung || desc == global::SharpDX.Direct2D1.ResultCode.RecreateTarget ||
                 desc == global::SharpDX.DXGI.ResultCode.AccessLost)
             {
                 Log(LogLevel.Warning, $"Device Lost, code = {desc.Code}");
                 RenderBuffer_OnDeviceLost(RenderBuffer, EventArgs.Empty);
             }
             else
             {
                 Log(LogLevel.Error, ex);
                 EndD3D();
                 ExceptionOccurred?.Invoke(this, new RelayExceptionEventArgs(ex));
             }
         }
         catch (Exception ex)
         {
             Log(LogLevel.Error, ex);
             EndD3D();
             ExceptionOccurred?.Invoke(this, new RelayExceptionEventArgs(ex));
         }
         finally
         {
             PostRender();
             IsBusy = false;
         }
         lastRenderingDuration = TimeSpan.FromSeconds((double)Stopwatch.GetTimestamp() / Stopwatch.Frequency) - t0;
         RenderStatistics.LatencyStatistics.Push(lastRenderingDuration.TotalMilliseconds);
         OnRendered?.Invoke(this, EventArgs.Empty);
     }
 }