summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/08-update/update.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/examples/08-update/update.cpp')
-rw-r--r--3rdparty/bgfx/examples/08-update/update.cpp112
1 files changed, 63 insertions, 49 deletions
diff --git a/3rdparty/bgfx/examples/08-update/update.cpp b/3rdparty/bgfx/examples/08-update/update.cpp
index 9bb3af0e465..789b2a038ea 100644
--- a/3rdparty/bgfx/examples/08-update/update.cpp
+++ b/3rdparty/bgfx/examples/08-update/update.cpp
@@ -5,12 +5,15 @@
#include "common.h"
#include "bgfx_utils.h"
-
-#include <bx/uint32_t.h>
#include "packrect.h"
+#include "imgui/imgui.h"
+#include <bx/uint32_t.h>
#include <list>
+namespace
+{
+
struct PosTexcoordVertex
{
float m_x;
@@ -118,18 +121,19 @@ static const uint32_t texture2dSize = 256;
class ExampleUpdate : public entry::AppI
{
public:
- ExampleUpdate()
- : m_cube(textureside)
+ ExampleUpdate(const char* _name, const char* _description)
+ : entry::AppI(_name, _description)
+ , m_cube(textureside)
{
}
- void init(int _argc, char** _argv) BX_OVERRIDE
+ void init(int32_t _argc, const char* const* _argv, uint32_t _width, uint32_t _height) override
{
Args args(_argc, _argv);
- m_width = 1280;
- m_height = 720;
- m_debug = BGFX_DEBUG_TEXT;
+ m_width = _width;
+ m_height = _height;
+ m_debug = BGFX_DEBUG_NONE;
m_reset = BGFX_RESET_VSYNC;
bgfx::init(args.m_type, args.m_pciId);
@@ -210,13 +214,13 @@ public:
// Create programs.
m_program = loadProgram("vs_update", "fs_update");
m_programCmp = loadProgram("vs_update", "fs_update_cmp");
- m_program3d.idx = bgfx::invalidHandle;
+ m_program3d.idx = bgfx::kInvalidHandle;
if (m_texture3DSupported)
{
m_program3d = loadProgram("vs_update", "fs_update_3d");
}
- m_programCompute.idx = bgfx::invalidHandle;
+ m_programCompute.idx = bgfx::kInvalidHandle;
if (m_computeSupported)
{
m_programCompute = bgfx::createProgram( loadShader( "cs_update" ), true );
@@ -231,7 +235,7 @@ public:
for(uint32_t ii = 0; ii<BX_COUNTOF( m_textureCube ); ++ii)
{
- m_textureCube[ii].idx = bgfx::invalidHandle;
+ m_textureCube[ii].idx = bgfx::kInvalidHandle;
}
m_textureCube[0] = bgfx::createTextureCube(
@@ -256,7 +260,7 @@ public:
if (m_computeSupported)
{
m_textureCube[2] = bgfx::createTextureCube(
- textureside
+ textureside
, false
, 1
, bgfx::TextureFormat::RGBA8
@@ -284,10 +288,14 @@ public:
m_updateTime = 0;
m_timeOffset = bx::getHPCounter();
+
+ imguiCreate();
}
- virtual int shutdown() BX_OVERRIDE
+ virtual int shutdown() override
{
+ imguiDestroy();
+
// m_texture2dData is managed from main thread, and it's passed to renderer
// just as MemoryRef. At this point render might be using it. We must wait
// previous frame to finish before we can free it.
@@ -298,39 +306,39 @@ public:
for (uint32_t ii = 0; ii < BX_COUNTOF(m_textures); ++ii)
{
- bgfx::destroyTexture(m_textures[ii]);
+ bgfx::destroy(m_textures[ii]);
}
for (uint32_t ii = 0; ii < m_numTextures3d; ++ii)
{
- bgfx::destroyTexture(m_textures3d[ii]);
+ bgfx::destroy(m_textures3d[ii]);
}
- bgfx::destroyTexture(m_texture2d);
+ bgfx::destroy(m_texture2d);
for (uint32_t ii = 0; ii<BX_COUNTOF(m_textureCube); ++ii)
{
if (bgfx::isValid(m_textureCube[ii]))
{
- bgfx::destroyTexture(m_textureCube[ii]);
+ bgfx::destroy(m_textureCube[ii]);
}
}
- bgfx::destroyIndexBuffer(m_ibh);
- bgfx::destroyVertexBuffer(m_vbh);
+ bgfx::destroy(m_ibh);
+ bgfx::destroy(m_vbh);
if (bgfx::isValid(m_program3d) )
{
- bgfx::destroyProgram(m_program3d);
+ bgfx::destroy(m_program3d);
}
- bgfx::destroyProgram(m_programCmp);
+ bgfx::destroy(m_programCmp);
if (bgfx::isValid(m_programCompute) )
{
- bgfx::destroyProgram(m_programCompute);
+ bgfx::destroy(m_programCompute);
}
- bgfx::destroyProgram(m_program);
- bgfx::destroyUniform(u_time);
- bgfx::destroyUniform(s_texColor);
- bgfx::destroyUniform(s_texCube);
+ bgfx::destroy(m_program);
+ bgfx::destroy(u_time);
+ bgfx::destroy(s_texColor);
+ bgfx::destroy(s_texCube);
// Shutdown bgfx.
bgfx::shutdown();
@@ -338,10 +346,24 @@ public:
return 0;
}
- bool update() BX_OVERRIDE
+ bool update() override
{
- if (!entry::processEvents(m_width, m_height, m_debug, m_reset) )
+ if (!entry::processEvents(m_width, m_height, m_debug, m_reset, &m_mouseState) )
{
+ imguiBeginFrame(m_mouseState.m_mx
+ , m_mouseState.m_my
+ , (m_mouseState.m_buttons[entry::MouseButton::Left ] ? IMGUI_MBUT_LEFT : 0)
+ | (m_mouseState.m_buttons[entry::MouseButton::Right ] ? IMGUI_MBUT_RIGHT : 0)
+ | (m_mouseState.m_buttons[entry::MouseButton::Middle] ? IMGUI_MBUT_MIDDLE : 0)
+ , m_mouseState.m_mz
+ , uint16_t(m_width)
+ , uint16_t(m_height)
+ );
+
+ showExampleDialog(this);
+
+ imguiEndFrame();
+
float borderColor[4] = { float(rand()%255)/255.0f, float(rand()%255)/255.0f, float(rand()%255)/255.0f, float(rand()%255)/255.0f };
bgfx::setPaletteColor(1, borderColor);
@@ -354,20 +376,9 @@ public:
bgfx::touch(0);
int64_t now = bx::getHPCounter();
- static int64_t last = now;
- const int64_t frameTime = now - last;
- last = now;
- const int64_t freq = bx::getHPFrequency();
- const double toMs = 1000.0/double(freq);
float time = (float)( (now - m_timeOffset)/double(bx::getHPFrequency() ) );
bgfx::setUniform(u_time, &time);
- // Use debug font to print information about this example.
- bgfx::dbgTextClear();
- bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/08-update");
- bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Updating m_textures.");
- bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);
-
if (now > m_updateTime)
{
PackCube face;
@@ -444,8 +455,6 @@ public:
}
}
- bgfx::dbgTextPrintf(0, 4, 0x0f, "m_hit: %d, m_miss %d", m_hit, m_miss);
-
float at[3] = { 0.0f, 0.0f, 0.0f };
float eye[3] = { 0.0f, 0.0f, -5.0f };
@@ -475,7 +484,7 @@ public:
bgfx::setTransform( mtx );
// Set vertex and index buffer.
- bgfx::setVertexBuffer( m_vbh );
+ bgfx::setVertexBuffer(0, m_vbh );
bgfx::setIndexBuffer( m_ibh );
// Bind texture.
@@ -492,7 +501,8 @@ public:
// Set view and projection matrix for view 1.
const float aspectRatio = float(m_height)/float(m_width);
const float size = 11.0f;
- bx::mtxOrtho(proj, -size, size, size*aspectRatio, -size*aspectRatio, 0.0f, 1000.0f);
+ const bgfx::Caps* caps = bgfx::getCaps();
+ bx::mtxOrtho(proj, -size, size, size*aspectRatio, -size*aspectRatio, 0.0f, 1000.0f, 0.0f, caps->homogeneousDepth);
bgfx::setViewTransform(1, NULL, proj);
float mtx[16];
@@ -502,7 +512,7 @@ public:
bgfx::setTransform(mtx);
// Set vertex and index buffer.
- bgfx::setVertexBuffer(m_vbh);
+ bgfx::setVertexBuffer(0, m_vbh);
bgfx::setIndexBuffer(m_ibh);
// Bind texture.
@@ -524,7 +534,7 @@ public:
bgfx::setTransform(mtx);
// Set vertex and index buffer.
- bgfx::setVertexBuffer(m_vbh);
+ bgfx::setVertexBuffer(0, m_vbh);
bgfx::setIndexBuffer(m_ibh, 0, 6);
// Bind texture.
@@ -545,7 +555,7 @@ public:
bgfx::setTransform(mtx);
// Set vertex and index buffer.
- bgfx::setVertexBuffer(m_vbh);
+ bgfx::setVertexBuffer(0, m_vbh);
bgfx::setIndexBuffer(m_ibh, 0, 6);
// Bind texture.
@@ -566,7 +576,7 @@ public:
bgfx::setTransform(mtx);
// Set vertex and index buffer.
- bgfx::setVertexBuffer(m_vbh, 24, 4);
+ bgfx::setVertexBuffer(0, m_vbh, 24, 4);
bgfx::setIndexBuffer(m_ibh, 0, 6);
// Bind texture.
@@ -582,19 +592,21 @@ public:
// Advance to next frame. Rendering thread will be kicked to
// process submitted rendering primitives.
bgfx::frame();
+
return true;
}
return false;
}
- uint8_t* m_texture2dData;
+ entry::MouseState m_mouseState;
uint32_t m_width;
uint32_t m_height;
uint32_t m_debug;
uint32_t m_reset;
+ uint8_t* m_texture2dData;
uint32_t m_numTextures3d;
bool m_texture3DSupported;
bool m_blitSupported;
@@ -628,4 +640,6 @@ public:
};
-ENTRY_IMPLEMENT_MAIN(ExampleUpdate);
+} // namespace
+
+ENTRY_IMPLEMENT_MAIN(ExampleUpdate, "08-update", "Updating textures.");