// Used in the overlay unsafe int PresentExHook(IntPtr devicePtr, SharpDX.Rectangle *pSourceRect, SharpDX.Rectangle *pDestRect, IntPtr hDestWindowOverride, IntPtr pDirtyRegion, Present dwFlags) { _isUsingPresent = true; DeviceEx device = (DeviceEx)devicePtr; DoCaptureRenderTarget(device, "PresentEx"); // Region region = new Region(pDirtyRegion); if (pSourceRect == null || *pSourceRect == SharpDX.Rectangle.Empty) { device.PresentEx(dwFlags); } else { if (hDestWindowOverride != IntPtr.Zero) { device.PresentEx(dwFlags, *pSourceRect, *pDestRect, hDestWindowOverride); } else { device.PresentEx(dwFlags, *pSourceRect, *pDestRect); } } return(SharpDX.Result.Ok.Code); }
/// <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); } #if (MAX_FRAMERATE == false) if (doWaitForNextFame) { WaitForNextFrame(); } #endif _frameRenderingStartTime = DateTime.Now; _renderAndResourceAccessLock.EnterReadLock(); try { _device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0); _device.BeginScene(); _screenManager.Render(); _device.EndScene(); _device.PresentEx(_setup.Present); _fpsCounter += 1; TimeSpan ts = DateTime.Now - _fpsTimer; if (ts.TotalSeconds >= 1.0f) { float secs = (float)ts.TotalSeconds; SkinContext.FPS = _fpsCounter / secs; #if PROFILE_FRAMERATE ServiceRegistration.Get <ILogger>().Debug("RenderLoop: {0} frames per second, {1} total frames until last measurement", SkinContext.FPS, _fpsCounter); #endif _fpsCounter = 0; _fpsTimer = DateTime.Now; } ContentManager.Instance.Clean(); } catch (Direct3D9Exception 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); }
/// <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); }
/// <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); } RenderStrategy.BeginRender(doWaitForNextFame); _renderAndResourceAccessLock.EnterReadLock(); try { _device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0); _device.BeginScene(); Fire(DeviceSceneBegin); _screenManager.Render(); Fire(DeviceSceneEnd); _device.EndScene(); _device.PresentEx(RenderStrategy.PresentMode); Fire(DeviceScenePresented); ContentManager.Instance.Clean(); } catch (Direct3D9Exception 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); }