From 1dce73936fb394cbdd11b6ea6be344204e6a3119 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Tue, 25 Jul 2017 19:47:07 -0700 Subject: [PATCH] Cleanup. --- examples/09-hdr/hdr.cpp | 46 ++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/examples/09-hdr/hdr.cpp b/examples/09-hdr/hdr.cpp index af9ab504d..a3875b0cd 100644 --- a/examples/09-hdr/hdr.cpp +++ b/examples/09-hdr/hdr.cpp @@ -188,9 +188,7 @@ public: m_mesh = meshLoad("meshes/bunny.bin"); - m_fbtextures[0] = bgfx::createTexture2D(uint16_t(m_width), uint16_t(m_height), false, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_RT | BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP); - m_fbtextures[1] = bgfx::createTexture2D(uint16_t(m_width), uint16_t(m_height), false, 1, bgfx::TextureFormat::D16, BGFX_TEXTURE_RT_WRITE_ONLY); - m_fbh = bgfx::createFrameBuffer(BX_COUNTOF(m_fbtextures), m_fbtextures, true); + m_fbh.idx = bgfx::kInvalidHandle; m_lum[0] = bgfx::createFrameBuffer(128, 128, bgfx::TextureFormat::BGRA8); m_lum[1] = bgfx::createFrameBuffer( 64, 64, bgfx::TextureFormat::BGRA8); @@ -244,7 +242,11 @@ public: } bgfx::destroy(m_bright); bgfx::destroy(m_blur); - bgfx::destroy(m_fbh); + + if (bgfx::isValid(m_fbh) ) + { + bgfx::destroy(m_fbh); + } bgfx::destroy(m_meshProgram); bgfx::destroy(m_skyProgram); @@ -277,7 +279,8 @@ public: { if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) ) { - if (m_oldWidth != m_width + if (!bgfx::isValid(m_fbh) + || m_oldWidth != m_width || m_oldHeight != m_height || m_oldReset != m_reset) { @@ -288,10 +291,37 @@ public: uint32_t msaa = (m_reset&BGFX_RESET_MSAA_MASK)>>BGFX_RESET_MSAA_SHIFT; - bgfx::destroy(m_fbh); + if (bgfx::isValid(m_fbh) ) + { + bgfx::destroy(m_fbh); + } + + m_fbtextures[0] = bgfx::createTexture2D( + uint16_t(m_width) + , uint16_t(m_height) + , false + , 1 + , bgfx::TextureFormat::BGRA8 + , ((msaa + 1) << BGFX_TEXTURE_RT_MSAA_SHIFT) | BGFX_TEXTURE_U_CLAMP | BGFX_TEXTURE_V_CLAMP + ); + + const uint32_t textureFlags = BGFX_TEXTURE_RT_WRITE_ONLY|( (msaa+1)<