From 8296514a618ff2bbd249bb14549efe9593cf09ba Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Fri, 26 Feb 2016 10:16:21 -1000 Subject: [PATCH] Blit rectangle fixes --- lib/graphicsdev/D3D11.cpp | 7 ++++--- lib/graphicsdev/D3D12.cpp | 7 ++++--- lib/graphicsdev/GL.cpp | 9 +++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/graphicsdev/D3D11.cpp b/lib/graphicsdev/D3D11.cpp index 892ad85..3faa3cf 100644 --- a/lib/graphicsdev/D3D11.cpp +++ b/lib/graphicsdev/D3D11.cpp @@ -902,9 +902,10 @@ struct D3D11CommandQueue : IGraphicsCommandQueue } else { - UINT y = tlOrigin ? rect.location[1] : (tex->m_height - rect.size[1] - rect.location[1]); - D3D11_BOX box = {UINT(rect.location[0]), y, 0, UINT(rect.location[0] + rect.size[0]), y + rect.size[1], 1}; - m_deferredCtx->CopySubresourceRegion1(tex->m_colorBindTex.Get(), 0, rect.location[0], y, 0, + int y = tlOrigin ? rect.location[1] : (tex->m_height - rect.size[1] - rect.location[1]); + D3D11_BOX box = {UINT(std::max(0, rect.location[0])), UINT(std::max(0, y)), 0, + UINT(std::max(0, rect.location[0] + rect.size[0])), UINT(std::max(0, y + rect.size[1])), 1}; + m_deferredCtx->CopySubresourceRegion1(tex->m_colorBindTex.Get(), 0, box.left, box.top, 0, tex->m_colorTex.Get(), 0, &box, D3D11_COPY_DISCARD); } } diff --git a/lib/graphicsdev/D3D12.cpp b/lib/graphicsdev/D3D12.cpp index dce88ea..6765006 100644 --- a/lib/graphicsdev/D3D12.cpp +++ b/lib/graphicsdev/D3D12.cpp @@ -1210,13 +1210,14 @@ struct D3D12CommandQueue : IGraphicsCommandQueue } else { - UINT y = tlOrigin ? rect.location[1] : (tex->m_height - rect.size[1] - rect.location[1]); - D3D12_BOX box = {UINT(rect.location[0]), y, 0, UINT(rect.location[0] + rect.size[0]), y + rect.size[1], 1}; + int y = tlOrigin ? rect.location[1] : (tex->m_height - rect.size[1] - rect.location[1]); + D3D12_BOX box = {UINT(std::max(0, rect.location[0])), UINT(std::max(0, y)), 0, + UINT(std::max(0, rect.location[0] + rect.size[0])), UINT(std::max(0, y + rect.size[1])), 1}; D3D12_TEXTURE_COPY_LOCATION dst = {tex->m_colorBindTex.Get(), D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX}; dst.SubresourceIndex = 0; D3D12_TEXTURE_COPY_LOCATION src = {tex->m_colorTex.Get(), D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX}; src.SubresourceIndex = 0; - m_cmdList->CopyTextureRegion(&dst, rect.location[0], y, 0, &src, &box); + m_cmdList->CopyTextureRegion(&dst, box.left, box.top, 0, &src, &box); } D3D12_RESOURCE_BARRIER copyTeardown[] = diff --git a/lib/graphicsdev/GL.cpp b/lib/graphicsdev/GL.cpp index 53b11aa..f09a8f0 100644 --- a/lib/graphicsdev/GL.cpp +++ b/lib/graphicsdev/GL.cpp @@ -1140,11 +1140,16 @@ struct GLCommandQueue : IGraphicsCommandQueue std::vector& cmds = m_cmdBufs[m_fillBuf]; cmds.emplace_back(Command::Op::ResolveBindTexture); cmds.back().resolveTex = texture; - cmds.back().rect = rect; cmds.back().resolveColor = color; cmds.back().resolveDepth = depth; + SWindowRect& targetRect = cmds.back().rect; + targetRect.location[0] = std::max(0, rect.location[0]); if (tlOrigin) - cmds.back().rect.location[1] = static_cast(texture)->m_height - rect.location[1] - rect.size[1]; + targetRect.location[1] = std::max(0, int(static_cast(texture)->m_height) - rect.location[1] - rect.size[1]); + else + targetRect.location[1] = std::max(0, rect.location[1]); + targetRect.size[0] = std::max(0, rect.size[0]); + targetRect.size[1] = std::max(0, rect.size[1]); } void resolveDisplay(ITextureR* source)