Files
palladium/source/lithium/command.cpp
T

89 lines
2.2 KiB
C++
Raw Normal View History

2026-09-02 08:04:50 +02:00
#include <pd/drivers/gfx.hpp>
#include <pd/lithium/command.hpp>
2026-09-05 22:52:59 +02:00
#include <pd/lithium/pools.hpp>
2026-09-02 08:04:50 +02:00
namespace PD {
namespace Li {
void Command::Reserve(size_t vtx, size_t idx) {
2026-09-05 22:52:59 +02:00
auto& vpool = GetVertexPool();
auto& ipool = GetIndexPool();
2026-09-02 08:04:50 +02:00
if (VertexCountMax == 0) {
2026-09-05 22:52:59 +02:00
FirstVertex = vpool.size();
vpool.Allocate(vtx);
2026-09-02 08:04:50 +02:00
VertexCountMax = vtx;
} else {
2026-09-05 22:52:59 +02:00
if (vpool.size() == FirstVertex + VertexCountMax) {
vpool.Allocate(vtx);
VertexCountMax += vtx;
} else {
size_t tmp = FirstVertex;
FirstVertex = vpool.size();
vpool.Allocate(VertexCountMax + vtx);
for (size_t i = 0; i < VertexCount; i++) {
vpool[FirstVertex + i] = vpool[tmp + i];
}
VertexCountMax += vtx;
}
2026-09-02 08:04:50 +02:00
}
if (IndexCountMax == 0) {
2026-09-05 22:52:59 +02:00
FirstIndex = ipool.size();
ipool.Allocate(idx);
2026-09-02 08:04:50 +02:00
IndexCountMax = idx;
} else {
2026-09-05 22:52:59 +02:00
if (ipool.size() == FirstIndex + IndexCountMax) {
ipool.Allocate(idx);
IndexCountMax += idx;
} else {
size_t tmp = FirstIndex;
FirstIndex = ipool.size();
ipool.Allocate(IndexCountMax + idx);
for (size_t i = 0; i < IndexCount; i++) {
ipool[FirstIndex + i] = ipool[tmp + i];
}
IndexCountMax += idx;
}
2026-09-02 08:04:50 +02:00
}
}
void Command::Reset() {
Layer = 0;
Tex = 0;
2026-09-05 11:56:13 +02:00
SDF = false;
2026-09-02 08:04:50 +02:00
FirstIndex = 0;
FirstVertex = 0;
IndexCount = 0;
VertexCount = 0;
VertexCountMax = 0;
IndexCountMax = 0;
2026-09-08 21:15:21 +02:00
ClipRect = 0.f;
ClipRectUsed = false;
2026-09-02 08:04:50 +02:00
}
Command& Command::Add(const Vertex& vtx) {
2026-09-05 22:52:59 +02:00
if (VertexCount < VertexCountMax) {
GetVertexPool()[FirstVertex + VertexCount++] = vtx;
}
2026-09-02 08:04:50 +02:00
return *this;
}
Command& Command::Add(u16 idx) {
2026-09-05 22:52:59 +02:00
if (IndexCount < IndexCountMax) {
GetIndexPool()[FirstIndex + IndexCount++] =
static_cast<u16>(VertexCount + idx);
}
2026-09-02 08:04:50 +02:00
return *this;
}
Command& Command::Add(u16 a, u16 b, u16 c) {
if (IndexCount + 3 <= IndexCountMax) {
2026-09-05 22:52:59 +02:00
auto& ip = GetIndexPool();
2026-09-02 08:04:50 +02:00
size_t idx = FirstIndex + IndexCount;
2026-09-05 22:52:59 +02:00
ip[idx + 0] = static_cast<u16>(VertexCount + a);
ip[idx + 1] = static_cast<u16>(VertexCount + b);
ip[idx + 2] = static_cast<u16>(VertexCount + c);
2026-09-02 08:04:50 +02:00
IndexCount += 3;
}
return *this;
}
} // namespace Li
} // namespace PD