summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/21-deferred/deferred.cpp
diff options
context:
space:
mode:
author Miodrag Milanović <mmicko@gmail.com>2023-01-05 05:12:10 +0100
committer GitHub <noreply@github.com>2023-01-04 23:12:10 -0500
commit5581eaa50a42256242f32569f59ce10d70ddd8c2 (patch)
tree0d79e41b381ebf6d50ab5b7e20c0993b7328b5b6 /3rdparty/bgfx/examples/21-deferred/deferred.cpp
parent34c37d4f5415f886ec3ae462b008cebbf5fa22f9 (diff)
Update BGFX, BX and BIMG (#10750)
* 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.cpp68
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;