Merge pull request #1068 from MihailRis/show-vertices-in-debug-panel
Some checks are pending
x86-64 AppImage / build-appimage (ubuntu-22.04) (push) Waiting to run
Build / Build (push) Waiting to run
Macos Build / build-dmg (push) Waiting to run
Windows Build (CLang) / build-windows (clang, windows-latest) (push) Waiting to run
MSVC Build / build-windows (windows-2022) (push) Waiting to run

add vertices count to debug panel
This commit is contained in:
MihailRis 2026-11-01 02:03:23 +03:00 • committed by GitHub
commit 7561515ff2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 66 additions and 26 deletions

View file

@ -78,6 +78,8 @@ std::shared_ptr<UINode> create_debug_panel(
static int drawCallsMax = drawCalls; static int drawCallsMax = drawCalls;
static std::wstring drawCallsAvgString = L""; static std::wstring drawCallsAvgString = L"";
static std::wstring drawCallsMinMaxString = L""; static std::wstring drawCallsMinMaxString = L"";
static int verticesCount = 0;
static std::wstring verticesCountString = L"";
static size_t lastTotalDownload = 0; static size_t lastTotalDownload = 0;
static size_t lastTotalUpload = 0; static size_t lastTotalUpload = 0;
@ -151,6 +153,19 @@ std::shared_ptr<UINode> create_debug_panel(
panel->add(create_label(gui, []() { panel->add(create_label(gui, []() {
return drawCallsMinMaxString; return drawCallsMinMaxString;
})); }));
panel->add(create_label(gui, []() {
static int frame = 0;
verticesCount = std::max<int>(verticesCount, MeshStats::vertices);
if (frame % 4 == 0) {
verticesCountString =
L"vertices: " + std::to_wstring(verticesCount) + L" (" +
util::str2wstr_utf8(util::format_count(verticesCount)) + L")";
}
frame++;
MeshStats::vertices = 0;
verticesCount = 0;
return verticesCountString;
}));
panel->add(create_label(gui, []() { panel->add(create_label(gui, []() {
return L"speakers: " + std::to_wstring(audio::count_speakers()) + return L"speakers: " + std::to_wstring(audio::count_speakers()) +
L" streams: " + std::to_wstring(audio::count_streams()); L" streams: " + std::to_wstring(audio::count_streams());

View file

@ -1,4 +1,5 @@
#include "graphics/core/Mesh.hpp" #include "graphics/core/Mesh.hpp"
int MeshStats::meshesCount = 0; int MeshStats::meshesCount = 0;
int MeshStats::drawCalls = 0; int MeshStats::drawCalls = 0;
int MeshStats::vertices = 0;

View file

@ -8,6 +8,7 @@
struct MeshStats { struct MeshStats {
static int meshesCount; static int meshesCount;
static int drawCalls; static int drawCalls;
static int vertices;
}; };
struct IndexBufferData { struct IndexBufferData {

View file

@ -126,17 +126,20 @@ void Mesh<VertexStructure>::draw(unsigned int primitive, int iboIndex) const {
if (!ibos.empty()) { if (!ibos.empty()) {
if (iboIndex < ibos.size()) { if (iboIndex < ibos.size()) {
size_t indexCount = ibos.at(iboIndex).indexCount;
glBindVertexArray(vao); glBindVertexArray(vao);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibos[iboIndex].ibo); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibos[iboIndex].ibo);
glDrawElements( glDrawElements(
primitive, ibos.at(iboIndex).indexCount, GL_UNSIGNED_INT, nullptr primitive, indexCount, GL_UNSIGNED_INT, nullptr
); );
glBindVertexArray(0); glBindVertexArray(0);
MeshStats::vertices += indexCount;
} }
} else if (vertexCount > 0) { } else if (vertexCount > 0) {
glBindVertexArray(vao); glBindVertexArray(vao);
glDrawArrays(primitive, 0, vertexCount); glDrawArrays(primitive, 0, vertexCount);
glBindVertexArray(0); glBindVertexArray(0);
MeshStats::vertices += vertexCount;
} }
} }

View file

@ -1,11 +1,11 @@
#include "stringutil.hpp" #include "stringutil.hpp"
#include <algorithm> #include <algorithm>
#include <charconv> #include <charconv>
#include <cctype> #include <cctype>
#include <cmath> #include <cmath>
#include <iomanip> #include <iomanip>
#include <locale> #include <locale>
#include <sstream> #include <sstream>
#include <stdexcept> #include <stdexcept>
@ -511,22 +511,22 @@ int util::replaceAll(
return replace_all(str, from, to); return replace_all(str, from, to);
} }
double util::parse_double(const std::string& str) { double util::parse_double(const std::string& str) {
const char* begin = str.data(); const char* begin = str.data();
const char* end = begin + str.size(); const char* end = begin + str.size();
while (begin != end && std::isspace(static_cast<unsigned char>(*begin))) { while (begin != end && std::isspace(static_cast<unsigned char>(*begin))) {
begin++; begin++;
} }
if (begin != end && *begin == '+') { if (begin != end && *begin == '+') {
begin++; begin++;
} }
double d = 0.0; double d = 0.0;
const auto result = std::from_chars(begin, end, d); const auto result = std::from_chars(begin, end, d);
if (result.ec != std::errc()) { if (result.ec != std::errc()) {
throw std::runtime_error("invalid number format"); throw std::runtime_error("invalid number format");
} }
return d; return d;
} }
double util::parse_double(const std::string& str, size_t offset, size_t len) { double util::parse_double(const std::string& str, size_t offset, size_t len) {
return parse_double(str.substr(offset, len)); return parse_double(str.substr(offset, len));
@ -667,6 +667,25 @@ std::string util::format_data_size(size_t size) {
postfixes[group]; postfixes[group];
} }
std::string util::format_count(size_t count) {
if (count < 1000) {
return std::to_string(count);
}
const std::string postfixes[] {
"", " K", " M", " B"
};
int group = 0;
size_t remainder = 0;
while (count >= 1000) {
group++;
remainder = count % 1000;
count /= 1000;
}
return std::to_string(count) + "." +
std::to_string(static_cast<int>(round(remainder / 1000.0f))) +
postfixes[group];
}
std::pair<std::string, std::string> util::split_at( std::pair<std::string, std::string> util::split_at(
std::string_view view, char c std::string_view view, char c
) { ) {

View file

@ -118,6 +118,7 @@ namespace util {
std::vector<std::wstring> split(const std::wstring& str, char delimiter); std::vector<std::wstring> split(const std::wstring& str, char delimiter);
std::string format_data_size(size_t size); std::string format_data_size(size_t size);
std::string format_count(size_t size);
std::pair<std::string, std::string> split_at(std::string_view view, char c); std::pair<std::string, std::string> split_at(std::string_view view, char c);