From 9e8508b64d9118d3f19e66b7d4c8a83126c0b2d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 17 Oct 2015 17:39:44 -0700 Subject: [PATCH] Added blit to 08-update example. --- examples/08-update/update.cpp | 57 ++++++++++++++++++++++++----------- src/renderer_d3d11.cpp | 2 +- src/renderer_d3d12.cpp | 2 +- src/renderer_gl.cpp | 2 +- 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/examples/08-update/update.cpp b/examples/08-update/update.cpp index 51bd8c02..2589d67b 100644 --- a/examples/08-update/update.cpp +++ b/examples/08-update/update.cpp @@ -169,6 +169,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) const bgfx::Caps* caps = bgfx::getCaps(); const bool texture3DSupported = !!(caps->supported & BGFX_CAPS_TEXTURE_3D); + const bool blitSupported = !!(caps->supported & BGFX_CAPS_BLIT); uint32_t numTextures3d = 0; bgfx::TextureHandle textures3d[3] = {}; @@ -215,11 +216,21 @@ int _main_(int /*_argc*/, char** /*_argv*/) const uint32_t textureSide = 2048; - bgfx::TextureHandle textureCube = bgfx::createTextureCube(textureSide, 1 + bgfx::TextureHandle textureCube[2]; + + textureCube[0] = bgfx::createTextureCube(textureSide, 1 , bgfx::TextureFormat::BGRA8 , BGFX_TEXTURE_MIN_POINT|BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIP_POINT ); + if (blitSupported) + { + textureCube[1] = bgfx::createTextureCube(textureSide, 1 + , bgfx::TextureFormat::BGRA8 + , BGFX_TEXTURE_MIN_POINT|BGFX_TEXTURE_MAG_POINT|BGFX_TEXTURE_MIP_POINT|BGFX_TEXTURE_BLIT_DST + ); + } + const uint32_t texture2dSize = 256; bgfx::TextureHandle texture2d = bgfx::createTexture2D(texture2dSize, texture2dSize, 1 @@ -285,7 +296,11 @@ int _main_(int /*_argc*/, char** /*_argv*/) ++hit; const Pack2D& rect = face.m_rect; - updateTextureCubeRectBgra8(textureCube, face.m_side, rect.m_x, rect.m_y, rect.m_width, rect.m_height, rr, gg, bb); + updateTextureCubeRectBgra8(textureCube[0], face.m_side, rect.m_x, rect.m_y, rect.m_width, rect.m_height, rr, gg, bb); + if (blitSupported) + { + bgfx::blit(0, textureCube[1], 0, rect.m_x, rect.m_y, face.m_side, textureCube[0], 0, rect.m_x, rect.m_y, face.m_side, rect.m_width, rect.m_height); + } rr = rand()%255; gg = rand()%255; @@ -347,25 +362,27 @@ int _main_(int /*_argc*/, char** /*_argv*/) // Set view and projection matrix for view 0. bgfx::setViewTransform(0, view, proj); - float mtx[16]; - bx::mtxRotateXY(mtx, time, time*0.37f); + for (uint32_t ii = 0; ii < 1 + uint32_t(blitSupported); ++ii) + { + float mtx[16]; + bx::mtxSRT(mtx, 1.0f, 1.0f, 1.0f, time, time*0.37f, 0.0f, -1.5f*blitSupported + ii*3.0f, 0.0f, 0.0f); - // Set model matrix for rendering. - bgfx::setTransform(mtx); + // Set model matrix for rendering. + bgfx::setTransform(mtx); - // Set vertex and index buffer. - bgfx::setVertexBuffer(vbh); - bgfx::setIndexBuffer(ibh); + // Set vertex and index buffer. + bgfx::setVertexBuffer(vbh); + bgfx::setIndexBuffer(ibh); - // Bind texture. - bgfx::setTexture(0, s_texCube, textureCube); + // Bind texture. + bgfx::setTexture(0, s_texCube, textureCube[ii]); - // Set render states. - bgfx::setState(BGFX_STATE_DEFAULT); - - // Submit primitive for rendering to view 0. - bgfx::submit(0, program); + // Set render states. + bgfx::setState(BGFX_STATE_DEFAULT); + // Submit primitive for rendering to view 0. + bgfx::submit(0, program); + } // Set view and projection matrix for view 1. const float aspectRatio = float(height)/float(width); @@ -373,7 +390,7 @@ int _main_(int /*_argc*/, char** /*_argv*/) bx::mtxOrtho(proj, -size, size, size*aspectRatio, -size*aspectRatio, 0.0f, 1000.0f); bgfx::setViewTransform(1, NULL, proj); - + float mtx[16]; bx::mtxTranslate(mtx, -size+2.0f - BX_COUNTOF(textures)*0.1f*0.5f, 1.9f, 0.0f); // Set model matrix for rendering. @@ -481,7 +498,11 @@ int _main_(int /*_argc*/, char** /*_argv*/) } bgfx::destroyTexture(texture2d); - bgfx::destroyTexture(textureCube); + bgfx::destroyTexture(textureCube[0]); + if (blitSupported) + { + bgfx::destroyTexture(textureCube[1]); + } bgfx::destroyIndexBuffer(ibh); bgfx::destroyVertexBuffer(vbh); if (bgfx::isValid(program3d) ) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index ad0d2098..95427e99 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -4618,7 +4618,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); box.front = blit.m_srcZ; box.right = blit.m_srcX + width; box.bottom = blit.m_srcY + height;; - box.back = blit.m_srcZ + bx::uint32_max(1, depth); + box.back = blit.m_srcZ + bx::uint32_imax(1, depth); deviceCtx->CopySubresourceRegion(dst.m_ptr , blit.m_dstMip diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index d8cccdba..6e225606 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -4419,7 +4419,7 @@ data.NumQualityLevels = 0; box.front = blit.m_srcZ; box.right = blit.m_srcX + width; box.bottom = blit.m_srcY + height;; - box.back = blit.m_srcZ + bx::uint32_max(1, depth); + box.back = blit.m_srcZ + bx::uint32_imax(1, depth); D3D12_TEXTURE_COPY_LOCATION dstLocation = { dst.m_ptr, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, { 0 } }; D3D12_TEXTURE_COPY_LOCATION srcLocation = { src.m_ptr, D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX, { 0 } }; diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 75c0fc12..739888b1 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -5320,7 +5320,7 @@ namespace bgfx { namespace gl , bi.m_dstZ , width , height - , bx::uint32_max(depth, 1) + , bx::uint32_imax(depth, 1) ) ); } }