Handle mismatched swapchain & window sizes

* The debug text used to render at swapchain dimensions, but that could
  make it unreadable if the window was significantly different, so apply a
  scaling factor to account for it.
This commit is contained in:
baldurk
2014-10-30 22:48:12 +00:00
parent e8508be085
commit 1ac13f418c
3 changed files with 18 additions and 6 deletions
+13
View File
@@ -106,6 +106,9 @@ D3D11DebugManager::D3D11DebugManager(WrappedID3D11Device *wrapper)
m_OutputWindowID = 1;
m_supersamplingX = 1.0f;
m_supersamplingY = 1.0f;
m_WrappedDevice = wrapper;
ID3D11DeviceContext *ctx = NULL;
m_WrappedDevice->GetImmediateContext(&ctx);
@@ -1628,6 +1631,13 @@ bool D3D11DebugManager::InitFontRendering()
return true;
}
void D3D11DebugManager::SetOutputWindow(HWND w)
{
RECT rect;GetClientRect(w, &rect);
m_supersamplingX = float(m_width)/float(rect.right-rect.left);
m_supersamplingY = float(m_height)/float(rect.bottom-rect.top);
}
void D3D11DebugManager::OutputWindow::MakeRTV()
{
ID3D11Texture2D *texture = NULL;
@@ -3201,6 +3211,9 @@ void D3D11DebugManager::RenderTextInternal(float x, float y, const char *text)
data.TextSize = m_Font.CharSize;
data.FontScreenAspect.x *= m_Font.CharAspect;
data.FontScreenAspect.x *= m_supersamplingX;
data.FontScreenAspect.y *= m_supersamplingY;
data.CharacterSize.x = 1.0f/float(FONT_TEX_WIDTH);
data.CharacterSize.y = 1.0f/float(FONT_TEX_HEIGHT);
+2
View File
@@ -108,6 +108,7 @@ class D3D11DebugManager
void FlipOutputWindow(uint64_t id);
void SetOutputDimensions(int w, int h) { m_width = w; m_height = h; }
void SetOutputWindow(HWND w);
int GetWidth() { return m_width; }
int GetHeight() { return m_height; }
@@ -252,6 +253,7 @@ class D3D11DebugManager
CacheElem &GetCachedElem(ResourceId id, bool raw);
int m_width, m_height;
float m_supersamplingX, m_supersamplingY;
WrappedID3D11Device *m_WrappedDevice;
WrappedID3D11DeviceContext *m_WrappedContext;
+3 -6
View File
@@ -2349,8 +2349,6 @@ void WrappedID3D11Device::SetSwapChainTexture(IDXGISwapChain *swap, DXGI_SWAP_CH
if(m_SwapChain == NULL)
{
m_SwapChain = swap;
GetDebugManager()->SetOutputDimensions(desc.Width, desc.Height);
}
}
@@ -2767,6 +2765,7 @@ bool WrappedID3D11Device::EndFrameCapture(void *wnd)
DXGI_SWAP_CHAIN_DESC swapDesc = {0};
swap->GetDesc(&swapDesc);
GetDebugManager()->SetOutputDimensions(swapDesc.BufferDesc.Width, swapDesc.BufferDesc.Height);
GetDebugManager()->SetOutputWindow(swapDesc.OutputWindow);
const char *reasonString = "Unknown reason";
switch(reason)
@@ -2777,8 +2776,6 @@ bool WrappedID3D11Device::EndFrameCapture(void *wnd)
}
GetDebugManager()->RenderText(0.0f, 0.0f, "Failed to capture frame %u: %hs", m_FrameCounter, reasonString);
GetDebugManager()->SetOutputDimensions(w, h);
}
old.ApplyState(m_pImmediateContext);
@@ -2931,6 +2928,7 @@ HRESULT WrappedID3D11Device::Present(IDXGISwapChain *swap, UINT SyncInterval, UI
DXGI_SWAP_CHAIN_DESC swapDesc = {0};
swap->GetDesc(&swapDesc);
GetDebugManager()->SetOutputDimensions(swapDesc.BufferDesc.Width, swapDesc.BufferDesc.Height);
GetDebugManager()->SetOutputWindow(swapDesc.OutputWindow);
if(swap == m_SwapChain)
{
@@ -3016,8 +3014,6 @@ HRESULT WrappedID3D11Device::Present(IDXGISwapChain *swap, UINT SyncInterval, UI
GetDebugManager()->RenderText(0.0f, 0.0f, str.c_str());
}
GetDebugManager()->SetOutputDimensions(w, h);
old.ApplyState(m_pImmediateContext);
}
@@ -3045,6 +3041,7 @@ HRESULT WrappedID3D11Device::Present(IDXGISwapChain *swap, UINT SyncInterval, UI
DXGI_SWAP_CHAIN_DESC swapDesc = {0};
m_SwapChain->GetDesc(&swapDesc);
GetDebugManager()->SetOutputDimensions(swapDesc.BufferDesc.Width, swapDesc.BufferDesc.Height);
GetDebugManager()->SetOutputWindow(swapDesc.OutputWindow);
}
}