From 3a8e0e2bb16d105d237da4adbd0af94fd7f6089e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Fri, 9 Oct 2020 20:47:50 -0700 Subject: [PATCH] Fixed blit on cubemaps. --- examples/08-update/update.cpp | 32 +++++++++++++++++++-- src/bgfx.cpp | 54 +++++++++++++++++++---------------- src/bgfx_p.h | 15 ++++++++-- 3 files changed, 72 insertions(+), 29 deletions(-) diff --git a/examples/08-update/update.cpp b/examples/08-update/update.cpp index a32007122..24066e9d5 100644 --- a/examples/08-update/update.cpp +++ b/examples/08-update/update.cpp @@ -588,7 +588,21 @@ public: updateTextureCubeRectBgra8(m_textureCube[0], face.m_side, rect.m_x, rect.m_y, rect.m_width, rect.m_height, m_rr, m_gg, m_bb); if (m_blitSupported) { - bgfx::blit(0, m_textureCube[1], 0, rect.m_x, rect.m_y, face.m_side, m_textureCube[0], 0, rect.m_x, rect.m_y, face.m_side, rect.m_width, rect.m_height); + bgfx::blit( + 0 + , m_textureCube[1] + , 0 + , rect.m_x + , rect.m_y + , face.m_side + , m_textureCube[0] + , 0 + , rect.m_x + , rect.m_y + , face.m_side + , rect.m_width + , rect.m_height + ); } m_rr = m_rng.gen()%255; @@ -607,7 +621,21 @@ public: updateTextureCubeRectBgra8(m_textureCube[0], face.m_side, rect.m_x, rect.m_y, rect.m_width, rect.m_height, 0, 0, 0); if (m_blitSupported) { - bgfx::blit(0, m_textureCube[1], 0, rect.m_x, rect.m_y, face.m_side, m_textureCube[0], 0, rect.m_x, rect.m_y, face.m_side, rect.m_width, rect.m_height); + bgfx::blit( + 0 + , m_textureCube[1] + , 0 + , rect.m_x + , rect.m_y + , face.m_side + , m_textureCube[0] + , 0 + , rect.m_x + , rect.m_y + , face.m_side + , rect.m_width + , rect.m_height + ); } m_cube.clear(face); diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 5cae41e78..a11a38628 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -23,21 +23,24 @@ namespace bgfx #define BGFX_API_THREAD_MAGIC UINT32_C(0x78666762) #if BGFX_CONFIG_MULTITHREADED -# define BGFX_CHECK_API_THREAD() \ + +# define BGFX_CHECK_API_THREAD() \ BX_ASSERT(NULL != s_ctx, "Library is not initialized yet."); \ BX_ASSERT(BGFX_API_THREAD_MAGIC == s_threadIndex, "Must be called from main thread.") -# define BGFX_CHECK_RENDER_THREAD() \ + +# define BGFX_CHECK_RENDER_THREAD() \ BX_ASSERT( (NULL != s_ctx && s_ctx->m_singleThreaded) \ - || ~BGFX_API_THREAD_MAGIC == s_threadIndex \ - , "Must be called from render thread." \ + || ~BGFX_API_THREAD_MAGIC == s_threadIndex \ + , "Must be called from render thread." \ ) + #else # define BGFX_CHECK_API_THREAD() # define BGFX_CHECK_RENDER_THREAD() #endif // BGFX_CONFIG_MULTITHREADED #define BGFX_CHECK_CAPS(_caps, _msg) \ - BX_ASSERT(0 != (g_caps.supported & (_caps) ) \ + BX_ASSERT(0 != (g_caps.supported & (_caps) ) \ , _msg " Use bgfx::getCaps to check " #_caps " backend renderer capabilities." \ ); @@ -3869,32 +3872,35 @@ namespace bgfx BX_ASSERT(_srcMip < src.m_numMips, "Invalid blit src mip (%d > %d)", _srcMip, src.m_numMips - 1); BX_ASSERT(_dstMip < dst.m_numMips, "Invalid blit dst mip (%d > %d)", _dstMip, dst.m_numMips - 1); - uint32_t srcWidth = bx::uint32_max(1, src.m_width >> _srcMip); - uint32_t srcHeight = bx::uint32_max(1, src.m_height >> _srcMip); - uint32_t srcDepth = bx::uint32_max(1, src.m_depth >> _srcMip); - uint32_t dstWidth = bx::uint32_max(1, dst.m_width >> _dstMip); - uint32_t dstHeight = bx::uint32_max(1, dst.m_height >> _dstMip); - uint32_t dstDepth = bx::uint32_max(1, dst.m_depth >> _dstMip); + uint32_t srcWidth = bx::max(1, src.m_width >> _srcMip); + uint32_t srcHeight = bx::max(1, src.m_height >> _srcMip); + uint32_t dstWidth = bx::max(1, dst.m_width >> _dstMip); + uint32_t dstHeight = bx::max(1, dst.m_height >> _dstMip); + + uint32_t srcDepth = src.isCubeMap() ? 6 : bx::max(1, src.m_depth >> _srcMip); + uint32_t dstDepth = dst.isCubeMap() ? 6 : bx::max(1, dst.m_depth >> _dstMip); BX_ASSERT(_srcX < srcWidth && _srcY < srcHeight && _srcZ < srcDepth - , "Blit src coordinates out of range (%d,%d,%d) >= (%d,%d,%d)" + , "Blit src coordinates out of range (%d, %d, %d) >= (%d, %d, %d)" , _srcX, _srcY, _srcZ - , srcWidth, srcHeight, srcDepth); + , srcWidth, srcHeight, srcDepth + ); BX_ASSERT(_dstX < dstWidth && _dstY < dstHeight && _dstZ < dstDepth - , "Blit dst coordinates out of range (%d,%d,%d) >= (%d,%d,%d)" + , "Blit dst coordinates out of range (%d, %d, %d) >= (%d, %d, %d)" , _dstX, _dstY, _dstZ - , dstWidth, dstHeight, dstDepth); + , dstWidth, dstHeight, dstDepth + ); - srcWidth = bx::uint32_min(srcWidth, _srcX + _width) - _srcX; - srcHeight = bx::uint32_min(srcHeight, _srcY + _height) - _srcY; - srcDepth = bx::uint32_min(srcDepth, _srcZ + _depth) - _srcZ; - dstWidth = bx::uint32_min(dstWidth, _dstX + _width) - _dstX; - dstHeight = bx::uint32_min(dstHeight, _dstY + _height) - _dstY; - dstDepth = bx::uint32_min(dstDepth, _dstZ + _depth) - _dstZ; + srcWidth = bx::min(srcWidth, _srcX + _width ) - _srcX; + srcHeight = bx::min(srcHeight, _srcY + _height) - _srcY; + srcDepth = bx::min(srcDepth, _srcZ + _depth ) - _srcZ; + dstWidth = bx::min(dstWidth, _dstX + _width ) - _dstX; + dstHeight = bx::min(dstHeight, _dstY + _height) - _dstY; + dstDepth = bx::min(dstDepth, _dstZ + _depth ) - _dstZ; - uint16_t width = uint16_t(bx::min(srcWidth, dstWidth)); - uint16_t height = uint16_t(bx::min(srcHeight, dstHeight)); - uint16_t depth = uint16_t(bx::min(srcDepth, dstDepth)); + uint16_t width = bx::min(srcWidth, dstWidth); + uint16_t height = bx::min(srcHeight, dstHeight); + uint16_t depth = bx::min(srcDepth, dstDepth); BGFX_ENCODER(blit(_id, _dst, _dstMip, _dstX, _dstY, _dstZ, _src, _srcMip, _srcX, _srcY, _srcZ, width, height, depth) ); } diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 5445ee9c9..1af7a9798 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -1820,6 +1820,7 @@ namespace bgfx , uint16_t _numLayers , bool _ptrPending , bool _immutable + , bool _cubeMap , uint64_t _flags ) { @@ -1835,6 +1836,7 @@ namespace bgfx m_numLayers = _numLayers; m_owned = false; m_immutable = _immutable; + m_cubeMap = _cubeMap; m_flags = _flags; } @@ -1848,6 +1850,11 @@ namespace bgfx return 0 != (m_flags&BGFX_TEXTURE_READ_BACK); } + bool isCubeMap() const + { + return m_cubeMap; + } + String m_name; void* m_ptr; uint64_t m_flags; @@ -1862,6 +1869,7 @@ namespace bgfx uint16_t m_numLayers; bool m_owned; bool m_immutable; + bool m_cubeMap; }; struct FrameBufferRef @@ -4257,15 +4265,16 @@ namespace bgfx TextureRef& ref = m_textureRef[handle.idx]; ref.init( _ratio - , (uint16_t)imageContainer.m_width - , (uint16_t)imageContainer.m_height - , (uint16_t)imageContainer.m_depth + , uint16_t(imageContainer.m_width) + , uint16_t(imageContainer.m_height) + , uint16_t(imageContainer.m_depth) , _info->format , _info->storageSize , imageContainer.m_numMips , imageContainer.m_numLayers , 0 != (g_caps.supported & BGFX_CAPS_TEXTURE_DIRECT_ACCESS) , _immutable + , imageContainer.m_cubeMap , _flags );