Combined all examples. Issue #1143.

This commit is contained in:
Branimir Karadžić
2017-06-25 21:44:04 -07:00
parent d89a4e0346
commit 5f666a5ee2
38 changed files with 1301 additions and 755 deletions

View File

@@ -5,6 +5,10 @@
#include "common.h"
#include "bgfx_utils.h"
#include "imgui/imgui.h"
namespace
{
struct PosNormalTangentTexcoordVertex
{
@@ -80,13 +84,19 @@ static const uint16_t s_cubeIndices[36] =
class ExampleBump : public entry::AppI
{
public:
ExampleBump(const char* _name, const char* _description)
: entry::AppI(_name, _description)
{
}
void init(int _argc, char** _argv) BX_OVERRIDE
{
Args args(_argc, _argv);
m_width = 1280;
m_height = 720;
m_debug = BGFX_DEBUG_TEXT;
m_debug = BGFX_DEBUG_NONE;
m_reset = BGFX_RESET_VSYNC;
bgfx::init(args.m_type, args.m_pciId);
@@ -144,10 +154,14 @@ class ExampleBump : public entry::AppI
m_textureNormal = loadTexture("textures/fieldstone-n.dds");
m_timeOffset = bx::getHPCounter();
imguiCreate();
}
virtual int shutdown() BX_OVERRIDE
{
imguiDestroy();
// Cleanup.
bgfx::destroyIndexBuffer(m_ibh);
bgfx::destroyVertexBuffer(m_vbh);
@@ -167,8 +181,22 @@ class ExampleBump : public entry::AppI
bool update() BX_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)
);
bool restart = showExampleDialog(this);
imguiEndFrame();
// Set view 0 default viewport.
bgfx::setViewRect(0, 0, 0, uint16_t(m_width), uint16_t(m_height) );
@@ -176,20 +204,7 @@ class ExampleBump : public entry::AppI
// if no other draw calls are submitted to view 0.
bgfx::touch(0);
int64_t now = bx::getHPCounter();
static int64_t last = now;
const int64_t frameTime = now - last;
last = now;
const double freq = double(bx::getHPFrequency() );
const double toMs = 1000.0/freq;
float time = (float)( (now-m_timeOffset)/freq);
// Use debug font to print information about this example.
bgfx::dbgTextClear();
bgfx::dbgTextPrintf(0, 1, 0x4f, "bgfx/examples/06-bump");
bgfx::dbgTextPrintf(0, 2, 0x6f, "Description: Loading textures.");
bgfx::dbgTextPrintf(0, 3, 0x0f, "Frame: % 7.3f[ms]", double(frameTime)*toMs);
float time = (float)( (bx::getHPCounter()-m_timeOffset)/double(bx::getHPFrequency() ));
float at[3] = { 0.0f, 0.0f, 0.0f };
float eye[3] = { 0.0f, 0.0f, -7.0f };
@@ -333,12 +348,14 @@ class ExampleBump : public entry::AppI
// process submitted rendering primitives.
bgfx::frame();
return true;
return !restart;
}
return false;
}
entry::MouseState m_mouseState;
bgfx::VertexBufferHandle m_vbh;
bgfx::IndexBufferHandle m_ibh;
bgfx::UniformHandle s_texColor;
@@ -358,4 +375,6 @@ class ExampleBump : public entry::AppI
int64_t m_timeOffset;
};
ENTRY_IMPLEMENT_MAIN(ExampleBump);
} // namespace
ENTRY_IMPLEMENT_MAIN(ExampleBump, "06-bump", "Description: Loading textures.");