mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-25 00:58:30 -05:00
Clamp blit to texture bounds.
This commit is contained in:
parent
ad5a46779a
commit
60c7072558
4 changed files with 48 additions and 15 deletions
|
@ -3800,7 +3800,10 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
|||
const uint32_t textureWidth = bx::uint32_max(blockInfo.blockWidth, imageContainer.m_width >>startLod);
|
||||
const uint32_t textureHeight = bx::uint32_max(blockInfo.blockHeight, imageContainer.m_height>>startLod);
|
||||
|
||||
m_flags = _flags;
|
||||
m_flags = _flags;
|
||||
m_width = textureWidth;
|
||||
m_height = textureHeight;
|
||||
m_depth = imageContainer.m_depth;
|
||||
m_requestedFormat = (uint8_t)imageContainer.m_format;
|
||||
m_textureFormat = (uint8_t)imageContainer.m_format;
|
||||
|
||||
|
@ -4594,16 +4597,26 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
|||
const BlitItem& blit = _render->m_blitItem[blitItem];
|
||||
blitKey.decode(_render->m_blitKeys[blitItem+1]);
|
||||
|
||||
const TextureD3D11 src = m_textures[blit.m_src.idx];
|
||||
const TextureD3D11 dst = m_textures[blit.m_dst.idx];
|
||||
const TextureD3D11& src = m_textures[blit.m_src.idx];
|
||||
const TextureD3D11& dst = m_textures[blit.m_dst.idx];
|
||||
|
||||
uint32_t srcWidth = bx::uint32_min(src.m_width, blit.m_srcX + blit.m_width) - blit.m_srcX;
|
||||
uint32_t srcHeight = bx::uint32_min(src.m_height, blit.m_srcY + blit.m_height) - blit.m_srcY;
|
||||
uint32_t srcDepth = bx::uint32_min(src.m_depth, blit.m_srcZ + blit.m_depth) - blit.m_srcZ;
|
||||
uint32_t dstWidth = bx::uint32_min(dst.m_width, blit.m_dstX + blit.m_width) - blit.m_dstX;
|
||||
uint32_t dstHeight = bx::uint32_min(dst.m_height, blit.m_dstY + blit.m_height) - blit.m_dstY;
|
||||
uint32_t dstDepth = bx::uint32_min(dst.m_depth, blit.m_dstZ + blit.m_depth) - blit.m_dstZ;
|
||||
uint32_t width = bx::uint32_min(srcWidth, dstWidth);
|
||||
uint32_t height = bx::uint32_min(srcHeight, dstHeight);
|
||||
uint32_t depth = bx::uint32_min(srcDepth, dstDepth);
|
||||
|
||||
D3D11_BOX box;
|
||||
box.left = blit.m_srcX;
|
||||
box.top = blit.m_srcY;
|
||||
box.front = blit.m_srcZ;
|
||||
box.right = blit.m_srcX + blit.m_width;
|
||||
box.bottom = blit.m_srcY + blit.m_height;
|
||||
box.back = blit.m_srcZ + bx::uint16_max(blit.m_depth, 1);
|
||||
box.right = blit.m_srcX + width;
|
||||
box.bottom = blit.m_srcY + height;
|
||||
box.back = blit.m_srcZ + bx::uint32_max(1, depth);
|
||||
|
||||
deviceCtx->CopySubresourceRegion(dst.m_ptr
|
||||
, blit.m_dstMip
|
||||
|
|
|
@ -238,6 +238,9 @@ namespace bgfx { namespace d3d11
|
|||
ID3D11ShaderResourceView* m_srv;
|
||||
ID3D11UnorderedAccessView* m_uav;
|
||||
uint32_t m_flags;
|
||||
uint32_t m_width;
|
||||
uint32_t m_height;
|
||||
uint32_t m_depth;
|
||||
uint8_t m_type;
|
||||
uint8_t m_requestedFormat;
|
||||
uint8_t m_textureFormat;
|
||||
|
|
|
@ -3305,11 +3305,18 @@ namespace bgfx { namespace d3d9
|
|||
const BlitItem& blit = _render->m_blitItem[blitItem];
|
||||
blitKey.decode(_render->m_blitKeys[blitItem+1]);
|
||||
|
||||
const TextureD3D9 src = m_textures[blit.m_src.idx];
|
||||
const TextureD3D9 dst = m_textures[blit.m_dst.idx];
|
||||
const TextureD3D9& src = m_textures[blit.m_src.idx];
|
||||
const TextureD3D9& dst = m_textures[blit.m_dst.idx];
|
||||
|
||||
RECT srcRect = { blit.m_srcX, blit.m_srcY, blit.m_srcX + blit.m_width, blit.m_srcY + blit.m_height };
|
||||
RECT dstRect = { blit.m_dstX, blit.m_dstY, blit.m_dstX + blit.m_width, blit.m_dstY + blit.m_height };
|
||||
uint32_t srcWidth = bx::uint32_min(src.m_width, blit.m_srcX + blit.m_width) - blit.m_srcX;
|
||||
uint32_t srcHeight = bx::uint32_min(src.m_height, blit.m_srcY + blit.m_height) - blit.m_srcY;
|
||||
uint32_t dstWidth = bx::uint32_min(dst.m_width, blit.m_dstX + blit.m_width) - blit.m_dstX;
|
||||
uint32_t dstHeight = bx::uint32_min(dst.m_height, blit.m_dstY + blit.m_height) - blit.m_dstY;
|
||||
uint32_t width = bx::uint32_min(srcWidth, dstWidth);
|
||||
uint32_t height = bx::uint32_min(srcHeight, dstHeight);
|
||||
|
||||
RECT srcRect = { blit.m_srcX, blit.m_srcY, blit.m_srcX + width, blit.m_srcY + height };
|
||||
RECT dstRect = { blit.m_dstX, blit.m_dstY, blit.m_dstX + width, blit.m_dstY + height };
|
||||
|
||||
IDirect3DSurface9* srcSurface;
|
||||
DX_CHECK(src.m_texture2d->GetSurfaceLevel(blit.m_srcMip, &srcSurface) );
|
||||
|
|
|
@ -5277,8 +5277,18 @@ namespace bgfx { namespace gl
|
|||
const BlitItem& blit = _render->m_blitItem[blitItem];
|
||||
blitKey.decode(_render->m_blitKeys[blitItem+1]);
|
||||
|
||||
const TextureGL src = m_textures[blit.m_src.idx];
|
||||
const TextureGL dst = m_textures[blit.m_dst.idx];
|
||||
const TextureGL& src = m_textures[blit.m_src.idx];
|
||||
const TextureGL& dst = m_textures[blit.m_dst.idx];
|
||||
|
||||
uint32_t srcWidth = bx::uint32_min(src.m_width, blit.m_srcX + blit.m_width) - blit.m_srcX;
|
||||
uint32_t srcHeight = bx::uint32_min(src.m_height, blit.m_srcY + blit.m_height) - blit.m_srcY;
|
||||
uint32_t srcDepth = bx::uint32_min(src.m_depth, blit.m_srcZ + blit.m_depth) - blit.m_srcZ;
|
||||
uint32_t dstWidth = bx::uint32_min(dst.m_width, blit.m_dstX + blit.m_width) - blit.m_dstX;
|
||||
uint32_t dstHeight = bx::uint32_min(dst.m_height, blit.m_dstY + blit.m_height) - blit.m_dstY;
|
||||
uint32_t dstDepth = bx::uint32_min(dst.m_depth, blit.m_dstZ + blit.m_depth) - blit.m_dstZ;
|
||||
uint32_t width = bx::uint32_min(srcWidth, dstWidth);
|
||||
uint32_t height = bx::uint32_min(srcHeight, dstHeight);
|
||||
uint32_t depth = bx::uint32_min(srcDepth, dstDepth);
|
||||
|
||||
GL_CHECK(glCopyImageSubData(src.m_id
|
||||
, src.m_target
|
||||
|
@ -5292,9 +5302,9 @@ namespace bgfx { namespace gl
|
|||
, blit.m_dstX
|
||||
, blit.m_dstY
|
||||
, blit.m_dstZ
|
||||
, blit.m_width
|
||||
, blit.m_height
|
||||
, bx::uint32_max(blit.m_depth, 1)
|
||||
, width
|
||||
, height
|
||||
, bx::uint32_max(depth, 1)
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue