diff options
author | 2023-01-05 15:32:40 +0100 | |
---|---|---|
committer | 2023-01-05 09:32:40 -0500 | |
commit | 812e6094f47bb8d1da5a6b421aa4c724cf2035c0 (patch) | |
tree | 0f5bab2fe9393d1f629e9bf63e76cecca74ec0c9 /3rdparty/bgfx/examples/21-deferred/deferred.cpp | |
parent | 4a1b41854bba8fc2567906b88bab8ca81e75d187 (diff) |
Update BGFX, BX and BIMG (#10789)
* Update to bgfx a93a714632b79b5ddbf5c86ac323fa9b76ed3433
Co-authored-by: Бранимир Караџић <branimirkaradzic@gmail.com>
Diffstat (limited to '3rdparty/bgfx/examples/21-deferred/deferred.cpp')
-rw-r--r-- | 3rdparty/bgfx/examples/21-deferred/deferred.cpp | 68 |
1 files changed, 56 insertions, 12 deletions
diff --git a/3rdparty/bgfx/examples/21-deferred/deferred.cpp b/3rdparty/bgfx/examples/21-deferred/deferred.cpp index 375edbab9fc..6c379fd3fe1 100644 --- a/3rdparty/bgfx/examples/21-deferred/deferred.cpp +++ b/3rdparty/bgfx/examples/21-deferred/deferred.cpp @@ -1,13 +1,13 @@ /* - * Copyright 2011-2021 Branimir Karadzic. All rights reserved. - * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause + * Copyright 2011-2022 Branimir Karadzic. All rights reserved. + * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE */ +#include <bx/bounds.h> #include "common.h" #include "bgfx_utils.h" #include "imgui/imgui.h" #include "camera.h" -#include "bounds.h" namespace { @@ -211,6 +211,8 @@ public: bgfx::Init init; init.type = args.m_type; init.vendorId = args.m_pciId; + init.platformData.nwh = entry::getNativeWindowHandle(entry::kDefaultWindowHandle); + init.platformData.ndt = entry::getNativeDisplayHandle(); init.resolution.width = m_width; init.resolution.height = m_height; init.resolution.reset = m_reset; @@ -275,6 +277,7 @@ public: u_mtx = bgfx::createUniform("u_mtx", bgfx::UniformType::Mat4); u_lightPosRadius = bgfx::createUniform("u_lightPosRadius", bgfx::UniformType::Vec4); u_lightRgbInnerR = bgfx::createUniform("u_lightRgbInnerR", bgfx::UniformType::Vec4); + u_layer = bgfx::createUniform("u_layer", bgfx::UniformType::Vec4); // Create program from shaders. m_geomProgram = loadProgram("vs_deferred_geom", "fs_deferred_geom"); @@ -288,11 +291,15 @@ public: if (0 != (BGFX_CAPS_TEXTURE_2D_ARRAY & bgfx::getCaps()->supported) ) { - m_lightTaProgram = loadProgram("vs_deferred_light", "fs_deferred_light_ta"); + m_lightTaProgram = loadProgram("vs_deferred_light", "fs_deferred_light_ta"); + m_combineTaProgram = loadProgram("vs_deferred_combine", "fs_deferred_combine_ta"); + m_debugTaProgram = loadProgram("vs_deferred_debug", "fs_deferred_debug_ta"); } else { - m_lightTaProgram = BGFX_INVALID_HANDLE; + m_lightTaProgram = BGFX_INVALID_HANDLE; + m_combineTaProgram = BGFX_INVALID_HANDLE; + m_debugTaProgram = BGFX_INVALID_HANDLE; } if (0 != (BGFX_CAPS_IMAGE_RW & bgfx::getCaps()->supported) @@ -388,7 +395,19 @@ public: } bgfx::destroy(m_combineProgram); + + if (bgfx::isValid(m_combineTaProgram) ) + { + bgfx::destroy(m_combineTaProgram); + } + bgfx::destroy(m_debugProgram); + + if (bgfx::isValid(m_debugTaProgram) ) + { + bgfx::destroy(m_debugTaProgram); + } + bgfx::destroy(m_lineProgram); bgfx::destroy(m_textureColor); @@ -401,6 +420,7 @@ public: bgfx::destroy(s_depth); bgfx::destroy(s_light); + bgfx::destroy(u_layer); bgfx::destroy(u_lightPosRadius); bgfx::destroy(u_lightRgbInnerR); bgfx::destroy(u_mtx); @@ -679,7 +699,7 @@ public: // Draw lights into light buffer. for (int32_t light = 0; light < m_numLights; ++light) { - Sphere lightPosRadius; + bx::Sphere lightPosRadius; float lightTime = time * m_lightAnimationSpeed * (bx::sin(light/float(m_numLights) * bx::kPiHalf ) * 0.5f + 0.5f); lightPosRadius.center.x = bx::sin( ( (lightTime + light*0.47f) + bx::kPiHalf*1.37f ) )*offset; @@ -687,7 +707,7 @@ public: lightPosRadius.center.z = bx::sin( ( (lightTime + light*0.37f) + bx::kPiHalf*1.57f ) )*2.0f; lightPosRadius.radius = 2.0f; - Aabb aabb; + bx::Aabb aabb; toAabb(aabb, lightPosRadius); const bx::Vec3 box[8] = @@ -819,21 +839,30 @@ public: } // Combine color and light buffers. - bgfx::setTexture(0, s_albedo, m_gbufferTex[0]); + bgfx::setTexture(0, s_albedo, bgfx::getTexture(m_gbuffer, 0) ); bgfx::setTexture(1, s_light, m_lightBufferTex); bgfx::setState(0 | BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A ); screenSpaceQuad( (float)m_width, (float)m_height, s_texelHalf, m_caps->originBottomLeft); - bgfx::submit(kRenderPassCombine, m_combineProgram); + + if (bgfx::isValid(m_lightTaProgram) + && m_useTArray) + { + bgfx::submit(kRenderPassCombine, m_combineTaProgram); + } + else + { + bgfx::submit(kRenderPassCombine, m_combineProgram); + } if (m_showGBuffer) { const float aspectRatio = float(m_width)/float(m_height); // Draw m_debug m_gbuffer. - for (uint32_t ii = 0; ii < BX_COUNTOF(m_gbufferTex); ++ii) + for (uint8_t ii = 0; ii < BX_COUNTOF(m_gbufferTex); ++ii) { float mtx[16]; bx::mtxSRT(mtx @@ -845,9 +874,21 @@ public: bgfx::setTransform(mtx); bgfx::setVertexBuffer(0, m_vbh); bgfx::setIndexBuffer(m_ibh, 0, 6); - bgfx::setTexture(0, s_texColor, m_gbufferTex[ii]); + bgfx::setTexture(0, s_texColor, bgfx::getTexture(m_gbuffer, ii) ); bgfx::setState(BGFX_STATE_WRITE_RGB); - bgfx::submit(kRenderPassDebugGBuffer, m_debugProgram); + + if (ii != BX_COUNTOF(m_gbufferTex) - 1 + && bgfx::isValid(m_lightTaProgram) + && m_useTArray) + { + const float layer[4] = { float(ii) }; + bgfx::setUniform(u_layer, layer); + bgfx::submit(kRenderPassDebugGBuffer, m_debugTaProgram); + } + else + { + bgfx::submit(kRenderPassDebugGBuffer, m_debugProgram); + } } } } @@ -877,6 +918,7 @@ public: bgfx::UniformHandle u_mtx; bgfx::UniformHandle u_lightPosRadius; bgfx::UniformHandle u_lightRgbInnerR; + bgfx::UniformHandle u_layer; bgfx::ProgramHandle m_geomProgram; bgfx::ProgramHandle m_lightProgram; @@ -884,7 +926,9 @@ public: bgfx::ProgramHandle m_lightUavProgram; bgfx::ProgramHandle m_clearUavProgram; bgfx::ProgramHandle m_combineProgram; + bgfx::ProgramHandle m_combineTaProgram; bgfx::ProgramHandle m_debugProgram; + bgfx::ProgramHandle m_debugTaProgram; bgfx::ProgramHandle m_lineProgram; bgfx::TextureHandle m_textureColor; bgfx::TextureHandle m_textureNormal; |