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);
|
||||
|
||||
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<UINT>(value);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<UINT>(vsync);
|
||||
|
||||
const auto hr = impl->dxSwapChain->Present(presentValue, NULL);
|
||||
return !FAILED(hr);
|
||||
}
|
||||
}
|
@ -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
|
||||
};
|
||||
|
||||
|
@ -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<PresentationParameters> const& presentationParameters, sptr<GraphicsAdapter> const& graphicsAdapter);
|
||||
|
||||
|
@ -11,7 +11,7 @@ namespace xna {
|
||||
SwapChain(sptr<GraphicsDevice> const& device);
|
||||
~SwapChain() override;
|
||||
bool Initialize();
|
||||
bool Present(bool vsync);
|
||||
bool Present(bool vsync) const;
|
||||
bool GetBackBuffer(Texture2D& texture2D);
|
||||
public:
|
||||
struct PlatformImplementation;
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user