From a8fe58ef0f78556f4767a1436468188b88e6e2a7 Mon Sep 17 00:00:00 2001 From: tobid7 Date: Wed, 25 Mar 2026 20:27:23 +0100 Subject: [PATCH] Add debug getters (and somehow text is not rendering :/) --- include/pd/drivers/gfx.hpp | 17 ++++++++++++++--- source/drivers/gfx.cpp | 8 +++++++- source/lithium/font.cpp | 1 + tests/gfx/source/main.cpp | 8 ++++++++ 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/include/pd/drivers/gfx.hpp b/include/pd/drivers/gfx.hpp index 657e1a4..4872f73 100755 --- a/include/pd/drivers/gfx.hpp +++ b/include/pd/drivers/gfx.hpp @@ -42,6 +42,11 @@ class PD_API GfxDriver : public DriverInterface { Li::Texture::Ptr GetWhiteTexture() { return &pWhite; } PDBackendFlags GetFlags() { return Flags; } + size_t GetNumVertices() const { return CountVertices; } + size_t GetNumIndices() const { return CountIndices; } + size_t GetNumDrawcalls() const { return CountDrawcalls; } + size_t GetNumCommands() const { return CountCommands; } + protected: virtual void SysDeinit() {} virtual void SysInit() {} @@ -58,6 +63,8 @@ class PD_API GfxDriver : public DriverInterface { size_t CountIndices = 0; size_t CurrentIndex = 0; size_t CurrentVertex = 0; + size_t pCountDrawcalls = 0; + size_t pCountCommands = 0; TextureID CurrentTex = 0; Mat4 Projection; ivec2 ViewPort; @@ -91,7 +98,7 @@ class GfxDriverBase : public GfxDriver { } void Draw(const Pool& commands) override { - CountCommands += commands.size(); + pCountCommands += commands.size(); size_t index = 0; while (index < commands.size()) { CurrentTex = commands[index].Tex; @@ -103,8 +110,6 @@ class GfxDriverBase : public GfxDriver { (CurrentTex == commands[index].Tex || (CurrentTex == pWhite.GetID() && commands[index].Tex == 0))) { const auto& c = commands[index]; - CountVertices += c.VertexCount; - CountIndices += c.IndexCount; auto pIdx = pIdxPool.Allocate(c.IndexCount); auto pVtx = pVtxPool.Allocate(c.VertexCount); for (size_t i = 0; i < c.IndexCount; i++) { @@ -118,6 +123,7 @@ class GfxDriverBase : public GfxDriver { index++; } Submit(CurrentIndex - startidx, startidx); + pCountDrawcalls++; } } @@ -172,6 +178,11 @@ class PD_API Gfx { static const char* GetDriverName() { return driver->GetName(); } + static size_t GetNumVertices() { return driver->GetNumVertices(); } + static size_t GetNumIndices() { return driver->GetNumIndices(); } + static size_t GetNumDrawcalls() { return driver->GetNumDrawcalls(); } + static size_t GetNumCommands() { return driver->GetNumCommands(); } + private: static std::unique_ptr driver; }; diff --git a/source/drivers/gfx.cpp b/source/drivers/gfx.cpp index 86b11c0..ea1d98d 100644 --- a/source/drivers/gfx.cpp +++ b/source/drivers/gfx.cpp @@ -25,8 +25,14 @@ PD_API void GfxDriver::SetViewPort(int x, int y) { } PD_API void GfxDriver::Reset() { + CountIndices = CurrentIndex; + CountVertices = CurrentVertex; CurrentVertex = 0; CurrentIndex = 0; + CountCommands = pCountCommands; + CountDrawcalls = pCountDrawcalls; + pCountCommands = 0; + pCountDrawcalls = 0; ResetPools(); SysReset(); } @@ -41,7 +47,7 @@ PD_API void GfxDriver::UnregisterTexture(const Li::Texture& tex) { PDLOG("GfxDriver: Texture {{ {} }} has been deleted!", tex); } else { PDWARN("GfxDriver: WARNING Texture {{ {} }} does not exist in regestry!", - tex); + tex); } } } // namespace PD \ No newline at end of file diff --git a/source/lithium/font.cpp b/source/lithium/font.cpp index ac89aa3..05d2732 100644 --- a/source/lithium/font.cpp +++ b/source/lithium/font.cpp @@ -20,6 +20,7 @@ PD_API void Font::LoadTTF(const std::string& path, int px_height) { PDLOG("Font: Loading {}...", path); TT::Scope st("LI_LoadTTF_" + path); auto font = PD::IO::LoadFile2Mem(path); + PDLOG("Font Size: {}", PD::Strings::FormatBytes(font.size())); LoadTTF(font, px_height); } diff --git a/tests/gfx/source/main.cpp b/tests/gfx/source/main.cpp index 9ce7671..5f4aa2a 100644 --- a/tests/gfx/source/main.cpp +++ b/tests/gfx/source/main.cpp @@ -52,6 +52,14 @@ int main(int argc, char** argv) { pList.DrawRectFilled(pOs->PositionTranslate(PD::fvec2(0.02f, 0.5f)), pOs->SizeTranslate(PD::fvec2(0.3)), 0xffffffff); pList.DrawText(5, "Hello World!", 0xff0000ff); + pList.DrawText( + pOs->PositionTranslate(PD::fvec2(0.005, 0.9)), + std::format("VIDC: [{}, {}, {}, {}]\nGfxDriver: {}", + PD::Gfx::GetNumVertices(), PD::Gfx::GetNumIndices(), + PD::Gfx::GetNumDrawcalls(), PD::Gfx::GetNumCommands(), + PD::Gfx::GetDriverName()) + .c_str(), + PD::Color("#ffffff")); PD::Gfx::Reset(); PD::Gfx::Draw(pList); pList.Clear();