From e8a905509079a2197d4c70616bd5f076c7640d3e Mon Sep 17 00:00:00 2001 From: tobid7 Date: Sun, 6 Sep 2026 14:39:28 +0200 Subject: [PATCH] Layers are back --- include/pd/lithium/drawlist.hpp | 5 +++++ source/lithium/drawlist.cpp | 10 ++++++++++ source/lithium/font.cpp | 3 ++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/pd/lithium/drawlist.hpp b/include/pd/lithium/drawlist.hpp index b023576..669aae7 100644 --- a/include/pd/lithium/drawlist.hpp +++ b/include/pd/lithium/drawlist.hpp @@ -42,6 +42,10 @@ class PD_API Drawlist { void Copy(Drawlist& other); void Optimize(); void Clear(); + void SetLayer(int layer) { pCurrentLayer = layer; } + void LayerUp() { pCurrentLayer++; } + void LayerDown() { pCurrentLayer--; } + int GetLayer() const { return pCurrentLayer; } size_t GetNumVertices() const { size_t count = 0; @@ -126,6 +130,7 @@ class PD_API Drawlist { private: Texture pCurrentTexture; + int pCurrentLayer = 0; Pool pCommands; Pool pPath; Pool pVertices; diff --git a/source/lithium/drawlist.cpp b/source/lithium/drawlist.cpp index d067430..d4ec540 100644 --- a/source/lithium/drawlist.cpp +++ b/source/lithium/drawlist.cpp @@ -12,12 +12,20 @@ PD_API Drawlist::Drawlist() { Clear(); } PD_API Drawlist::~Drawlist() { Clear(); } PD_API void Drawlist::Merge(Drawlist& other) { + size_t start = pCommands.size(); pCommands.AppendMove(other.pCommands); + for (size_t i = start; i < pCommands.size(); i++) { + pCommands[i].Layer += this->pCurrentLayer; + } other.Clear(); } PD_API void Drawlist::Copy(Drawlist& other) { + int start = pCommands.size(); pCommands.AppendCopy(other.pCommands); + for (size_t i = start; i < pCommands.size(); i++) { + pCommands[i].Layer += this->pCurrentLayer; + } } PD_API void Drawlist::Optimize() { @@ -34,12 +42,14 @@ PD_API void Drawlist::Clear() { UnbindTexture(); pPath.ResetFast(); pCommands.NoReset(); + pCurrentLayer = 0; } /** Command Allocation */ PD_API Command& Drawlist::NewCommand() { auto cmd = pCommands.Allocate(1); cmd->Reset(); + cmd->Layer = pCurrentLayer; cmd->Tex = pCurrentTexture.GetID(); return *cmd; } diff --git a/source/lithium/font.cpp b/source/lithium/font.cpp index e9d778f..9aaa59a 100644 --- a/source/lithium/font.cpp +++ b/source/lithium/font.cpp @@ -288,7 +288,8 @@ PD_API void Font::CmdTextEx(Drawlist& dl, const fvec2& pos, u32 color, } if (cp.Size.x > 0 && cp.Size.y > 0) { - if (cmd == nullptr || cmd->Tex != Textures[cp.Tex]) { + if (cmd == nullptr || cmd->Tex != Textures[cp.Tex] || + cmd->Layer != dl.GetLayer()) { if (cp.Tex >= Textures.size()) continue; cmd = &dl.NewCommand(); cmd->Tex = Textures[cp.Tex];