move global pools into gfx driver
prevents double copy problems saves memory (needs to be optimized...)
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#include <pd/drivers/gfx.hpp>
|
||||
#include <pd/lithium/command.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Li {
|
||||
|
||||
void Command::Reserve(size_t vtx, size_t idx) {
|
||||
if (VertexCountMax == 0) {
|
||||
FirstVertex = Gfx::AllocateVertices(vtx, (PD::ptr)this);
|
||||
VertexCountMax = vtx;
|
||||
} else {
|
||||
Gfx::ExpandVertices(vtx, (PD::ptr)this);
|
||||
VertexCountMax += vtx;
|
||||
}
|
||||
if (IndexCountMax == 0) {
|
||||
FirstIndex = Gfx::AllocateIndices(idx, (PD::ptr)this);
|
||||
IndexCountMax = idx;
|
||||
} else {
|
||||
Gfx::ExpandIndices(idx, (PD::ptr)this);
|
||||
IndexCountMax += idx;
|
||||
}
|
||||
}
|
||||
|
||||
void Command::Reset() {
|
||||
Layer = 0;
|
||||
Tex = 0;
|
||||
FirstIndex = 0;
|
||||
FirstVertex = 0;
|
||||
IndexCount = 0;
|
||||
VertexCount = 0;
|
||||
VertexCountMax = 0;
|
||||
IndexCountMax = 0;
|
||||
}
|
||||
|
||||
Command& Command::Add(const Vertex& vtx) {
|
||||
if (VertexCount <= VertexCountMax)
|
||||
Gfx::PutVertex(FirstVertex + VertexCount++, vtx, (PD::ptr)this);
|
||||
return *this;
|
||||
}
|
||||
Command& Command::Add(u16 idx) {
|
||||
if (IndexCount <= IndexCountMax)
|
||||
Gfx::PutIndex(FirstIndex + IndexCount++, FirstVertex + VertexCount + idx,
|
||||
(PD::ptr)this);
|
||||
return *this;
|
||||
}
|
||||
Command& Command::Add(u16 a, u16 b, u16 c) {
|
||||
if (IndexCount + 3 <= IndexCountMax) {
|
||||
size_t idx = FirstIndex + IndexCount;
|
||||
Gfx::PutIndex(idx + 0, FirstVertex + VertexCount + a, (PD::ptr)this);
|
||||
Gfx::PutIndex(idx + 1, FirstVertex + VertexCount + b, (PD::ptr)this);
|
||||
Gfx::PutIndex(idx + 2, FirstVertex + VertexCount + c, (PD::ptr)this);
|
||||
IndexCount += 3;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
} // namespace Li
|
||||
} // namespace PD
|
||||
@@ -1,64 +0,0 @@
|
||||
#include <pd/core/core.hpp>
|
||||
#include <pd/lithium/pools.hpp>
|
||||
|
||||
namespace PD {
|
||||
namespace Li {
|
||||
PD::Pool<Vertex> pVtxPool;
|
||||
PD::Pool<u16> pIdxPool;
|
||||
PD::ptr pVertexAccessor = 0;
|
||||
PD::ptr pIndexAccessor = 0;
|
||||
|
||||
PD_API size_t AllocateVertices(size_t count, PD::ptr accessor) {
|
||||
pVertexAccessor = accessor;
|
||||
int loc = pVtxPool.size();
|
||||
pVtxPool.Allocate(count);
|
||||
return loc;
|
||||
}
|
||||
|
||||
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 ExpandIndices(size_t count, PD::ptr accessor) {
|
||||
if (pIndexAccessor != accessor) return false;
|
||||
pIdxPool.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.NoReset();
|
||||
pIdxPool.NoReset();
|
||||
}
|
||||
} // namespace Li
|
||||
} // namespace PD
|
||||
Reference in New Issue
Block a user