Clamp blit to texture bounds.

This commit is contained in:
Branimir Karadžić 2015-10-15 17:42:48 -07:00
parent ad5a46779a
commit 60c7072558
4 changed files with 48 additions and 15 deletions

View file

@ -3800,7 +3800,10 @@ BX_PRAGMA_DIAGNOSTIC_POP();
const uint32_t textureWidth = bx::uint32_max(blockInfo.blockWidth, imageContainer.m_width >>startLod); 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); 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_requestedFormat = (uint8_t)imageContainer.m_format;
m_textureFormat = (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]; const BlitItem& blit = _render->m_blitItem[blitItem];
blitKey.decode(_render->m_blitKeys[blitItem+1]); blitKey.decode(_render->m_blitKeys[blitItem+1]);
const TextureD3D11 src = m_textures[blit.m_src.idx]; const TextureD3D11& src = m_textures[blit.m_src.idx];
const TextureD3D11 dst = m_textures[blit.m_dst.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; D3D11_BOX box;
box.left = blit.m_srcX; box.left = blit.m_srcX;
box.top = blit.m_srcY; box.top = blit.m_srcY;
box.front = blit.m_srcZ; box.front = blit.m_srcZ;
box.right = blit.m_srcX + blit.m_width; box.right = blit.m_srcX + width;
box.bottom = blit.m_srcY + blit.m_height; box.bottom = blit.m_srcY + height;
box.back = blit.m_srcZ + bx::uint16_max(blit.m_depth, 1); box.back = blit.m_srcZ + bx::uint32_max(1, depth);
deviceCtx->CopySubresourceRegion(dst.m_ptr deviceCtx->CopySubresourceRegion(dst.m_ptr
, blit.m_dstMip , blit.m_dstMip

View file

@ -238,6 +238,9 @@ namespace bgfx { namespace d3d11
ID3D11ShaderResourceView* m_srv; ID3D11ShaderResourceView* m_srv;
ID3D11UnorderedAccessView* m_uav; ID3D11UnorderedAccessView* m_uav;
uint32_t m_flags; uint32_t m_flags;
uint32_t m_width;
uint32_t m_height;
uint32_t m_depth;
uint8_t m_type; uint8_t m_type;
uint8_t m_requestedFormat; uint8_t m_requestedFormat;
uint8_t m_textureFormat; uint8_t m_textureFormat;

View file

@ -3305,11 +3305,18 @@ namespace bgfx { namespace d3d9
const BlitItem& blit = _render->m_blitItem[blitItem]; const BlitItem& blit = _render->m_blitItem[blitItem];
blitKey.decode(_render->m_blitKeys[blitItem+1]); blitKey.decode(_render->m_blitKeys[blitItem+1]);
const TextureD3D9 src = m_textures[blit.m_src.idx]; const TextureD3D9& src = m_textures[blit.m_src.idx];
const TextureD3D9 dst = m_textures[blit.m_dst.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 }; uint32_t srcWidth = bx::uint32_min(src.m_width, blit.m_srcX + blit.m_width) - blit.m_srcX;
RECT dstRect = { blit.m_dstX, blit.m_dstY, blit.m_dstX + blit.m_width, blit.m_dstY + blit.m_height }; 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; IDirect3DSurface9* srcSurface;
DX_CHECK(src.m_texture2d->GetSurfaceLevel(blit.m_srcMip, &srcSurface) ); DX_CHECK(src.m_texture2d->GetSurfaceLevel(blit.m_srcMip, &srcSurface) );

View file

@ -5277,8 +5277,18 @@ namespace bgfx { namespace gl
const BlitItem& blit = _render->m_blitItem[blitItem]; const BlitItem& blit = _render->m_blitItem[blitItem];
blitKey.decode(_render->m_blitKeys[blitItem+1]); blitKey.decode(_render->m_blitKeys[blitItem+1]);
const TextureGL src = m_textures[blit.m_src.idx]; const TextureGL& src = m_textures[blit.m_src.idx];
const TextureGL dst = m_textures[blit.m_dst.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 GL_CHECK(glCopyImageSubData(src.m_id
, src.m_target , src.m_target
@ -5292,9 +5302,9 @@ namespace bgfx { namespace gl
, blit.m_dstX , blit.m_dstX
, blit.m_dstY , blit.m_dstY
, blit.m_dstZ , blit.m_dstZ
, blit.m_width , width
, blit.m_height , height
, bx::uint32_max(blit.m_depth, 1) , bx::uint32_max(depth, 1)
) ); ) );
} }
} }