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:
+27
-3
@@ -1,6 +1,30 @@
|
||||
#include <iostream>
|
||||
#include <pd/common.hpp>
|
||||
|
||||
PD_API void PD::Log(const std::string& txt) {
|
||||
std::cout << "[PD] " << txt << std::endl;
|
||||
}
|
||||
namespace PD {
|
||||
constexpr const char* pColorNo = "\033[0m";
|
||||
constexpr const char* pColorYellow = "\033[33m";
|
||||
constexpr const char* pColorRed = "\033[31m";
|
||||
static LogLevel pFilter = LogLevel::Info;
|
||||
PD_API void Log(const std::string& txt, LogLevel lvl) {
|
||||
if ((int)lvl < (int)pFilter) return;
|
||||
const char* clr = pColorNo;
|
||||
const char* plvl = "INFO";
|
||||
switch (lvl) {
|
||||
case PD::LogLevel::Info:
|
||||
clr = pColorNo;
|
||||
plvl = "INFO";
|
||||
break;
|
||||
case PD::LogLevel::Warning:
|
||||
clr = pColorYellow;
|
||||
plvl = "WARNING";
|
||||
break;
|
||||
case PD::LogLevel::Error:
|
||||
clr = pColorRed;
|
||||
plvl = "ERROR";
|
||||
break;
|
||||
}
|
||||
|
||||
std::cout << clr << "[PD][" << plvl << "] " << txt << pColorNo << std::endl;
|
||||
}
|
||||
} // namespace PD
|
||||
@@ -8,7 +8,7 @@ PD_API GfxDriver::GfxDriver(std::string_view name) : DriverInterface(name) {}
|
||||
|
||||
PD_API GfxDriver::~GfxDriver() {
|
||||
if (pTextureRegestry.size()) {
|
||||
PDLOG("GfxDriver: {} is still holding {} texture{}!", GetName(),
|
||||
PDERR("GfxDriver: {} is still holding {} texture{}!", GetName(),
|
||||
pTextureRegestry.size(), (pTextureRegestry.size() == 1 ? "" : "s"));
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ PD_API void GfxDriver::UnregisterTexture(const Li::Texture& tex) {
|
||||
pTextureRegestry.erase(pTextureRegestry.find(tex.GetID()));
|
||||
PDLOG("GfxDriver: Texture {{ {} }} has been deleted!", tex);
|
||||
} else {
|
||||
PDLOG("GfxDriver: WARNING Texture {{ {} }} does not exist in regestry!",
|
||||
PDWARN("GfxDriver: WARNING Texture {{ {} }} does not exist in regestry!",
|
||||
tex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user