Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions DeviceResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ DX::DeviceResources::DeviceResources(DXGI_FORMAT backBufferFormat,
, m_dpi(-1.0f)
, // Require DPI to be explicitly set.
m_vTotalMode(false)
, m_tearingSupport(false)
{
UNREFERENCED_PARAMETER(minFeatureLevel);

Expand Down Expand Up @@ -233,9 +234,7 @@ void DX::DeviceResources::CreateWindowSizeDependentResources()
}
else
{
swapFlags = 0; // default is vsync on, not tearing
// swapFlags = DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING; // It is recommended to always use the tearing flag when it is available.
// swapChainDesc.Flags = m_tearingSupport ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0; TODO make this not hard-coded -then older systems may work
swapFlags = m_tearingSupport ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0;
}
// If the swap chain already exists, resize it.
HRESULT hr = m_swapChain->ResizeBuffers(m_backBufferCount, backBufferWidth, backBufferHeight, m_backBufferFormat, swapFlags);
Expand Down Expand Up @@ -294,9 +293,7 @@ void DX::DeviceResources::CreateWindowSizeDependentResources()
}
else
{
swapFlags = 0; // default is vsync enabled, not tearing
// swapFlags = DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING; // It is recommended to always use the tearing flag when it is available.
// swapChainDesc.Flags = m_tearingSupport ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0; TODO make this not hard-coded -then older systems may work
swapFlags = m_tearingSupport ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0;
}
swapChainDesc.Flags = swapFlags;

Expand Down Expand Up @@ -465,8 +462,13 @@ HRESULT DX::DeviceResources::Present(UINT syncInterval, UINT flags)
// flag when it is supported, even when presenting in windowed mode.
// However, this flag cannot be used if the app is in fullscreen mode as a
// result of calling SetFullscreenState.
// UINT presentFlags = (m_tearingSupport && m_windowedMode) ? DXGI_PRESENT_ALLOW_TEARING : 0;
HRESULT hr = m_swapChain->Present(syncInterval, flags);
UINT presentFlags = flags;
if (m_tearingSupport && syncInterval == 0)
{
presentFlags |= DXGI_PRESENT_ALLOW_TEARING;
}

HRESULT hr = m_swapChain->Present(syncInterval, presentFlags);

if (m_d3dContext)
{
Expand Down
5 changes: 5 additions & 0 deletions DeviceResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ namespace DX
{
m_vTotalMode = vTotalMode;
} // Tell DevResources object when we are requesting v-total Fixed.
void SetTearingSupport(bool tearingSupport)
{
m_tearingSupport = tearingSupport;
}

// The size of the render target, in pixels.
RECT GetOutputSize() const
Expand Down Expand Up @@ -185,6 +189,7 @@ namespace DX
Microsoft::WRL::ComPtr<ID3DUserDefinedAnnotation> m_d3dAnnotation;
HANDLE m_frameLatencyHandle;
BOOL m_vTotalMode; // True for a FIXED v-total average swapchain
bool m_tearingSupport;

// Direct3D rendering objects. Required for 3D.
Microsoft::WRL::ComPtr<ID3D11Texture2D> m_renderTarget;
Expand Down
3 changes: 3 additions & 0 deletions Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ void Game::RotateFrameLog()
// Initialize the Direct3D resources required to run.
void Game::Initialize(HWND window, int width, int height)
{
CheckTearingSupport();
m_deviceResources->SetTearingSupport(m_tearingSupport);

m_deviceResources->SetWindow(window, width, height);
m_deviceResources->CreateDeviceResources();
m_deviceResources->SetDpi(96.0f); // TODO: using default 96 DPI for now
Expand Down