mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementações em uso de vsync com swapchain
This commit is contained in:
parent
a60e0f366d
commit
022c6aad48
@ -168,13 +168,30 @@ namespace xna {
|
|||||||
|
|
||||||
initAndApplyState(*impl, _this);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GraphicsDevice::Present() {
|
bool GraphicsDevice::Present() const {
|
||||||
if (!impl) return false;
|
const auto currentPresenInterval = impl->_presentationParameters->PresentationInterval;
|
||||||
|
bool result = impl->_swapChain->Present(impl->vSyncValue != 0);
|
||||||
const auto result = impl->_swapChain->Present(impl->_usevsync);
|
|
||||||
impl->_context->OMSetRenderTargets(
|
impl->_context->OMSetRenderTargets(
|
||||||
1,
|
1,
|
||||||
impl->_renderTarget2D->render_impl->_renderTargetView.GetAddressOf(),
|
impl->_renderTarget2D->render_impl->_renderTargetView.GetAddressOf(),
|
||||||
@ -183,7 +200,7 @@ namespace xna {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsDevice::Clear(Color const& color) {
|
void GraphicsDevice::Clear(Color const& color) const {
|
||||||
if (!impl) return;
|
if (!impl) return;
|
||||||
|
|
||||||
const auto v4 = color.ToVector4();
|
const auto v4 = color.ToVector4();
|
||||||
@ -241,10 +258,10 @@ namespace xna {
|
|||||||
impl->_viewport = viewport;
|
impl->_viewport = viewport;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsDevice::UseVSync(bool use) {
|
void GraphicsDevice::UseVSync(bool value) {
|
||||||
if (!impl) return;
|
if (!impl) return;
|
||||||
|
|
||||||
impl->_usevsync = use;
|
impl->vSyncValue = static_cast<UINT>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,11 +79,13 @@ namespace xna {
|
|||||||
return !FAILED(hr);
|
return !FAILED(hr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SwapChain::Present(bool vsync) {
|
bool SwapChain::Present(bool vsync) const {
|
||||||
if (!impl || !impl->dxSwapChain)
|
if (!impl || !impl->dxSwapChain)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const auto hr = impl->dxSwapChain->Present(vsync, NULL);
|
const auto presentValue = static_cast<UINT>(vsync);
|
||||||
|
|
||||||
|
const auto hr = impl->dxSwapChain->Present(presentValue, NULL);
|
||||||
return !FAILED(hr);
|
return !FAILED(hr);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -223,10 +223,15 @@ namespace xna {
|
|||||||
Four,
|
Four,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Defines flags that describe the relationship between the adapter refresh rate and the rate at which Present operations are completed.
|
||||||
enum class PresentInterval {
|
enum class PresentInterval {
|
||||||
|
//Equivalent to setting One.
|
||||||
Default,
|
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,
|
One,
|
||||||
|
//The driver waits for the vertical retrace period. Present operations are not affected more frequently than every second screen refresh.
|
||||||
Two,
|
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
|
Immediate
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -43,11 +43,11 @@ namespace xna {
|
|||||||
return PresentationParameters();
|
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, Color const& color, float depth, Int stencil);
|
||||||
void Clear(ClearOptions options, Vector4 const& color, float depth, Int stencil);
|
void Clear(ClearOptions options, Vector4 const& color, float depth, Int stencil);
|
||||||
bool Initialize();
|
bool Initialize();
|
||||||
bool Present();
|
bool Present() const;
|
||||||
|
|
||||||
void Reset(sptr<PresentationParameters> const& presentationParameters, sptr<GraphicsAdapter> const& graphicsAdapter);
|
void Reset(sptr<PresentationParameters> const& presentationParameters, sptr<GraphicsAdapter> const& graphicsAdapter);
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ namespace xna {
|
|||||||
SwapChain(sptr<GraphicsDevice> const& device);
|
SwapChain(sptr<GraphicsDevice> const& device);
|
||||||
~SwapChain() override;
|
~SwapChain() override;
|
||||||
bool Initialize();
|
bool Initialize();
|
||||||
bool Present(bool vsync);
|
bool Present(bool vsync) const;
|
||||||
bool GetBackBuffer(Texture2D& texture2D);
|
bool GetBackBuffer(Texture2D& texture2D);
|
||||||
public:
|
public:
|
||||||
struct PlatformImplementation;
|
struct PlatformImplementation;
|
||||||
|
@ -873,7 +873,7 @@ namespace xna {
|
|||||||
private:
|
private:
|
||||||
friend class GraphicsDevice;
|
friend class GraphicsDevice;
|
||||||
float _backgroundColor[4] = { 0, 0, 0, 0 };
|
float _backgroundColor[4] = { 0, 0, 0, 0 };
|
||||||
bool _usevsync{ true };
|
UINT vSyncValue = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Game::PlatformImplementation {
|
struct Game::PlatformImplementation {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user