summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/08-update
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/examples/08-update')
-rw-r--r--3rdparty/bgfx/examples/08-update/cs_update.sc4
-rw-r--r--3rdparty/bgfx/examples/08-update/fs_update.sc4
-rw-r--r--3rdparty/bgfx/examples/08-update/fs_update_3d.sc4
-rw-r--r--3rdparty/bgfx/examples/08-update/fs_update_cmp.sc4
-rw-r--r--3rdparty/bgfx/examples/08-update/makefile4
-rw-r--r--3rdparty/bgfx/examples/08-update/update.cpp387
-rw-r--r--3rdparty/bgfx/examples/08-update/vs_update.sc4
7 files changed, 374 insertions, 37 deletions
diff --git a/3rdparty/bgfx/examples/08-update/cs_update.sc b/3rdparty/bgfx/examples/08-update/cs_update.sc
index 4b1d5fcc725..54566d8344b 100644
--- a/3rdparty/bgfx/examples/08-update/cs_update.sc
+++ b/3rdparty/bgfx/examples/08-update/cs_update.sc
@@ -1,6 +1,6 @@
/*
* Copyright 2014 Stanlo Slasinski. All rights reserved.
- * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
+ * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
*/
#include "bgfx_compute.sh"
@@ -25,6 +25,6 @@ void main()
{
vec3 color = colors[face]*0.75 + sin(u_time.x*4.0)*0.25;
ivec3 dest = ivec3(gl_GlobalInvocationID.xy, face);
- imageStore(s_texColor, dest, vec4(color,1) );
+ imageStore(s_texColor, dest, vec4(color, 1.0) );
}
}
diff --git a/3rdparty/bgfx/examples/08-update/fs_update.sc b/3rdparty/bgfx/examples/08-update/fs_update.sc
index 7c64dfb8def..41e24ed1fe2 100644
--- a/3rdparty/bgfx/examples/08-update/fs_update.sc
+++ b/3rdparty/bgfx/examples/08-update/fs_update.sc
@@ -1,8 +1,8 @@
$input v_texcoord0
/*
- * Copyright 2011-2018 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 "../common/common.sh"
diff --git a/3rdparty/bgfx/examples/08-update/fs_update_3d.sc b/3rdparty/bgfx/examples/08-update/fs_update_3d.sc
index d07e2abeeef..8986846d5f1 100644
--- a/3rdparty/bgfx/examples/08-update/fs_update_3d.sc
+++ b/3rdparty/bgfx/examples/08-update/fs_update_3d.sc
@@ -1,8 +1,8 @@
$input v_texcoord0
/*
- * Copyright 2011-2018 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 "../common/common.sh"
diff --git a/3rdparty/bgfx/examples/08-update/fs_update_cmp.sc b/3rdparty/bgfx/examples/08-update/fs_update_cmp.sc
index d5e13254172..076d8965e6f 100644
--- a/3rdparty/bgfx/examples/08-update/fs_update_cmp.sc
+++ b/3rdparty/bgfx/examples/08-update/fs_update_cmp.sc
@@ -1,8 +1,8 @@
$input v_texcoord0
/*
- * Copyright 2011-2018 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 "../common/common.sh"
diff --git a/3rdparty/bgfx/examples/08-update/makefile b/3rdparty/bgfx/examples/08-update/makefile
index 171709170a4..19c81e43692 100644
--- a/3rdparty/bgfx/examples/08-update/makefile
+++ b/3rdparty/bgfx/examples/08-update/makefile
@@ -1,6 +1,6 @@
#
-# Copyright 2011-2018 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
#
BGFX_DIR=../..
diff --git a/3rdparty/bgfx/examples/08-update/update.cpp b/3rdparty/bgfx/examples/08-update/update.cpp
index 0eb0c53cabe..e7e54f56f78 100644
--- a/3rdparty/bgfx/examples/08-update/update.cpp
+++ b/3rdparty/bgfx/examples/08-update/update.cpp
@@ -1,12 +1,14 @@
/*
- * Copyright 2011-2018 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 "common.h"
#include "bgfx_utils.h"
#include "packrect.h"
#include "imgui/imgui.h"
+#include "entry/entry.h"
+#include <bimg/decode.h>
#include <bx/rng.h>
@@ -26,17 +28,17 @@ struct PosTexcoordVertex
static void init()
{
- ms_decl
+ ms_layout
.begin()
.add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float)
.add(bgfx::Attrib::TexCoord0, 3, bgfx::AttribType::Float)
.end();
};
- static bgfx::VertexDecl ms_decl;
+ static bgfx::VertexLayout ms_layout;
};
-bgfx::VertexDecl PosTexcoordVertex::ms_decl;
+bgfx::VertexLayout PosTexcoordVertex::ms_layout;
static PosTexcoordVertex s_cubeVertices[] =
{
@@ -99,6 +101,16 @@ static const uint16_t s_cubeIndices[] =
};
BX_STATIC_ASSERT(BX_COUNTOF(s_cubeIndices) == 36);
+bx::Vec3 s_faceColors[] =
+{
+ { 0.75f, 0.0f, 0.0f },
+ { 0.75f, 0.75f, 0.0f },
+ { 0.75f, 0.0f, 0.75f },
+ { 0.0f, 0.75f, 0.0f },
+ { 0.0f, 0.75f, 0.75f },
+ { 0.0f, 0.0f, 0.75f },
+};
+
static void updateTextureCubeRectBgra8(
bgfx::TextureHandle _handle
, uint8_t _side
@@ -129,14 +141,94 @@ static void updateTextureCubeRectBgra8(
bgfx::updateTextureCube(_handle, 0, _side, 0, _x, _y, _width, _height, mem);
}
+bgfx::TextureHandle loadTextureWithUpdate(const char* _filePath, uint64_t _flags = BGFX_TEXTURE_NONE | BGFX_SAMPLER_NONE)
+{
+ bgfx::TextureHandle handle = BGFX_INVALID_HANDLE;
+
+ uint32_t size;
+ void* data = load(_filePath, &size);
+ if (NULL != data)
+ {
+ bimg::ImageContainer* imageContainer = bimg::imageParse(entry::getAllocator(), data, size);
+
+ if (NULL != imageContainer)
+ {
+ BX_ASSERT(!imageContainer->m_cubeMap, "Cubemap Texture loading not supported");
+ BX_ASSERT(1 >= imageContainer->m_depth, "3D Texture loading not supported");
+ BX_ASSERT(1 == imageContainer->m_numLayers, "Texture Layer loading not supported");
+
+ if (!imageContainer->m_cubeMap
+ && 1 >= imageContainer->m_depth
+ && 1 == imageContainer->m_numLayers
+ && bgfx::isTextureValid(0, false, imageContainer->m_numLayers, bgfx::TextureFormat::Enum(imageContainer->m_format), _flags)
+ )
+ {
+ handle = bgfx::createTexture2D(
+ uint16_t(imageContainer->m_width)
+ , uint16_t(imageContainer->m_height)
+ , 1 < imageContainer->m_numMips
+ , imageContainer->m_numLayers
+ , bgfx::TextureFormat::Enum(imageContainer->m_format)
+ , _flags
+ , NULL
+ );
+
+ const bimg::ImageBlockInfo& blockInfo = getBlockInfo(imageContainer->m_format);
+ const uint32_t blockWidth = blockInfo.blockWidth;
+ const uint32_t blockHeight = blockInfo.blockHeight;
+
+ uint32_t width = imageContainer->m_width;
+ uint32_t height = imageContainer->m_height;
+
+ for (uint8_t lod = 0, num = imageContainer->m_numMips; lod < num; ++lod)
+ {
+ width = bx::max(blockWidth, width);
+ height = bx::max(blockHeight, height);
+
+ bimg::ImageMip mip;
+
+ if (bimg::imageGetRawData(*imageContainer, 0, lod, imageContainer->m_data, imageContainer->m_size, mip))
+ {
+ const uint8_t* mipData = mip.m_data;
+ uint32_t mipDataSize = mip.m_size;
+
+ bgfx::updateTexture2D(
+ handle
+ , 0
+ , lod
+ , 0
+ , 0
+ , uint16_t(width)
+ , uint16_t(height)
+ , bgfx::copy(mipData, mipDataSize)
+ );
+ }
+
+ width >>= 1;
+ height >>= 1;
+ }
+
+ unload(data);
+ }
+
+ if (bgfx::isValid(handle))
+ {
+ bgfx::setName(handle, _filePath);
+ }
+ }
+ }
+
+ return handle;
+}
+
static const uint16_t kTextureSide = 512;
static const uint32_t kTexture2dSize = 256;
class ExampleUpdate : public entry::AppI
{
public:
- ExampleUpdate(const char* _name, const char* _description)
- : entry::AppI(_name, _description)
+ ExampleUpdate(const char* _name, const char* _description, const char* _url)
+ : entry::AppI(_name, _description, _url)
, m_cube(kTextureSide)
{
}
@@ -153,6 +245,9 @@ 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.platformData.type = entry::getNativeWindowHandleType(entry::kDefaultWindowHandle);
init.resolution.width = m_width;
init.resolution.height = m_height;
init.resolution.reset = m_reset;
@@ -169,6 +264,8 @@ public:
, 0
);
+ m_showDescriptions = true;
+
// Create vertex stream declaration.
PosTexcoordVertex::init();
@@ -184,7 +281,21 @@ public:
m_textures[ 9] = loadTexture("textures/texture_compression_atc.dds");
m_textures[10] = loadTexture("textures/texture_compression_atci.dds");
m_textures[11] = loadTexture("textures/texture_compression_atce.dds");
- BX_STATIC_ASSERT(12 == BX_COUNTOF(m_textures));
+
+ m_textures[12] = loadTextureWithUpdate("textures/texture_compression_bc1.ktx", BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP);
+ m_textures[13] = loadTextureWithUpdate("textures/texture_compression_bc2.ktx", BGFX_SAMPLER_U_CLAMP);
+ m_textures[14] = loadTextureWithUpdate("textures/texture_compression_bc3.ktx", BGFX_SAMPLER_V_CLAMP);
+ m_textures[15] = loadTextureWithUpdate("textures/texture_compression_etc1.ktx", BGFX_SAMPLER_U_BORDER | BGFX_SAMPLER_V_BORDER | BGFX_SAMPLER_BORDER_COLOR(1));
+ m_textures[16] = loadTextureWithUpdate("textures/texture_compression_etc2.ktx");
+ m_textures[17] = loadTextureWithUpdate("textures/texture_compression_ptc12.pvr");
+ m_textures[18] = loadTextureWithUpdate("textures/texture_compression_ptc14.pvr");
+ m_textures[19] = loadTextureWithUpdate("textures/texture_compression_ptc22.pvr");
+ m_textures[20] = loadTextureWithUpdate("textures/texture_compression_ptc24.pvr");
+ m_textures[21] = loadTextureWithUpdate("textures/texture_compression_atc.dds");
+ m_textures[22] = loadTextureWithUpdate("textures/texture_compression_atci.dds");
+ m_textures[23] = loadTextureWithUpdate("textures/texture_compression_atce.dds");
+
+ BX_STATIC_ASSERT(24 == BX_COUNTOF(m_textures));
const bgfx::Caps* caps = bgfx::getCaps();
m_texture3DSupported = !!(caps->supported & BGFX_CAPS_TEXTURE_3D);
@@ -229,29 +340,31 @@ public:
}
// Create static vertex buffer.
- m_vbh = bgfx::createVertexBuffer(bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) ), PosTexcoordVertex::ms_decl);
+ m_vbh = bgfx::createVertexBuffer(bgfx::makeRef(s_cubeVertices, sizeof(s_cubeVertices) ), PosTexcoordVertex::ms_layout);
// Create static index buffer.
m_ibh = bgfx::createIndexBuffer(bgfx::makeRef(s_cubeIndices, sizeof(s_cubeIndices) ) );
// Create programs.
- m_program = loadProgram("vs_update", "fs_update");
- m_programCmp = loadProgram("vs_update", "fs_update_cmp");
+ m_program = loadProgram("vs_update", "fs_update");
+ m_programCmp = loadProgram("vs_update", "fs_update_cmp");
m_program3d.idx = bgfx::kInvalidHandle;
+
if (m_texture3DSupported)
{
m_program3d = loadProgram("vs_update", "fs_update_3d");
}
m_programCompute.idx = bgfx::kInvalidHandle;
+
if (m_computeSupported)
{
m_programCompute = bgfx::createProgram( loadShader( "cs_update" ), true );
}
// Create texture sampler uniforms.
- s_texCube = bgfx::createUniform("s_texCube", bgfx::UniformType::Int1);
- s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Int1);
+ s_texCube = bgfx::createUniform("s_texCube", bgfx::UniformType::Sampler);
+ s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Sampler);
// Create time uniform.
u_time = bgfx::createUniform("u_time", bgfx::UniformType::Vec4);
@@ -291,6 +404,17 @@ public:
);
}
+ {
+ m_textureCube[3] = bgfx::createTextureCube(kTextureSide, false, 1, bgfx::TextureFormat::BGRA8, BGFX_TEXTURE_RT);
+
+ for (uint32_t ii = 0; ii < BX_COUNTOF(m_textureCubeFaceFb); ++ii)
+ {
+ bgfx::Attachment at;
+ at.init(m_textureCube[3], bgfx::Access::Write, uint16_t(ii));
+ m_textureCubeFaceFb[ii] = bgfx::createFrameBuffer(1, &at);
+ }
+ }
+
m_texture2d = bgfx::createTexture2D(
kTexture2dSize
, kTexture2dSize
@@ -302,6 +426,16 @@ public:
m_texture2dData = (uint8_t*)malloc(kTexture2dSize*kTexture2dSize*4);
+ if (m_blitSupported)
+ {
+ m_blitTestA = bgfx::createTexture2D(16, 16, false, 1, bgfx::TextureFormat::Enum::RGBA8, BGFX_TEXTURE_BLIT_DST);
+ m_blitTestB = bgfx::createTexture2D(16, 16, false, 1, bgfx::TextureFormat::Enum::RGBA8, BGFX_TEXTURE_BLIT_DST);
+ m_blitTestC = bgfx::createTexture2D(16, 16, false, 1, bgfx::TextureFormat::Enum::RGBA8, BGFX_TEXTURE_BLIT_DST);
+ bgfx::setName(m_blitTestA, "Blit A");
+ bgfx::setName(m_blitTestB, "Blit B");
+ bgfx::setName(m_blitTestC, "Blit C");
+ }
+
m_rr = m_rng.gen()%255;
m_gg = m_rng.gen()%255;
m_bb = m_rng.gen()%255;
@@ -327,6 +461,13 @@ public:
// Cleanup.
free(m_texture2dData);
+ if (m_blitSupported)
+ {
+ bgfx::destroy(m_blitTestA);
+ bgfx::destroy(m_blitTestB);
+ bgfx::destroy(m_blitTestC);
+ }
+
for (uint32_t ii = 0; ii < BX_COUNTOF(m_textures); ++ii)
{
bgfx::destroy(m_textures[ii]);
@@ -339,7 +480,7 @@ public:
bgfx::destroy(m_texture2d);
- for (uint32_t ii = 0; ii<BX_COUNTOF(m_textureCube); ++ii)
+ for (uint32_t ii = 0; ii < BX_COUNTOF(m_textureCube); ++ii)
{
if (bgfx::isValid(m_textureCube[ii]))
{
@@ -347,17 +488,29 @@ public:
}
}
+ for (uint32_t ii = 0; ii < BX_COUNTOF(m_textureCubeFaceFb); ++ii)
+ {
+ if (bgfx::isValid(m_textureCubeFaceFb[ii]))
+ {
+ bgfx::destroy(m_textureCubeFaceFb[ii]);
+ }
+ }
+
bgfx::destroy(m_ibh);
bgfx::destroy(m_vbh);
+
if (bgfx::isValid(m_program3d) )
{
bgfx::destroy(m_program3d);
}
+
bgfx::destroy(m_programCmp);
+
if (bgfx::isValid(m_programCompute) )
{
bgfx::destroy(m_programCompute);
}
+
bgfx::destroy(m_program);
bgfx::destroy(u_time);
bgfx::destroy(s_texColor);
@@ -369,6 +522,25 @@ public:
return 0;
}
+ void ImGuiDescription(float _x, float _y, float _z, const float* _worldToScreen, const char* _text)
+ {
+ if (m_showDescriptions)
+ {
+ float worldPos[4] = { _x, _y, _z, 1.0f };
+ float screenPos[4];
+
+ bx::vec4MulMtx(screenPos, worldPos, _worldToScreen);
+
+ ImGui::SetNextWindowPos(ImVec2(screenPos[0] / screenPos[3], screenPos[1] / screenPos[3]), 0, ImVec2(0.5f, 0.5f));
+ ImGuiWindowFlags flags = ImGuiWindowFlags_NoInputs | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_AlwaysAutoResize;
+ ImGui::SetNextWindowBgAlpha(0.5f);
+
+ ImGui::Begin(_text, NULL, flags);
+ ImGui::Text("%s", _text);
+ ImGui::End();
+ }
+ }
+
bool update() override
{
if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) )
@@ -385,7 +557,21 @@ public:
showExampleDialog(this);
- imguiEndFrame();
+ ImGui::SetNextWindowPos (ImVec2( 10.0f, 270.0f), ImGuiCond_FirstUseEver);
+ ImGui::SetNextWindowSize(ImVec2(150.0f, 70.0f), ImGuiCond_FirstUseEver);
+
+ ImGui::Begin(
+ "Show descriptions"
+ , NULL
+ , ImGuiWindowFlags_NoResize
+ );
+
+ if (ImGui::Button(m_showDescriptions ? "On" : "Off"))
+ {
+ m_showDescriptions = !m_showDescriptions;
+ }
+
+ ImGui::End();
float borderColor[4] =
{
@@ -425,7 +611,21 @@ public:
updateTextureCubeRectBgra8(m_textureCube[0], face.m_side, rect.m_x, rect.m_y, rect.m_width, rect.m_height, m_rr, m_gg, m_bb);
if (m_blitSupported)
{
- bgfx::blit(0, m_textureCube[1], 0, rect.m_x, rect.m_y, face.m_side, m_textureCube[0], 0, rect.m_x, rect.m_y, face.m_side, rect.m_width, rect.m_height);
+ bgfx::blit(
+ 0
+ , m_textureCube[1]
+ , 0
+ , rect.m_x
+ , rect.m_y
+ , face.m_side
+ , m_textureCube[0]
+ , 0
+ , rect.m_x
+ , rect.m_y
+ , face.m_side
+ , rect.m_width
+ , rect.m_height
+ );
}
m_rr = m_rng.gen()%255;
@@ -444,7 +644,21 @@ public:
updateTextureCubeRectBgra8(m_textureCube[0], face.m_side, rect.m_x, rect.m_y, rect.m_width, rect.m_height, 0, 0, 0);
if (m_blitSupported)
{
- bgfx::blit(0, m_textureCube[1], 0, rect.m_x, rect.m_y, face.m_side, m_textureCube[0], 0, rect.m_x, rect.m_y, face.m_side, rect.m_width, rect.m_height);
+ bgfx::blit(
+ 0
+ , m_textureCube[1]
+ , 0
+ , rect.m_x
+ , rect.m_y
+ , face.m_side
+ , m_textureCube[0]
+ , 0
+ , rect.m_x
+ , rect.m_y
+ , face.m_side
+ , rect.m_width
+ , rect.m_height
+ );
}
m_cube.clear(face);
@@ -496,6 +710,15 @@ public:
// Set view and projection matrix for view 0.
bgfx::setViewTransform(0, view, proj);
+ float projToScreen[16];
+ bx::mtxSRT(projToScreen, float(m_width) * 0.5f, -float(m_height) * 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, float(m_width) * 0.5f, float(m_height) * 0.5f, 0.0f);
+
+ float viewProj[16];
+ bx::mtxMul(viewProj, view, proj);
+
+ float worldToScreen[16];
+ bx::mtxMul(worldToScreen, viewProj, projToScreen);
+
// Update texturecube using compute shader
if (bgfx::isValid(m_programCompute) )
{
@@ -503,12 +726,39 @@ public:
bgfx::dispatch(0, m_programCompute, kTextureSide/16, kTextureSide/16);
}
+ for (uint32_t ii = 0; ii < BX_COUNTOF(m_textureCubeFaceFb); ++ii)
+ {
+ bgfx::ViewId viewId = bgfx::ViewId(ii+2);
+ bgfx::setViewFrameBuffer(viewId, m_textureCubeFaceFb[ii]);
+
+ bx::Vec3 color = bx::add(s_faceColors[ii], bx::sin(time*4.0f)*0.25f);
+ uint32_t colorRGB8 = 0
+ | uint32_t(bx::toUnorm(color.x, 255.0f) ) << 24
+ | uint32_t(bx::toUnorm(color.y, 255.0f) ) << 16
+ | uint32_t(bx::toUnorm(color.z, 255.0f) ) << 8
+ ;
+
+ bgfx::setViewClear(viewId, BGFX_CLEAR_COLOR, colorRGB8);
+ bgfx::setViewRect(viewId, 0,0,512,512);
+
+ bgfx::touch(viewId);
+ }
+
+ static const char* descTextureCube[BX_COUNTOF(m_textureCube)] =
+ {
+ "updateTextureCube",
+ "blit",
+ "compute",
+ "frameBuffer",
+ };
+ BX_STATIC_ASSERT(BX_COUNTOF(descTextureCube) == BX_COUNTOF(m_textureCube));
+
for (uint32_t ii = 0; ii < BX_COUNTOF(m_textureCube); ++ii)
{
if (bgfx::isValid(m_textureCube[ii]))
{
float mtx[16];
- bx::mtxSRT(mtx, 0.7f, 0.7f, 0.7f, time, time*0.37f, 0.0f, -2.0f +ii*2.0f, 0.0f, 0.0f);
+ bx::mtxSRT(mtx, 0.65f, 0.65f, 0.65f, time, time*0.37f, 0.0f, -2.5f +ii*1.8f, 0.0f, 0.0f);
// Set model matrix for rendering.
bgfx::setTransform(mtx);
@@ -525,19 +775,25 @@ public:
// Submit primitive for rendering to view 0.
bgfx::submit(0, m_program);
+
+ ImGuiDescription(mtx[12], mtx[13], mtx[14], worldToScreen, descTextureCube[ii]);
}
}
// Set view and projection matrix for view 1.
+ const uint32_t numColumns = BX_COUNTOF(m_textures) / 2;
+
const float aspectRatio = float(m_height)/float(m_width);
const float margin = 0.7f;
- const float sizeX = 0.5f * BX_COUNTOF(m_textures) * 2.1f + margin;
+ const float sizeX = 0.5f * numColumns * 2.3f + margin;
const float sizeY = sizeX * aspectRatio;
const bgfx::Caps* caps = bgfx::getCaps();
bx::mtxOrtho(proj, -sizeX, sizeX, sizeY, -sizeY, 0.0f, 1000.0f, 0.0f, caps->homogeneousDepth);
bgfx::setViewTransform(1, NULL, proj);
+ bx::mtxMul(worldToScreen, proj, projToScreen);
+
float mtx[16];
bx::mtxTranslate(mtx, -sizeX + margin + 1.0f, 1.9f, 0.0f);
@@ -557,11 +813,42 @@ public:
// Submit primitive for rendering to view 1.
bgfx::submit(1, m_programCmp);
+ ImGuiDescription(mtx[12], mtx[13], mtx[14], worldToScreen, "updateTexture2D");
+
const float xpos = -sizeX + margin + 1.0f;
+ static const char* descTextures[] =
+ {
+ "create\nbc1",
+ "create\nbc2",
+ "create\nbc3",
+ "create\netc1",
+ "create\netc2",
+ "create\nptc12",
+ "create\nptc14",
+ "create\nptc22",
+ "create\nptc24",
+ "create\natc",
+ "create\natci",
+ "create\natce",
+ "update\nbc1",
+ "update\nbc2",
+ "update\nbc3",
+ "update\netc1",
+ "update\netc2",
+ "update\nptc12",
+ "update\nptc14",
+ "update\nptc22",
+ "update\nptc24",
+ "update\natc",
+ "update\natci",
+ "update\natce",
+ };
+ BX_STATIC_ASSERT(BX_COUNTOF(descTextures) == BX_COUNTOF(m_textures));
+
for (uint32_t ii = 0; ii < BX_COUNTOF(m_textures); ++ii)
{
- bx::mtxTranslate(mtx, xpos + ii*2.1f, sizeY - margin - 1.0f, 0.0f);
+ bx::mtxTranslate(mtx, xpos + (ii%numColumns) * 2.3f, sizeY - margin - 2.8f + (ii/numColumns) * 2.3f, 0.0f);
// Set model matrix for rendering.
bgfx::setTransform(mtx);
@@ -578,11 +865,21 @@ public:
// Submit primitive for rendering to view 1.
bgfx::submit(1, m_programCmp);
+
+ ImGuiDescription(mtx[12], mtx[13], mtx[14], worldToScreen, descTextures[ii]);
}
+ static const char* descTextures3d[] =
+ {
+ "Tex3D R8",
+ "Tex3D R16F",
+ "Tex3D R32F",
+ };
+ BX_STATIC_ASSERT(BX_COUNTOF(descTextures3d) == BX_COUNTOF(m_textures3d));
+
for (uint32_t ii = 0; ii < m_numTextures3d; ++ii)
{
- bx::mtxTranslate(mtx, xpos + (ii+(BX_COUNTOF(m_textures) - m_numTextures3d)*0.5f)*2.1f, -sizeY + margin + 1.0f, 0.0f);
+ bx::mtxTranslate(mtx, xpos + (ii+(numColumns - m_numTextures3d)*0.5f)*2.3f, -sizeY + margin + 1.0f, 0.0f);
// Set model matrix for rendering.
bgfx::setTransform(mtx);
@@ -599,9 +896,20 @@ public:
// Submit primitive for rendering to view 1.
bgfx::submit(1, m_program3d);
+
+ ImGuiDescription(mtx[12], mtx[13], mtx[14], worldToScreen, descTextures3d[ii]);
}
- for (uint32_t ii = 0; ii < 4; ++ii)
+ static const char* descSampler[] =
+ {
+ "U_CLAMP\nV_CLAMP",
+ "U_CLAMP\nV_WRAP",
+ "U_WRAP\nV_CLAMP",
+ "U_BORDER\nV_BORDER",
+ "U_WRAP\nV_WRAP",
+ };
+
+ for (uint32_t ii = 0; ii < 5; ++ii)
{
bx::mtxTranslate(mtx, sizeX - margin - 1.0f, -sizeY + margin + 1.0f + ii*2.1f, 0.0f);
@@ -620,8 +928,27 @@ public:
// Submit primitive for rendering to view 1.
bgfx::submit(1, m_programCmp);
+
+ ImGuiDescription(mtx[12], mtx[13], mtx[14], worldToScreen, descSampler[ii]);
}
+ if (m_blitSupported)
+ {
+ bgfx::blit(1, m_blitTestA, 0, 0, m_blitTestB, 0, 0);
+ bgfx::blit(1, m_blitTestC, 0, 0, m_blitTestA, 0, 0);
+
+ bgfx::blit(1, m_blitTestA, 0, 0, m_blitTestB, 0, 0);
+ bgfx::blit(1, m_blitTestB, 0, 0, m_blitTestC, 0, 0);
+
+ bgfx::blit(1, m_blitTestA, 0, 0, m_blitTestB, 0, 0);
+ bgfx::blit(1, m_blitTestB, 0, 0, m_blitTestA, 0, 0);
+
+ bgfx::blit(1, m_blitTestB, 0, 0, m_blitTestA, 0, 0);
+ bgfx::blit(1, m_blitTestC, 0, 0, m_blitTestB, 0, 0);
+ }
+
+ imguiEndFrame();
+
// Advance to next frame. Rendering thread will be kicked to
// process submitted rendering primitives.
bgfx::frame();
@@ -644,6 +971,7 @@ public:
bool m_texture3DSupported;
bool m_blitSupported;
bool m_computeSupported;
+ bool m_showDescriptions;
std::list<PackCube> m_quads;
RectPackCubeT<256> m_cube;
@@ -658,10 +986,14 @@ public:
uint8_t m_gg;
uint8_t m_bb;
- bgfx::TextureHandle m_textures[12];
+ bgfx::TextureHandle m_textures[24];
bgfx::TextureHandle m_textures3d[3];
bgfx::TextureHandle m_texture2d;
- bgfx::TextureHandle m_textureCube[3];
+ bgfx::TextureHandle m_textureCube[4];
+ bgfx::TextureHandle m_blitTestA;
+ bgfx::TextureHandle m_blitTestB;
+ bgfx::TextureHandle m_blitTestC;
+ bgfx::FrameBufferHandle m_textureCubeFaceFb[6];
bgfx::IndexBufferHandle m_ibh;
bgfx::VertexBufferHandle m_vbh;
bgfx::ProgramHandle m_program3d;
@@ -676,4 +1008,9 @@ public:
} // namespace
-ENTRY_IMPLEMENT_MAIN(ExampleUpdate, "08-update", "Updating textures.");
+ENTRY_IMPLEMENT_MAIN(
+ ExampleUpdate
+ , "08-update"
+ , "Updating textures."
+ , "https://bkaradzic.github.io/bgfx/examples.html#update"
+ );
diff --git a/3rdparty/bgfx/examples/08-update/vs_update.sc b/3rdparty/bgfx/examples/08-update/vs_update.sc
index 8c3b7a822b6..545369275d5 100644
--- a/3rdparty/bgfx/examples/08-update/vs_update.sc
+++ b/3rdparty/bgfx/examples/08-update/vs_update.sc
@@ -2,8 +2,8 @@ $input a_position, a_texcoord0
$output v_texcoord0
/*
- * Copyright 2011-2018 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 "../common/common.sh"