From ea712fae423b0cc4a4ba6896392e4cfda94c79ae Mon Sep 17 00:00:00 2001 From: JackCarterSmith Date: Sun, 5 Jan 2025 23:10:41 +0100 Subject: [PATCH] Add rendering debug infos --- Engine/Graphics/3DRenderer.cpp | 13 +++++++++++++ Engine/Graphics/3DRenderer.hpp | 10 ++++++++++ Engine/Graphics/DebugUI.cpp | 9 +++++---- Engine/Graphics/DebugUI.hpp | 3 ++- Game.cpp | 3 ++- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Engine/Graphics/3DRenderer.cpp b/Engine/Graphics/3DRenderer.cpp index 902019c..74dbae6 100644 --- a/Engine/Graphics/3DRenderer.cpp +++ b/Engine/Graphics/3DRenderer.cpp @@ -55,6 +55,12 @@ Graphic3DRenderer::Graphic3DRenderer() { mRenderList.push_back(std::make_shared()); mRenderList.back()->SetPosition(0.f, 0.f, 0.f); mRenderList.back()->SetScale(5.0f); + + for (size_t i = 0; i < 40; i++) { + mRenderList.push_back(std::make_shared()); + mRenderList.back()->SetPosition(-100.f + (i * 5.f), 0.f, 8.f); + mRenderList.back()->SetScale(5.0f); + } } Graphic3DRenderer::~Graphic3DRenderer() {} @@ -97,6 +103,10 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) { sf::BlendMode sBM = sf::BlendNone; sf::RenderStates sRS(sBM); +#ifdef DEBUG + drawnTriCount = 0; +#endif + // Hardcoded debug movement, TODO: remove it UpdateInternalTestObjects(); @@ -231,6 +241,9 @@ void Graphic3DRenderer::Draw(sf::RenderTexture& context) { context.draw(v_tri, 4, sf::Triangles, sRS); #else context.draw(v_tri, 4, sf::LineStrip, sRS); +#endif +#ifdef DEBUG + drawnTriCount++; #endif } } diff --git a/Engine/Graphics/3DRenderer.hpp b/Engine/Graphics/3DRenderer.hpp index cdcbfee..1afd3d7 100644 --- a/Engine/Graphics/3DRenderer.hpp +++ b/Engine/Graphics/3DRenderer.hpp @@ -32,6 +32,11 @@ public: void UpdateCamera(CAMERA_MOVE type, const float value); void Draw(sf::RenderTexture& context); + // Debug datas +#ifdef DEBUG + const unsigned int GetDrawTriCount() const noexcept { return drawnTriCount; } +#endif + private: std::unique_ptr mMainCamera; // Default player view sf::Vector2f mRTSize; @@ -40,5 +45,10 @@ private: void UpdateInternalTestObjects(); float ComputeSGRatio(); + + // Debug datas +#ifdef DEBUG + unsigned int drawnTriCount; +#endif }; \ No newline at end of file diff --git a/Engine/Graphics/DebugUI.cpp b/Engine/Graphics/DebugUI.cpp index 6354ab2..6ecd50a 100644 --- a/Engine/Graphics/DebugUI.cpp +++ b/Engine/Graphics/DebugUI.cpp @@ -14,22 +14,23 @@ DebugUI::DebugUI() { gDbgText.setFillColor(sf::Color::White); } -void DebugUI::UpdateDebugData(const double cpu_usage, const double cpu_time, const double cycle_time, const int fps, const std::size_t ram_virt_usage, const std::size_t ram_phys_usage) { +void DebugUI::UpdateDebugData(const double cpu_usage, const double cpu_time, const double cycle_time, const int fps, const std::size_t ram_virt_usage, const std::size_t ram_phys_usage, const unsigned int drawnTriCount) { gDbgStats.cpu_usage = cpu_usage; gDbgStats.cpu_time = cpu_time; gDbgStats.cycle_time = cycle_time; gDbgStats.fps = fps; gDbgStats.ram_virt_usage = ram_virt_usage; gDbgStats.ram_phys_usage = ram_phys_usage; + gDbgStats.drawnTriCount = drawnTriCount; } void DebugUI::DrawDebugData(std::shared_ptr context) { std::ostringstream outStrStream; outStrStream << std::fixed; - outStrStream << std::setprecision(0) << "CPU: " << gDbgStats.cpu_usage << "% (cycle: " << std::setprecision(3) << gDbgStats.cpu_time << "/" << gDbgStats.cycle_time << "ms)" << std::endl; - outStrStream << std::setprecision(1) << "RAM: " << gDbgStats.ram_virt_usage << "MB(V)/" << gDbgStats.ram_phys_usage << "MB(P)" << std::endl; - outStrStream << std::setprecision(0) << "FPS: " << gDbgStats.fps; + outStrStream << std::setprecision(0) << "CPU: " << gDbgStats.cpu_usage << "% (cycle: " << std::setprecision(3) << gDbgStats.cpu_time << "/" << gDbgStats.cycle_time << "ms) - Triangles: " << gDbgStats.drawnTriCount << '\n'; + outStrStream << std::setprecision(1) << "RAM: " << gDbgStats.ram_virt_usage << "MB(V)/" << gDbgStats.ram_phys_usage << "MB(P)\n"; + outStrStream << std::setprecision(0) << "FPS: " << gDbgStats.fps << std::flush; gDbgText.setString(outStrStream.str()); context->draw(gDbgText); diff --git a/Engine/Graphics/DebugUI.hpp b/Engine/Graphics/DebugUI.hpp index 8289f65..98de0ec 100644 --- a/Engine/Graphics/DebugUI.hpp +++ b/Engine/Graphics/DebugUI.hpp @@ -14,6 +14,7 @@ struct sDbgStats { int fps; std::size_t ram_virt_usage; std::size_t ram_phys_usage; + unsigned int drawnTriCount; }; class DebugUI { @@ -21,7 +22,7 @@ public: DebugUI(); ~DebugUI() {} - void UpdateDebugData(const double cpu_usage, const double cpu_time, const double cycle_time, const int fps, const std::size_t ram_virt_usage, const std::size_t ram_phys_usage); + void UpdateDebugData(const double cpu_usage, const double cpu_time, const double cycle_time, const int fps, const std::size_t ram_virt_usage, const std::size_t ram_phys_usage, const unsigned int drawnTriCount); void DrawDebugData(std::shared_ptr context); private: diff --git a/Game.cpp b/Game.cpp index f65d26b..dd31725 100644 --- a/Game.cpp +++ b/Game.cpp @@ -68,7 +68,8 @@ GAME_STATUS Game::Tick() { 1000.f / TARGET_FPS, mFrameCnt, PerfsGetVirtMem() / 1000, - PerfsGetPhysMem() / 1000 + PerfsGetPhysMem() / 1000, + mWorld3D->GetDrawTriCount() ); mFrameCnt = 0;