From cd2030cc11e9905c98725ec324c491ed72ef48a7 Mon Sep 17 00:00:00 2001 From: Jean Tampon Date: Sun, 16 Jan 2022 17:15:14 +0100 Subject: [PATCH] Use shift directly instead of float casts (#2714) --- examples/38-bloom/bloom.cpp | 39 ++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/examples/38-bloom/bloom.cpp b/examples/38-bloom/bloom.cpp index d7c2d368a..61d2118ff 100644 --- a/examples/38-bloom/bloom.cpp +++ b/examples/38-bloom/bloom.cpp @@ -178,10 +178,10 @@ void screenSpaceQuad(float _textureWidth, float _textureHeight, float _texelHalf } } -class ExampleDeferred : public entry::AppI +class ExampleBloom : public entry::AppI { public: - ExampleDeferred(const char* _name, const char* _description, const char* _url) + ExampleBloom(const char* _name, const char* _description, const char* _url) : entry::AppI(_name, _description, _url) { } @@ -396,11 +396,9 @@ public: bgfx::destroy(m_texChainFb[ii]); } - const float dim = float(1 << ii); - m_texChainFb[ii] = bgfx::createFrameBuffer( - (uint16_t)(m_width / dim) - , (uint16_t)(m_height / dim) + (uint16_t)(m_width >> ii) + , (uint16_t)(m_height >> ii) , bgfx::TextureFormat::RGBA32F , tsFlags ); @@ -446,21 +444,19 @@ public: for (uint16_t ii = 0; ii < TEX_CHAIN_LEN-1; ++ii) { - const float dim = float(1 << (ii + 1) ); - + const uint16_t shift = ii + 1; bgfx::setViewRect(RENDER_PASS_DOWNSAMPLE0_ID + ii, 0, 0 - , uint16_t(m_width / dim) - , uint16_t(m_height / dim) + , uint16_t(m_width >> shift) + , uint16_t(m_height >> shift) ); } for (uint16_t ii = 0; ii < TEX_CHAIN_LEN-1; ++ii) { - const float dim = float(1 << (TEX_CHAIN_LEN - ii - 2) ); - + const uint16_t shift = TEX_CHAIN_LEN - ii - 2; bgfx::setViewRect(RENDER_PASS_UPSAMPLE0_ID + ii, 0, 0 - , uint16_t(m_width / dim) - , uint16_t(m_height / dim) + , uint16_t(m_width >> shift) + , uint16_t(m_height >> shift) ); } @@ -539,11 +535,11 @@ public: // Now downsample. for (uint16_t ii = 0; ii < TEX_CHAIN_LEN-1; ++ii) { - const float dim = float(1 << (ii + 1) ); + const uint16_t shift = ii + 1; const float pixelSize[4] = { - 1.0f / (m_width / dim), - 1.0f / (m_height / dim), + 1.0f / (float)(m_width >> shift), + 1.0f / (float)(m_height >> shift), 0.0f, 0.0f, }; @@ -563,12 +559,11 @@ public: // Now upsample. for (uint16_t ii = 0; ii < TEX_CHAIN_LEN - 1; ++ii) { - const float dim = float(1 << (TEX_CHAIN_LEN - 2 - ii) ); - + const uint16_t shift = TEX_CHAIN_LEN - 2 - ii; const float pixelSize[4] = { - 1.0f / (float)(m_width / dim), - 1.0f / (float)(m_height / dim), + 1.0f / (float)(m_width >> shift), + 1.0f / (float)(m_height >> shift), 0.0f, 0.0f, }; @@ -658,7 +653,7 @@ public: } // namespace ENTRY_IMPLEMENT_MAIN( - ExampleDeferred + ExampleBloom , "38-bloom" , "Bloom." , "https://bkaradzic.github.io/bgfx/examples.html#bloom"