diff --git a/framework/platform-dx/device.cpp b/framework/platform-dx/device.cpp index 5cbc57a..1f625b8 100644 --- a/framework/platform-dx/device.cpp +++ b/framework/platform-dx/device.cpp @@ -168,13 +168,30 @@ namespace xna { initAndApplyState(*impl, _this); + const auto currentPresenInterval = impl->_presentationParameters->PresentationInterval; + + switch (currentPresenInterval) + { + case PresentInterval::Default: + case PresentInterval::One: + case PresentInterval::Two: + impl->vSyncValue = 1; + break; + case PresentInterval::Immediate: + impl->vSyncValue = 0; + break; + default: + impl->vSyncValue = 1; + break; + } + return true; } - bool GraphicsDevice::Present() { - if (!impl) return false; - - const auto result = impl->_swapChain->Present(impl->_usevsync); + bool GraphicsDevice::Present() const { + const auto currentPresenInterval = impl->_presentationParameters->PresentationInterval; + bool result = impl->_swapChain->Present(impl->vSyncValue != 0); + impl->_context->OMSetRenderTargets( 1, impl->_renderTarget2D->render_impl->_renderTargetView.GetAddressOf(), @@ -183,7 +200,7 @@ namespace xna { return result; } - void GraphicsDevice::Clear(Color const& color) { + void GraphicsDevice::Clear(Color const& color) const { if (!impl) return; const auto v4 = color.ToVector4(); @@ -241,10 +258,10 @@ namespace xna { impl->_viewport = viewport; } - void GraphicsDevice::UseVSync(bool use) { + void GraphicsDevice::UseVSync(bool value) { if (!impl) return; - impl->_usevsync = use; + impl->vSyncValue = static_cast(value); } diff --git a/framework/platform-dx/swapchain.cpp b/framework/platform-dx/swapchain.cpp index 6ac7818..dc76cd9 100644 --- a/framework/platform-dx/swapchain.cpp +++ b/framework/platform-dx/swapchain.cpp @@ -79,11 +79,13 @@ namespace xna { return !FAILED(hr); } - bool SwapChain::Present(bool vsync) { + bool SwapChain::Present(bool vsync) const { if (!impl || !impl->dxSwapChain) return false; - const auto hr = impl->dxSwapChain->Present(vsync, NULL); + const auto presentValue = static_cast(vsync); + + const auto hr = impl->dxSwapChain->Present(presentValue, NULL); return !FAILED(hr); } } \ No newline at end of file diff --git a/inc/xna/enumerations.hpp b/inc/xna/enumerations.hpp index dd0657f..1821daa 100644 --- a/inc/xna/enumerations.hpp +++ b/inc/xna/enumerations.hpp @@ -223,10 +223,15 @@ namespace xna { Four, }; + //Defines flags that describe the relationship between the adapter refresh rate and the rate at which Present operations are completed. enum class PresentInterval { + //Equivalent to setting One. Default, + //The driver waits for the vertical retrace period (the runtime will beam trace to prevent tearing). Present operations are not affected more frequently than the screen refresh rate; the runtime completes one Present operation per adapter refresh period, at most. This option is always available for both windowed and full-screen swap chains. One, + //The driver waits for the vertical retrace period. Present operations are not affected more frequently than every second screen refresh. Two, + //The runtime updates the window client area immediately, and might do so more than once during the adapter refresh period. Present operations might be affected immediately. This option is always available for both windowed and full-screen swap chains. Immediate }; diff --git a/inc/xna/graphics/device.hpp b/inc/xna/graphics/device.hpp index 6ce3e31..46c6a31 100644 --- a/inc/xna/graphics/device.hpp +++ b/inc/xna/graphics/device.hpp @@ -43,11 +43,11 @@ namespace xna { return PresentationParameters(); } - void Clear(Color const& color); + void Clear(Color const& color) const; void Clear(ClearOptions options, Color const& color, float depth, Int stencil); void Clear(ClearOptions options, Vector4 const& color, float depth, Int stencil); bool Initialize(); - bool Present(); + bool Present() const; void Reset(sptr const& presentationParameters, sptr const& graphicsAdapter); diff --git a/inc/xna/graphics/swapchain.hpp b/inc/xna/graphics/swapchain.hpp index 2674027..b4e489a 100644 --- a/inc/xna/graphics/swapchain.hpp +++ b/inc/xna/graphics/swapchain.hpp @@ -11,7 +11,7 @@ namespace xna { SwapChain(sptr const& device); ~SwapChain() override; bool Initialize(); - bool Present(bool vsync); + bool Present(bool vsync) const; bool GetBackBuffer(Texture2D& texture2D); public: struct PlatformImplementation; diff --git a/inc/xna/xna-dx.hpp b/inc/xna/xna-dx.hpp index e5c19c7..15d64af 100644 --- a/inc/xna/xna-dx.hpp +++ b/inc/xna/xna-dx.hpp @@ -873,7 +873,7 @@ namespace xna { private: friend class GraphicsDevice; float _backgroundColor[4] = { 0, 0, 0, 0 }; - bool _usevsync{ true }; + UINT vSyncValue = 1; }; struct Game::PlatformImplementation {