/// <summary> /// Renders the entire scene. /// </summary> /// <param name="doWaitForNextFame"><c>true</c>, if this method should wait to the correct frame start time /// before it renders, else <c>false</c>.</param> /// <returns><c>true</c>, if the caller should wait some milliseconds before rendering the next time.</returns> public static bool Render(bool doWaitForNextFame) { if (_device == null || !_deviceOk) { return(true); } IRenderStrategy renderStrategy = RenderStrategy; IRenderPipeline pipeline = RenderPipeline; renderStrategy.BeginRender(doWaitForNextFame); _renderAndResourceAccessLock.EnterReadLock(); bool doReset = false; try { Fire(DeviceSceneBegin); pipeline.BeginRender(); pipeline.Render(); pipeline.EndRender(); Fire(DeviceSceneEnd); _device.PresentEx(renderStrategy.PresentMode); Fire(DeviceScenePresented); ContentManager.Instance.Clean(); } catch (SharpDXException e) { doReset = true; DeviceState state = CheckDeviceState(); ServiceRegistration.Get <ILogger>().Warn("GraphicsDevice: DirectX Exception, DeviceState: {0}", e, state); _deviceOk = state == DeviceState.Ok; return(!_deviceOk); } finally { _renderAndResourceAccessLock.ExitReadLock(); // If there are exceptions during render pass, the device can stay in an invalid state, even if the CheckDeviceState returns "ok". // So we prefer to reset the device and try continue rendering. if (doReset) { Reset(); } } return(false); }
/// <summary> /// Renders the entire scene. /// </summary> /// <param name="doWaitForNextFame"><c>true</c>, if this method should wait to the correct frame start time /// before it renders, else <c>false</c>.</param> /// <returns><c>true</c>, if the caller should wait some milliseconds before rendering the next time.</returns> public static bool Render(bool doWaitForNextFame) { if (_device == null || !_deviceOk) { return(true); } IRenderStrategy renderStrategy = RenderStrategy; IRenderPipeline pipeline = RenderPipeline; renderStrategy.BeginRender(doWaitForNextFame); _renderAndResourceAccessLock.EnterReadLock(); try { Fire(DeviceSceneBegin); pipeline.BeginRender(); pipeline.Render(); pipeline.EndRender(); Fire(DeviceSceneEnd); _device.PresentEx(renderStrategy.PresentMode); Fire(DeviceScenePresented); ContentManager.Instance.Clean(); } catch (SharpDXException e) { DeviceState state = CheckDeviceState(); ServiceRegistration.Get <ILogger>().Warn("GraphicsDevice: DirectX Exception, DeviceState: {0}", e, state); _deviceOk = state == DeviceState.Ok; return(!_deviceOk); } finally { _renderAndResourceAccessLock.ExitReadLock(); } return(false); }