summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/common/example-glue.cpp
diff options
context:
space:
mode:
author Julian Sikorski <belegdol+github@gmail.com>2019-10-13 13:50:38 +0200
committer R. Belmont <rb6502@users.noreply.github.com>2019-10-13 07:50:38 -0400
commit0837e7451a84f95c29dbdb9bd6b8b931fee1635d (patch)
tree626bcbd250a7fbebdf5958a288d2f438d4f9fb5a /3rdparty/bgfx/examples/common/example-glue.cpp
parentc913ccb59d713ce0b91135520719ac5385e54358 (diff)
WIP: sync bgfx, bx and bimg with latest upstream (#5723)
* Sync with bgfx upstream revision b91d0b6 * Sync with bx upstream revision d60912b * Sync with bimg upstream revision bd81f60 * Add astc-codec decoder * Rename VertexDecl to VertexLayout * Rename UniformType enum Int1 to Sampler. * Add NVN stub * Fix unused-const-variable error on macOS * Drop redundant explicit language parameters buildoptions_cpp are only applied to c++ files and buildoptions_objcpp are only applied to objective c++ files. As such, hardcoding -x offers no benefit while preventing overrides (such as one needed by 3rdparty/bgfx/src/renderer_vk.cpp on macOS) from working. * Re-introduce -x c++ in places where C code is compiled as C++ to prevent clang from throwing a warning * Build bgfx as Objective-C++ on macOS It is needed due to included headers * Enable Direct3D12 and Vulkan bgfx rendering backends * Enable building of spirv shaders * Properly escape /c in cmd call * Comment out dx12 bgfx renderer * Honor VERBOSE setting during shaders build * Only invert hlsl shader XYZ_TO_sRGB matrix for opengl * Add spirv shaders * OpenGL ES needs transposed matrix too * Metal needs transposed matrix as well
Diffstat (limited to '3rdparty/bgfx/examples/common/example-glue.cpp')
-rw-r--r--3rdparty/bgfx/examples/common/example-glue.cpp103
1 files changed, 96 insertions, 7 deletions
diff --git a/3rdparty/bgfx/examples/common/example-glue.cpp b/3rdparty/bgfx/examples/common/example-glue.cpp
index b6b3d456255..0c4f84f93c6 100644
--- a/3rdparty/bgfx/examples/common/example-glue.cpp
+++ b/3rdparty/bgfx/examples/common/example-glue.cpp
@@ -1,15 +1,67 @@
/*
- * Copyright 2011-2018 Branimir Karadzic. All rights reserved.
+ * Copyright 2011-2019 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
#include "imgui/imgui.h"
#include "entry/entry.h"
#include "entry/cmd.h"
+#include "entry/dialog.h"
#include <bx/string.h>
#include <bx/timer.h>
#include <bx/math.h>
+struct SampleData
+{
+ static constexpr uint32_t kNumSamples = 100;
+
+ SampleData()
+ {
+ reset();
+ }
+
+ void reset()
+ {
+ m_offset = 0;
+ bx::memSet(m_values, 0, sizeof(m_values) );
+
+ m_min = 0.0f;
+ m_max = 0.0f;
+ m_avg = 0.0f;
+ }
+
+ void pushSample(float value)
+ {
+ m_values[m_offset] = value;
+ m_offset = (m_offset+1) % kNumSamples;
+
+ float min = bx::kFloatMax;
+ float max = -bx::kFloatMax;
+ float avg = 0.0f;
+
+ for (uint32_t ii = 0; ii < kNumSamples; ++ii)
+ {
+ const float val = m_values[ii];
+ min = bx::min(min, val);
+ max = bx::max(max, val);
+ avg += val;
+ }
+
+ m_min = min;
+ m_max = max;
+ m_avg = avg / kNumSamples;
+ }
+
+ int32_t m_offset;
+ float m_values[kNumSamples];
+
+ float m_min;
+ float m_max;
+ float m_avg;
+};
+
+static SampleData s_frameTime;
+
static bool bar(float _width, float _maxWidth, float _height, const ImVec4& _color)
{
const ImGuiStyle& style = ImGui::GetStyle();
@@ -33,7 +85,7 @@ static bool bar(float _width, float _maxWidth, float _height, const ImVec4& _col
itemHovered |= ImGui::IsItemHovered();
ImGui::SameLine();
- ImGui::InvisibleButton("", ImVec2(_maxWidth-_width, _height) );
+ ImGui::InvisibleButton("", ImVec2(bx::max(1.0f, _maxWidth-_width), _height) );
itemHovered |= ImGui::IsItemHovered();
ImGui::PopStyleVar(2);
@@ -80,13 +132,30 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText)
, ImGuiCond_FirstUseEver
);
ImGui::SetNextWindowSize(
- ImVec2(300.0f, 200.0f)
+ ImVec2(300.0f, 210.0f)
, ImGuiCond_FirstUseEver
);
ImGui::Begin(temp);
ImGui::TextWrapped("%s", _app->getDescription() );
+
+ bx::StringView url = _app->getUrl();
+ if (!url.isEmpty() )
+ {
+ ImGui::SameLine();
+ if (ImGui::SmallButton(ICON_FA_LINK) )
+ {
+ openUrl(url);
+ }
+ else if (ImGui::IsItemHovered() )
+ {
+ char tmp[1024];
+ bx::snprintf(tmp, BX_COUNTOF(tmp), "Documentation: %.*s", url.getLength(), url.getPtr() );
+ ImGui::SetTooltip(tmp);
+ }
+ }
+
ImGui::Separator();
if (NULL != _errorText)
@@ -229,10 +298,30 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText)
const double toMsCpu = 1000.0/stats->cpuTimerFreq;
const double toMsGpu = 1000.0/stats->gpuTimerFreq;
const double frameMs = double(stats->cpuTimeFrame)*toMsCpu;
- ImGui::Text("Frame %0.3f [ms], %0.3f FPS"
- , frameMs
- , 1000.0/frameMs
+
+ s_frameTime.pushSample(float(frameMs) );
+
+ char frameTextOverlay[256];
+ bx::snprintf(frameTextOverlay, BX_COUNTOF(frameTextOverlay), "%s%.3fms, %s%.3fms\nAvg: %.3fms, %.1f FPS"
+ , ICON_FA_ARROW_DOWN
+ , s_frameTime.m_min
+ , ICON_FA_ARROW_UP
+ , s_frameTime.m_max
+ , s_frameTime.m_avg
+ , 1000.0f/s_frameTime.m_avg
+ );
+
+ ImGui::PushStyleColor(ImGuiCol_PlotHistogram, ImColor(0.0f, 0.5f, 0.15f, 1.0f).Value);
+ ImGui::PlotHistogram("Frame"
+ , s_frameTime.m_values
+ , SampleData::kNumSamples
+ , s_frameTime.m_offset
+ , frameTextOverlay
+ , 0.0f
+ , 60.0f
+ , ImVec2(0.0f, 45.0f)
);
+ ImGui::PopStyleColor();
ImGui::Text("Submit CPU %0.3f, GPU %0.3f (L: %d)"
, double(stats->cpuTimeEnd - stats->cpuTimeBegin)*toMsCpu
@@ -279,7 +368,7 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText)
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);
+ resourceBar(" VL", "Vertex layouts", stats->numVertexLayouts, caps->limits.maxVertexLayouts, maxWidth, itemHeight);
ImGui::PopFont();
}