Moved showExampleDialog to separate library to decouple entry and imgui.
This commit is contained in:
parent
9e737f705d
commit
b12ce15a82
88
examples/common/example-glue.cpp
Normal file
88
examples/common/example-glue.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2011-2017 Branimir Karadzic. All rights reserved.
|
||||
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
||||
*/
|
||||
|
||||
#include "imgui/imgui.h"
|
||||
#include "entry/entry.h"
|
||||
|
||||
bool showExampleDialog(entry::AppI* _app)
|
||||
{
|
||||
bool restart = false;
|
||||
|
||||
char temp[1024];
|
||||
bx::snprintf(temp, BX_COUNTOF(temp), "Example: %s", _app->getName() );
|
||||
|
||||
ImGui::Begin(temp
|
||||
, NULL
|
||||
, ImVec2(256.0f, 200.0f)
|
||||
, ImGuiWindowFlags_AlwaysAutoResize
|
||||
);
|
||||
|
||||
ImGui::TextWrapped("%s", _app->getDescription() );
|
||||
ImGui::Separator();
|
||||
|
||||
{
|
||||
uint32_t num = entry::getNumApps();
|
||||
const char** items = (const char**)alloca(num*sizeof(void*) );
|
||||
|
||||
uint32_t ii = 0;
|
||||
int32_t current = 0;
|
||||
for (entry::AppI* app = entry::getFirstApp(); NULL != app; app = app->getNext() )
|
||||
{
|
||||
if (app == _app)
|
||||
{
|
||||
current = ii;
|
||||
}
|
||||
|
||||
items[ii++] = app->getName();
|
||||
}
|
||||
|
||||
if (1 < num
|
||||
&& ImGui::Combo("Example", ¤t, items, num) )
|
||||
{
|
||||
entry::setRestartArgs(items[current]);
|
||||
restart = true;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
{
|
||||
bgfx::RendererType::Enum supportedRenderers[bgfx::RendererType::Count];
|
||||
uint8_t num = bgfx::getSupportedRenderers(BX_COUNTOF(supportedRenderers), supportedRenderers);
|
||||
|
||||
const bgfx::Caps* caps = bgfx::getCaps();
|
||||
|
||||
const char* items[bgfx::RendererType::Count];
|
||||
|
||||
int32_t current = 0;
|
||||
for (uint8_t ii = 0; ii < num; ++ii)
|
||||
{
|
||||
items[ii] = bgfx::getRendererName(supportedRenderers[ii]);
|
||||
if (supportedRenderers[ii] == caps->rendererType)
|
||||
{
|
||||
current = ii;
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::Combo("Renderer", ¤t, items, num) )
|
||||
{
|
||||
restart = true;
|
||||
}
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
const bgfx::Stats* stats = bgfx::getStats();
|
||||
ImGui::Text("CPU %0.3f"
|
||||
, double(stats->cpuTimeEnd-stats->cpuTimeBegin)/stats->cpuTimerFreq*1000.0
|
||||
);
|
||||
|
||||
ImGui::Text("GPU %0.3f (latency: %d)"
|
||||
, double(stats->gpuTimeEnd-stats->gpuTimeBegin)/stats->gpuTimerFreq*1000.0
|
||||
, stats->maxGpuLatency
|
||||
);
|
||||
|
||||
ImGui::End();
|
||||
|
||||
return restart;
|
||||
}
|
@ -34,7 +34,6 @@
|
||||
#include "ocornut_imgui.h"
|
||||
#include "../bgfx_utils.h"
|
||||
#include "../nanovg/nanovg.h"
|
||||
#include "../entry/entry.h"
|
||||
|
||||
#include <bgfx/embedded_shader.h>
|
||||
|
||||
@ -3310,98 +3309,3 @@ bgfx::ProgramHandle imguiGetImageProgram(uint8_t _mip)
|
||||
bgfx::setUniform(s_imgui.u_imageLodEnabled, lodEnabled);
|
||||
return s_imgui.m_imageProgram;
|
||||
}
|
||||
|
||||
static const char* s_rendererNames[] =
|
||||
{
|
||||
"Noop",
|
||||
"Direct3D9",
|
||||
"Direct3D11",
|
||||
"Direct3D12",
|
||||
"Gnm",
|
||||
"Metal",
|
||||
"OpenGLES",
|
||||
"OpenGL",
|
||||
"Vulkan",
|
||||
};
|
||||
BX_STATIC_ASSERT(bgfx::RendererType::Count == BX_COUNTOF(s_rendererNames) );
|
||||
|
||||
bool showExampleDialog(entry::AppI* _app)
|
||||
{
|
||||
bool restart = false;
|
||||
|
||||
char temp[1024];
|
||||
bx::snprintf(temp, BX_COUNTOF(temp), "Example: %s", _app->getName() );
|
||||
|
||||
ImGui::Begin(temp
|
||||
, NULL
|
||||
, ImVec2(256.0f, 200.0f)
|
||||
, ImGuiWindowFlags_AlwaysAutoResize
|
||||
);
|
||||
|
||||
ImGui::TextWrapped("%s", _app->getDescription() );
|
||||
ImGui::Separator();
|
||||
|
||||
{
|
||||
uint32_t num = entry::getNumApps();
|
||||
const char** items = (const char**)alloca(num*sizeof(void*) );
|
||||
|
||||
uint32_t ii = 0;
|
||||
int32_t current = 0;
|
||||
for (entry::AppI* app = entry::getFirstApp(); NULL != app; app = app->getNext() )
|
||||
{
|
||||
if (app == _app)
|
||||
{
|
||||
current = ii;
|
||||
}
|
||||
|
||||
items[ii++] = app->getName();
|
||||
}
|
||||
|
||||
if (1 < num
|
||||
&& ImGui::Combo("Example", ¤t, items, num) )
|
||||
{
|
||||
entry::setRestartArgs(items[current]);
|
||||
restart = true;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
{
|
||||
bgfx::RendererType::Enum supportedRenderers[bgfx::RendererType::Count];
|
||||
uint8_t num = bgfx::getSupportedRenderers(BX_COUNTOF(supportedRenderers), supportedRenderers);
|
||||
|
||||
const bgfx::Caps* caps = bgfx::getCaps();
|
||||
|
||||
const char* items[bgfx::RendererType::Count];
|
||||
|
||||
int32_t current = 0;
|
||||
for (uint8_t ii = 0; ii < num; ++ii)
|
||||
{
|
||||
items[ii] = s_rendererNames[supportedRenderers[ii] ];
|
||||
if (supportedRenderers[ii] == caps->rendererType)
|
||||
{
|
||||
current = ii;
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::Combo("Renderer", ¤t, items, num) )
|
||||
{
|
||||
restart = true;
|
||||
}
|
||||
}
|
||||
#endif // 0
|
||||
|
||||
const bgfx::Stats* stats = bgfx::getStats();
|
||||
ImGui::Text("CPU %0.3f"
|
||||
, double(stats->cpuTimeEnd-stats->cpuTimeBegin)/stats->cpuTimerFreq*1000.0
|
||||
);
|
||||
|
||||
ImGui::Text("GPU %0.3f (latency: %d)"
|
||||
, double(stats->gpuTimeEnd-stats->gpuTimeBegin)/stats->gpuTimerFreq*1000.0
|
||||
, stats->maxGpuLatency
|
||||
);
|
||||
|
||||
ImGui::End();
|
||||
|
||||
return restart;
|
||||
}
|
||||
|
@ -3,8 +3,21 @@
|
||||
-- License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
|
||||
--
|
||||
|
||||
project ("example-glue")
|
||||
kind "StaticLib"
|
||||
|
||||
includedirs {
|
||||
path.join(BX_DIR, "include"),
|
||||
path.join(BIMG_DIR, "include"),
|
||||
path.join(BGFX_DIR, "include"),
|
||||
path.join(BGFX_DIR, "3rdparty"),
|
||||
}
|
||||
|
||||
files {
|
||||
path.join(BGFX_DIR, "examples/common/example-glue.cpp"),
|
||||
}
|
||||
|
||||
project ("example-common")
|
||||
uuid ("21cc0e26-bf62-11e2-a01e-0291bd4c8125")
|
||||
kind "StaticLib"
|
||||
|
||||
includedirs {
|
||||
@ -24,6 +37,10 @@ project ("example-common")
|
||||
path.join(BGFX_DIR, "examples/common/**.h"),
|
||||
}
|
||||
|
||||
removefiles {
|
||||
path.join(BGFX_DIR, "examples/common/example-glue.cpp"),
|
||||
}
|
||||
|
||||
if _OPTIONS["with-scintilla"] then
|
||||
defines {
|
||||
"SCI_NAMESPACE",
|
||||
|
@ -134,6 +134,7 @@ function exampleProjectDefaults()
|
||||
|
||||
links {
|
||||
"example-common",
|
||||
"example-glue",
|
||||
"bgfx",
|
||||
"bimg_decode",
|
||||
"bimg",
|
||||
|
Loading…
Reference in New Issue
Block a user