diff options
Diffstat (limited to '3rdparty/bgfx/examples/common/example-glue.cpp')
-rw-r--r-- | 3rdparty/bgfx/examples/common/example-glue.cpp | 226 |
1 files changed, 150 insertions, 76 deletions
diff --git a/3rdparty/bgfx/examples/common/example-glue.cpp b/3rdparty/bgfx/examples/common/example-glue.cpp index 61eba601b80..b6b3d456255 100644 --- a/3rdparty/bgfx/examples/common/example-glue.cpp +++ b/3rdparty/bgfx/examples/common/example-glue.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011-2017 Branimir Karadzic. All rights reserved. + * Copyright 2011-2018 Branimir Karadzic. All rights reserved. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause */ @@ -42,6 +42,34 @@ static bool bar(float _width, float _maxWidth, float _height, const ImVec4& _col return itemHovered; } +static const ImVec4 s_resourceColor(0.5f, 0.5f, 0.5f, 1.0f); + +static void resourceBar(const char* _name, const char* _tooltip, uint32_t _num, uint32_t _max, float _maxWidth, float _height) +{ + bool itemHovered = false; + + ImGui::Text("%s: %4d / %4d", _name, _num, _max); + itemHovered |= ImGui::IsItemHovered(); + ImGui::SameLine(); + + const float percentage = float(_num)/float(_max); + + itemHovered |= bar(bx::max(1.0f, percentage*_maxWidth), _maxWidth, _height, s_resourceColor); + ImGui::SameLine(); + + ImGui::Text("%5.2f%%", percentage*100.0f); + + if (itemHovered) + { + ImGui::SetTooltip("%s %5.2f%%" + , _tooltip + , percentage*100.0f + ); + } +} + +static bool s_showStats = false; + void showExampleDialog(entry::AppI* _app, const char* _errorText) { char temp[1024]; @@ -49,13 +77,15 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText) ImGui::SetNextWindowPos( ImVec2(10.0f, 50.0f) - , ImGuiSetCond_FirstUseEver + , ImGuiCond_FirstUseEver ); - ImGui::Begin(temp - , NULL - , ImVec2(256.0f, 200.0f) + ImGui::SetNextWindowSize( + ImVec2(300.0f, 200.0f) + , ImGuiCond_FirstUseEver ); + ImGui::Begin(temp); + ImGui::TextWrapped("%s", _app->getDescription() ); ImGui::Separator(); @@ -136,6 +166,9 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText) cmdExec("exit"); } + ImGui::SameLine(); + s_showStats ^= ImGui::Button(ICON_FA_BAR_CHART); + ImGui::PopStyleVar(); } @@ -195,8 +228,10 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText) const bgfx::Stats* stats = bgfx::getStats(); const double toMsCpu = 1000.0/stats->cpuTimerFreq; const double toMsGpu = 1000.0/stats->gpuTimerFreq; - ImGui::Text("Frame %0.3f" - , double(stats->cpuTimeFrame)*toMsCpu + const double frameMs = double(stats->cpuTimeFrame)*toMsCpu; + ImGui::Text("Frame %0.3f [ms], %0.3f FPS" + , frameMs + , 1000.0/frameMs ); ImGui::Text("Submit CPU %0.3f, GPU %0.3f (L: %d)" @@ -216,102 +251,141 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText) ImGui::Text("GPU mem: %s / %s", tmp0, tmp1); } - if (0 != stats->numViews) + if (s_showStats) { - if (ImGui::CollapsingHeader(ICON_FA_CLOCK_O " Profiler") ) + ImGui::SetNextWindowSize( + ImVec2(300.0f, 500.0f) + , ImGuiCond_FirstUseEver + ); + + if (ImGui::Begin(ICON_FA_BAR_CHART " Stats", &s_showStats) ) { - if (ImGui::BeginChild("##view_profiler", ImVec2(0.0f, 0.0f) ) ) + if (ImGui::CollapsingHeader(ICON_FA_PUZZLE_PIECE " Resources") ) { - ImGui::PushFont(ImGui::Font::Mono); - - ImVec4 cpuColor(0.5f, 1.0f, 0.5f, 1.0f); - ImVec4 gpuColor(0.5f, 0.5f, 1.0f, 1.0f); + const bgfx::Caps* caps = bgfx::getCaps(); const float itemHeight = ImGui::GetTextLineHeightWithSpacing(); - const float itemHeightWithSpacing = ImGui::GetItemsLineHeightWithSpacing(); - const double toCpuMs = 1000.0/double(stats->cpuTimerFreq); - const double toGpuMs = 1000.0/double(stats->gpuTimerFreq); - const float scale = 3.0f; + const float maxWidth = 90.0f; - if (ImGui::ListBoxHeader("Encoders", ImVec2(ImGui::GetWindowWidth(), stats->numEncoders*itemHeightWithSpacing) ) ) - { - ImGuiListClipper clipper(stats->numEncoders, itemHeight); + ImGui::PushFont(ImGui::Font::Mono); + ImGui::Text("Res: Num / Max"); + resourceBar("DIB", "Dynamic index buffers", stats->numDynamicIndexBuffers, caps->limits.maxDynamicIndexBuffers, maxWidth, itemHeight); + resourceBar("DVB", "Dynamic vertex buffers", stats->numDynamicVertexBuffers, caps->limits.maxDynamicVertexBuffers, maxWidth, itemHeight); + resourceBar(" FB", "Frame buffers", stats->numFrameBuffers, caps->limits.maxFrameBuffers, maxWidth, itemHeight); + resourceBar(" IB", "Index buffers", stats->numIndexBuffers, caps->limits.maxIndexBuffers, maxWidth, itemHeight); + resourceBar(" OQ", "Occlusion queries", stats->numOcclusionQueries, caps->limits.maxOcclusionQueries, maxWidth, itemHeight); + resourceBar(" P", "Programs", stats->numPrograms, caps->limits.maxPrograms, maxWidth, itemHeight); + resourceBar(" S", "Shaders", stats->numShaders, caps->limits.maxShaders, maxWidth, itemHeight); + resourceBar(" T", "Textures", stats->numTextures, caps->limits.maxTextures, maxWidth, itemHeight); + resourceBar(" U", "Uniforms", stats->numUniforms, caps->limits.maxUniforms, maxWidth, itemHeight); + resourceBar(" VB", "Vertex buffers", stats->numVertexBuffers, caps->limits.maxVertexBuffers, maxWidth, itemHeight); + resourceBar(" VD", "Vertex declarations", stats->numVertexDecls, caps->limits.maxVertexDecls, maxWidth, itemHeight); + ImGui::PopFont(); + } - while (clipper.Step() ) + if (ImGui::CollapsingHeader(ICON_FA_CLOCK_O " Profiler") ) + { + if (0 == stats->numViews) + { + ImGui::Text("Profiler is not enabled."); + } + else + { + if (ImGui::BeginChild("##view_profiler", ImVec2(0.0f, 0.0f) ) ) { - for (int32_t pos = clipper.DisplayStart; pos < clipper.DisplayEnd; ++pos) - { - const bgfx::EncoderStats& encoderStats = stats->encoderStats[pos]; + ImGui::PushFont(ImGui::Font::Mono); - ImGui::Text("%3d", pos); - ImGui::SameLine(64.0f); + ImVec4 cpuColor(0.5f, 1.0f, 0.5f, 1.0f); + ImVec4 gpuColor(0.5f, 0.5f, 1.0f, 1.0f); - const float maxWidth = 30.0f*scale; - const float cpuMs = float( (encoderStats.cpuTimeEnd-encoderStats.cpuTimeBegin)*toCpuMs); - const float cpuWidth = bx::fclamp(cpuMs*scale, 1.0f, maxWidth); + const float itemHeight = ImGui::GetTextLineHeightWithSpacing(); + const float itemHeightWithSpacing = ImGui::GetFrameHeightWithSpacing(); + const double toCpuMs = 1000.0/double(stats->cpuTimerFreq); + const double toGpuMs = 1000.0/double(stats->gpuTimerFreq); + const float scale = 3.0f; - if (bar(cpuWidth, maxWidth, itemHeight, cpuColor) ) + if (ImGui::ListBoxHeader("Encoders", ImVec2(ImGui::GetWindowWidth(), stats->numEncoders*itemHeightWithSpacing) ) ) + { + ImGuiListClipper clipper(stats->numEncoders, itemHeight); + + while (clipper.Step() ) { - ImGui::SetTooltip("Encoder %d, CPU: %f [ms]" - , pos - , cpuMs - ); + for (int32_t pos = clipper.DisplayStart; pos < clipper.DisplayEnd; ++pos) + { + const bgfx::EncoderStats& encoderStats = stats->encoderStats[pos]; + + ImGui::Text("%3d", pos); + ImGui::SameLine(64.0f); + + const float maxWidth = 30.0f*scale; + const float cpuMs = float( (encoderStats.cpuTimeEnd-encoderStats.cpuTimeBegin)*toCpuMs); + const float cpuWidth = bx::clamp(cpuMs*scale, 1.0f, maxWidth); + + if (bar(cpuWidth, maxWidth, itemHeight, cpuColor) ) + { + ImGui::SetTooltip("Encoder %d, CPU: %f [ms]" + , pos + , cpuMs + ); + } + } } - } - } - - ImGui::ListBoxFooter(); - } - ImGui::Separator(); + ImGui::ListBoxFooter(); + } - if (ImGui::ListBoxHeader("Views", ImVec2(ImGui::GetWindowWidth(), stats->numViews*itemHeightWithSpacing) ) ) - { - ImGuiListClipper clipper(stats->numViews, itemHeight); + ImGui::Separator(); - while (clipper.Step() ) - { - for (int32_t pos = clipper.DisplayStart; pos < clipper.DisplayEnd; ++pos) + if (ImGui::ListBoxHeader("Views", ImVec2(ImGui::GetWindowWidth(), stats->numViews*itemHeightWithSpacing) ) ) { - const bgfx::ViewStats& viewStats = stats->viewStats[pos]; - - ImGui::Text("%3d %3d %s", pos, viewStats.view, viewStats.name); - - const float maxWidth = 30.0f*scale; - const float cpuWidth = bx::fclamp(float(viewStats.cpuTimeElapsed*toCpuMs)*scale, 1.0f, maxWidth); - const float gpuWidth = bx::fclamp(float(viewStats.gpuTimeElapsed*toGpuMs)*scale, 1.0f, maxWidth); - - ImGui::SameLine(64.0f); + ImGuiListClipper clipper(stats->numViews, itemHeight); - if (bar(cpuWidth, maxWidth, itemHeight, cpuColor) ) + while (clipper.Step() ) { - ImGui::SetTooltip("View %d \"%s\", CPU: %f [ms]" - , pos - , viewStats.name - , viewStats.cpuTimeElapsed*toCpuMs - ); + for (int32_t pos = clipper.DisplayStart; pos < clipper.DisplayEnd; ++pos) + { + const bgfx::ViewStats& viewStats = stats->viewStats[pos]; + + ImGui::Text("%3d %3d %s", pos, viewStats.view, viewStats.name); + + const float maxWidth = 30.0f*scale; + const float cpuWidth = bx::clamp(float(viewStats.cpuTimeElapsed*toCpuMs)*scale, 1.0f, maxWidth); + const float gpuWidth = bx::clamp(float(viewStats.gpuTimeElapsed*toGpuMs)*scale, 1.0f, maxWidth); + + ImGui::SameLine(64.0f); + + if (bar(cpuWidth, maxWidth, itemHeight, cpuColor) ) + { + ImGui::SetTooltip("View %d \"%s\", CPU: %f [ms]" + , pos + , viewStats.name + , viewStats.cpuTimeElapsed*toCpuMs + ); + } + + ImGui::SameLine(); + if (bar(gpuWidth, maxWidth, itemHeight, gpuColor) ) + { + ImGui::SetTooltip("View: %d \"%s\", GPU: %f [ms]" + , pos + , viewStats.name + , viewStats.gpuTimeElapsed*toGpuMs + ); + } + } } - ImGui::SameLine(); - if (bar(gpuWidth, maxWidth, itemHeight, gpuColor) ) - { - ImGui::SetTooltip("View: %d \"%s\", GPU: %f [ms]" - , pos - , viewStats.name - , viewStats.gpuTimeElapsed*toGpuMs - ); - } + ImGui::ListBoxFooter(); } + + ImGui::PopFont(); } - ImGui::ListBoxFooter(); + ImGui::EndChild(); } - - ImGui::PopFont(); } - - ImGui::EndChild(); } + ImGui::End(); } ImGui::End(); |