Refactor PD::Li Pools system, Upgrade PD::Pool and add better logging

- Add ResetFast to Pool using c++20 concept
- Add Put function to Pool
- Use Pool Index instead of pointers in Command
- Add accessor to Li Pools to prevent wrong command usage
- Add Command Formatter
- Use ResetFast for all Pools
- Add Reset func to Li::Vertex (for ResetFast)
- Add Pool Expandor and Put funcs to Lithium pools
- Add getters for GfxDriverBase to PD::Li Pools
This commit is contained in:
2026-03-21 13:35:16 +01:00
parent 3b0b103eb3
commit a86c13b9a3
16 changed files with 247 additions and 55 deletions
+7 -3
View File
@@ -1,5 +1,7 @@
#include <iostream>
#include <pd/drivers/gfx.hpp>
#include <pd/lithium/drawlist.hpp>
#include <pd/lithium/formatters.hpp>
#include <pd/lithium/math.hpp>
namespace PD {
@@ -16,9 +18,10 @@ PD_API void Drawlist::Optimize() {}
PD_API void Drawlist::Clear() {
UnbindTexture();
pPath.Reset();
pVertices.Reset();
pIndices.Reset();
pPath.ResetFast();
pVertices.ResetFast();
pIndices.ResetFast();
pCommands.ResetFast();
}
/** Command Allocation */
@@ -262,6 +265,7 @@ PD_API void Drawlist::DrawConvexPolyFilled(const Pool<fvec2>& points,
uv_tl.y + ((points[i].y - minY) / (maxY - minY)) * (uv_bl.y - uv_tl.y);
cmd.Add(Vertex(points[i], fvec2(u, v), color));
}
std::cout << std::format("{}: {}", __PRETTY_FUNCTION__, cmd);
}
PD_API void Drawlist::PrimQuad(Command& cmd, const Rect& quad, const Rect& uv,
+47 -3
View File
@@ -5,12 +5,56 @@ namespace PD {
namespace Li {
PD::Pool<Vertex> pVtxPool;
PD::Pool<u16> pIdxPool;
PD::ptr pVertexAccessor = 0;
PD::ptr pIndexAccessor = 0;
PD_API Vertex* AllocateVertices(size_t count) {
return pVtxPool.Allocate(count);
PD_API size_t AllocateVertices(size_t count, PD::ptr accessor) {
pVertexAccessor = accessor;
int loc = pVtxPool.size();
pVtxPool.Allocate(count);
return loc;
}
PD_API u16* AllocateIndices(size_t count) { return pIdxPool.Allocate(count); }
PD_API size_t AllocateIndices(size_t count, PD::ptr accessor) {
pIndexAccessor = accessor;
int loc = pIdxPool.size();
pIdxPool.Allocate(count);
return loc;
}
PD_API bool ExpandVertices(size_t count, PD::ptr accessor) {
if (pVertexAccessor != accessor) return false;
pVtxPool.Allocate(count);
return true;
}
PD_API bool EcpandIndices(size_t count, PD::ptr accessor) {
if (pIndexAccessor != accessor) return false;
pVtxPool.Allocate(count);
return true;
}
PD_API void PutVertex(size_t loc, const Vertex& vtx, PD::ptr accessor) {
if (pVertexAccessor != accessor) return;
pVtxPool.Put(loc, vtx);
}
PD_API void PutIndex(size_t loc, u16 idx, PD::ptr accessor) {
if (pIndexAccessor != accessor) return;
pIdxPool.Put(loc, idx);
}
PD_API const Vertex& GetVertex(size_t loc) {
if (loc < pVtxPool.size()) return pVtxPool[loc];
static Vertex pErrVtx;
return pErrVtx;
}
PD_API const u16& GetIndex(size_t loc) {
if (loc < pIdxPool.size()) return pIdxPool[loc];
static u16 pErrIdx = 0;
return pErrIdx;
}
PD_API void ResetPools() {
pVtxPool.Reset();