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:
@@ -236,7 +236,7 @@ void GfxCitro3D::DeleteTexture(const Li::Texture& tex) {
|
|||||||
#else
|
#else
|
||||||
namespace PD {
|
namespace PD {
|
||||||
void GfxCitro3D::SysInit() {
|
void GfxCitro3D::SysInit() {
|
||||||
PDLOG(
|
PDERR(
|
||||||
"GfxCitro3D::SysInit: Citro3D Driver is not included in "
|
"GfxCitro3D::SysInit: Citro3D Driver is not included in "
|
||||||
"palladium-system");
|
"palladium-system");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ void GfxDirectX9::SysInit() {
|
|||||||
HRESULT hr = D3DCompile(g_vsCode, strlen(g_vsCode), nullptr, nullptr,
|
HRESULT hr = D3DCompile(g_vsCode, strlen(g_vsCode), nullptr, nullptr,
|
||||||
nullptr, "main", "vs_2_0", 0, 0, &vsBlob, &errBlob);
|
nullptr, "main", "vs_2_0", 0, 0, &vsBlob, &errBlob);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
PDLOG("Vertex Shader compile error: {}",
|
PDERR("Vertex Shader compile error: {}",
|
||||||
errBlob ? (char*)errBlob->GetBufferPointer() : "");
|
errBlob ? (char*)errBlob->GetBufferPointer() : "");
|
||||||
} else {
|
} else {
|
||||||
impl->Device->CreateVertexShader((DWORD*)vsBlob->GetBufferPointer(),
|
impl->Device->CreateVertexShader((DWORD*)vsBlob->GetBufferPointer(),
|
||||||
@@ -109,7 +109,7 @@ void GfxDirectX9::SysInit() {
|
|||||||
if (psBlob) psBlob->Release();
|
if (psBlob) psBlob->Release();
|
||||||
if (errBlob) errBlob->Release();
|
if (errBlob) errBlob->Release();
|
||||||
} else {
|
} else {
|
||||||
PDLOG(
|
PDERR(
|
||||||
"GfxDirectX9::SysInit Error: pDevice is not set!\nYOu need to include "
|
"GfxDirectX9::SysInit Error: pDevice is not set!\nYOu need to include "
|
||||||
"your D3D9 Device as "
|
"your D3D9 Device as "
|
||||||
"folowing:\nPD::Gfx::UseDriver<PD::GfxDirectX9>(D3D9Device);");
|
"folowing:\nPD::Gfx::UseDriver<PD::GfxDirectX9>(D3D9Device);");
|
||||||
@@ -276,7 +276,7 @@ void GfxDirectX9::DeleteTexture(const Li::Texture& tex) {
|
|||||||
#else
|
#else
|
||||||
namespace PD {
|
namespace PD {
|
||||||
void GfxDirectX9::SysInit() {
|
void GfxDirectX9::SysInit() {
|
||||||
PDLOG(
|
PDERR(
|
||||||
"GfxDirectX9::SysInit: DirectX9 Driver is not included in "
|
"GfxDirectX9::SysInit: DirectX9 Driver is not included in "
|
||||||
"palladium-system");
|
"palladium-system");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,10 +82,6 @@ void GfxOpenGL2::SysInit() {
|
|||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
PDLOG(
|
|
||||||
"GfxOpenGL2::SysInit():\n pShader = {}\n pLocTex = {}\n pLocAlfa = "
|
|
||||||
"{}\n pLocProjection = {}\n VBO = {}\n IBO = {}",
|
|
||||||
pShader, pLocTex, pLocAlfa, pLocProjection, VBO, IBO);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GfxOpenGL2::SysDeinit() {
|
void GfxOpenGL2::SysDeinit() {
|
||||||
@@ -172,7 +168,7 @@ void GfxOpenGL2::DeleteTexture(const Li::Texture& tex) {
|
|||||||
#else
|
#else
|
||||||
namespace PD {
|
namespace PD {
|
||||||
void GfxOpenGL2::SysInit() {
|
void GfxOpenGL2::SysInit() {
|
||||||
PDLOG(
|
PDERR(
|
||||||
"GfxOpenGL2::SysInit: OpenGL2 Driver is not included in "
|
"GfxOpenGL2::SysInit: OpenGL2 Driver is not included in "
|
||||||
"palladium-system");
|
"palladium-system");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,10 +52,6 @@ void GfxOpenGL3::SysInit() {
|
|||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
PDLOG(
|
|
||||||
"GfxOpenGL3::SysInit():\n pShader = {}\n pLocTex = {}\n pLocAlfa = "
|
|
||||||
"{}\n pLocProjection = {}\n VBO = {}\n IBO = {}, VAO = {}",
|
|
||||||
pShader, pLocTex, pLocAlfa, pLocProjection, VBO, IBO, VAO);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GfxOpenGL3::SysDeinit() {
|
void GfxOpenGL3::SysDeinit() {
|
||||||
@@ -142,7 +138,7 @@ void GfxOpenGL3::DeleteTexture(const Li::Texture& tex) {
|
|||||||
#else
|
#else
|
||||||
namespace PD {
|
namespace PD {
|
||||||
void GfxOpenGL3::SysInit() {
|
void GfxOpenGL3::SysInit() {
|
||||||
PDLOG(
|
PDERR(
|
||||||
"GfxOpenGL3::SysInit: OpenGL3 Driver is not included in "
|
"GfxOpenGL3::SysInit: OpenGL3 Driver is not included in "
|
||||||
"palladium-system");
|
"palladium-system");
|
||||||
}
|
}
|
||||||
|
|||||||
+42
-2
@@ -23,6 +23,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if defined(__GNUG__) && !defined(_MSC_VER)
|
||||||
|
#include <cxxabi.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@@ -39,6 +43,11 @@ SOFTWARE.
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
|
enum class LogLevel {
|
||||||
|
Info,
|
||||||
|
Warning,
|
||||||
|
Error,
|
||||||
|
};
|
||||||
[[noreturn]] inline void Throw(const std::string& msg) {
|
[[noreturn]] inline void Throw(const std::string& msg) {
|
||||||
throw std::runtime_error(msg);
|
throw std::runtime_error(msg);
|
||||||
}
|
}
|
||||||
@@ -47,17 +56,48 @@ using u16 = unsigned short;
|
|||||||
using u32 = unsigned int;
|
using u32 = unsigned int;
|
||||||
using u64 = unsigned long long;
|
using u64 = unsigned long long;
|
||||||
using ptr = uintptr_t;
|
using ptr = uintptr_t;
|
||||||
PD_API void Log(const std::string& txt);
|
PD_API void Log(const std::string& txt, LogLevel lvl = LogLevel::Info);
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
void Log(std::format_string<Args...> fmt, Args&&... args) {
|
void Log(std::format_string<Args...> fmt, Args&&... args) {
|
||||||
std::string msg = std::format(fmt, std::forward<Args>(args)...);
|
std::string msg = std::format(fmt, std::forward<Args>(args)...);
|
||||||
Log(msg);
|
Log(msg, LogLevel::Info);
|
||||||
|
}
|
||||||
|
template <typename... Args>
|
||||||
|
void Log(LogLevel lvl, std::format_string<Args...> fmt, Args&&... args) {
|
||||||
|
std::string msg = std::format(fmt, std::forward<Args>(args)...);
|
||||||
|
Log(msg, lvl);
|
||||||
|
}
|
||||||
|
template <typename T>
|
||||||
|
std::string TypeName() {
|
||||||
|
#if defined(__GNUG__) && !defined(_MSC_VER)
|
||||||
|
int res = 0;
|
||||||
|
std::unique_ptr<char, void (*)(void*)> up{
|
||||||
|
abi::__cxa_demangle(typeid(T).name(), nullptr, nullptr, &res), std::free};
|
||||||
|
return (res == 0) ? up.get() : typeid(T).name();
|
||||||
|
#else
|
||||||
|
return typeid(T).name(); // no demangler available :/
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
|
|
||||||
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
|
#define PDPRETTYFUNC __PRETTY_FUNCTION__
|
||||||
|
#elif defined(_MSC_VER)
|
||||||
|
#define PDPRETTYFUNC __FUNCSIG__
|
||||||
|
#else
|
||||||
|
#define PDPRETTYFUNC __FUNCTION__
|
||||||
|
#endif
|
||||||
#ifdef PD_DEBUG
|
#ifdef PD_DEBUG
|
||||||
#define PDLOG(fmt, ...) \
|
#define PDLOG(fmt, ...) \
|
||||||
PD::Log("[{}:{}]: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
|
PD::Log("[{}:{}]: " fmt, __FILE__, __LINE__, ##__VA_ARGS__)
|
||||||
|
#define PDWARN(fmt, ...) \
|
||||||
|
PD::Log(PD::LogLevel::Warning, "[{}:{}]: " fmt, __FILE__, __LINE__, \
|
||||||
|
##__VA_ARGS__)
|
||||||
|
#define PDERR(fmt, ...) \
|
||||||
|
PD::Log(PD::LogLevel::Error, "[{}:{}]: " fmt, __FILE__, __LINE__, \
|
||||||
|
##__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
#define PDLOG(fmt, ...)
|
#define PDLOG(fmt, ...)
|
||||||
|
#define PDWARN(fmt, ...)
|
||||||
|
#define PDERR(fmt, ...)
|
||||||
#endif
|
#endif
|
||||||
@@ -3,6 +3,11 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <pd/common.hpp>
|
#include <pd/common.hpp>
|
||||||
namespace PD {
|
namespace PD {
|
||||||
|
// lets take use of c++ 20 concepts
|
||||||
|
// https://en.cppreference.com/w/cpp/language/constraints.html
|
||||||
|
template <typename T>
|
||||||
|
concept Resettable = requires(T& v) { v.Reset(); };
|
||||||
|
|
||||||
template <typename T, typename Alloc = std::allocator<T>>
|
template <typename T, typename Alloc = std::allocator<T>>
|
||||||
class Pool {
|
class Pool {
|
||||||
public:
|
public:
|
||||||
@@ -13,6 +18,9 @@ class Pool {
|
|||||||
Pool() = default;
|
Pool() = default;
|
||||||
~Pool() {
|
~Pool() {
|
||||||
if (pData) {
|
if (pData) {
|
||||||
|
for (size_t i = 0; i < pCap; i++) {
|
||||||
|
std::allocator_traits<Alloc>::destroy(pAlloc, &pData[i]);
|
||||||
|
}
|
||||||
pAlloc.deallocate(pData, pCap);
|
pAlloc.deallocate(pData, pCap);
|
||||||
pData = nullptr;
|
pData = nullptr;
|
||||||
}
|
}
|
||||||
@@ -47,6 +55,11 @@ class Pool {
|
|||||||
*e = elem;
|
*e = elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Put(size_t idx, const T& elem) {
|
||||||
|
if (idx >= pCap) ExpandIf(idx);
|
||||||
|
pData[idx] = elem;
|
||||||
|
}
|
||||||
|
|
||||||
void ExpandIf(size_t req) {
|
void ExpandIf(size_t req) {
|
||||||
if ((pPos + req) <= pCap) return;
|
if ((pPos + req) <= pCap) return;
|
||||||
size_t ncap = std::max(pCap * 2, pPos + req);
|
size_t ncap = std::max(pCap * 2, pPos + req);
|
||||||
@@ -56,11 +69,14 @@ class Pool {
|
|||||||
std::allocator_traits<Alloc>::construct(
|
std::allocator_traits<Alloc>::construct(
|
||||||
pAlloc, &nu[i], std::move_if_noexcept(pData[i]));
|
pAlloc, &nu[i], std::move_if_noexcept(pData[i]));
|
||||||
}
|
}
|
||||||
|
for (size_t i = 0; i < pCap; i++) {
|
||||||
|
std::allocator_traits<Alloc>::destroy(pAlloc, &pData[i]);
|
||||||
|
}
|
||||||
pAlloc.deallocate(pData, pCap);
|
pAlloc.deallocate(pData, pCap);
|
||||||
}
|
}
|
||||||
for (size_t i = pPos; i < ncap; i++) {
|
for (size_t i = pPos; i < ncap; i++) {
|
||||||
std::allocator_traits<Alloc>::construct(pAlloc, &nu[i]);
|
std::allocator_traits<Alloc>::construct(pAlloc, &nu[i]);
|
||||||
}
|
}
|
||||||
PDLOG("Pool::ExpandIf({}): {} -> {}", req, pCap, ncap);
|
PDLOG("Pool::ExpandIf({}): {} -> {}", req, pCap, ncap);
|
||||||
pData = nu;
|
pData = nu;
|
||||||
pCap = ncap;
|
pCap = ncap;
|
||||||
@@ -76,6 +92,21 @@ class Pool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResetFast() {
|
||||||
|
if constexpr (Resettable<T>) {
|
||||||
|
for (size_t i = 0; i < pPos; i++) {
|
||||||
|
pData[i].Reset();
|
||||||
|
}
|
||||||
|
} else if constexpr (!std::is_trivially_destructible_v<T>) {
|
||||||
|
PDWARN(
|
||||||
|
"ResetFast should only be executed with a non destructible type or a "
|
||||||
|
"class/struct that has a Reset func! {} is not "
|
||||||
|
"trivially_destructible and has no reset func.",
|
||||||
|
TypeName<T>());
|
||||||
|
}
|
||||||
|
pPos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
size_t size() const { return pPos; }
|
size_t size() const { return pPos; }
|
||||||
size_t capacity() const { return pCap; }
|
size_t capacity() const { return pCap; }
|
||||||
T& at(size_t idx) { return pData[idx]; }
|
T& at(size_t idx) { return pData[idx]; }
|
||||||
@@ -89,7 +120,16 @@ class Pool {
|
|||||||
const T& operator[](size_t idx) const { return at(idx); }
|
const T& operator[](size_t idx) const { return at(idx); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Pool(size_t size) : pCap(size), pPos(0) { pData = pAlloc.allocate(size); }
|
Pool(size_t size) : pCap(size), pPos(0) {
|
||||||
|
pPos = 0;
|
||||||
|
pCap = size;
|
||||||
|
pData = pAlloc.allocate(size);
|
||||||
|
for (size_t i = 0; i < pCap; i++) {
|
||||||
|
std::allocator_traits<Alloc>::construct(pAlloc, &pData[i]);
|
||||||
|
}
|
||||||
|
PDLOG("Pool::Init({})", size);
|
||||||
|
}
|
||||||
|
|
||||||
size_t pCap = 0;
|
size_t pCap = 0;
|
||||||
size_t pPos = 0;
|
size_t pPos = 0;
|
||||||
Alloc pAlloc;
|
Alloc pAlloc;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <pd/core/mat.hpp>
|
#include <pd/core/mat.hpp>
|
||||||
#include <pd/drivers/interface.hpp>
|
#include <pd/drivers/interface.hpp>
|
||||||
#include <pd/lithium/command.hpp>
|
#include <pd/lithium/command.hpp>
|
||||||
|
#include <pd/lithium/pools.hpp>
|
||||||
#include <pd/lithium/texture.hpp>
|
#include <pd/lithium/texture.hpp>
|
||||||
|
|
||||||
using PDBackendFlags = PD::u32;
|
using PDBackendFlags = PD::u32;
|
||||||
@@ -105,12 +106,12 @@ class GfxDriverBase : public GfxDriver {
|
|||||||
auto pIdx = pIdxPool.Allocate(c.IndexCount);
|
auto pIdx = pIdxPool.Allocate(c.IndexCount);
|
||||||
auto pVtx = pVtxPool.Allocate(c.VertexCount);
|
auto pVtx = pVtxPool.Allocate(c.VertexCount);
|
||||||
for (size_t i = 0; i < c.IndexCount; i++) {
|
for (size_t i = 0; i < c.IndexCount; i++) {
|
||||||
pIdx[i] = CurrentVertex + c.FirstIndex[i];
|
pIdx[i] = CurrentVertex + Li::GetIndex(c.FirstIndex + i);
|
||||||
}
|
}
|
||||||
CurrentIndex += c.IndexCount;
|
CurrentIndex += c.IndexCount;
|
||||||
CurrentVertex += c.VertexCount;
|
CurrentVertex += c.VertexCount;
|
||||||
for (size_t i = 0; i < c.VertexCount; i++) {
|
for (size_t i = 0; i < c.VertexCount; i++) {
|
||||||
pVtx[i] = c.FirstVertex[i];
|
pVtx[i] = Li::GetVertex(c.FirstVertex + i);
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
@@ -124,8 +125,8 @@ class GfxDriverBase : public GfxDriver {
|
|||||||
size_t GetVertexPoolSize() const { return pVtxPool.size(); }
|
size_t GetVertexPoolSize() const { return pVtxPool.size(); }
|
||||||
size_t GetIndexPoolSize() const { return pIdxPool.size(); }
|
size_t GetIndexPoolSize() const { return pIdxPool.size(); }
|
||||||
void ResetPools() override {
|
void ResetPools() override {
|
||||||
pVtxPool.Reset();
|
pVtxPool.ResetFast();
|
||||||
pIdxPool.Reset();
|
pIdxPool.ResetFast();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -13,44 +13,58 @@ class Command {
|
|||||||
~Command() {}
|
~Command() {}
|
||||||
|
|
||||||
void Reserve(size_t vtx, size_t idx) {
|
void Reserve(size_t vtx, size_t idx) {
|
||||||
if (!FirstVertex)
|
if (!FirstVertex) {
|
||||||
FirstVertex = AllocateVertices(vtx);
|
FirstVertex = AllocateVertices(vtx, (PD::ptr)this);
|
||||||
else
|
VertexCountMax = vtx;
|
||||||
AllocateVertices(vtx);
|
} else {
|
||||||
if (!FirstIndex)
|
ExpandVertices(vtx, (PD::ptr)this);
|
||||||
FirstIndex = AllocateIndices(idx);
|
VertexCountMax += vtx;
|
||||||
else
|
}
|
||||||
AllocateIndices(idx);
|
if (!FirstIndex) {
|
||||||
|
FirstIndex = AllocateIndices(idx, (PD::ptr)this);
|
||||||
|
IndexCountMax = idx;
|
||||||
|
} else {
|
||||||
|
ExpandVertices(idx, (PD::ptr)this);
|
||||||
|
IndexCountMax += idx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Reset() {
|
void Reset() {
|
||||||
Layer = 0;
|
Layer = 0;
|
||||||
Tex = 0;
|
Tex = 0;
|
||||||
FirstIndex = nullptr;
|
FirstIndex = 0;
|
||||||
FirstVertex = nullptr;
|
FirstVertex = 0;
|
||||||
IndexCount = 0;
|
IndexCount = 0;
|
||||||
VertexCount = 0;
|
VertexCount = 0;
|
||||||
|
VertexCountMax = 0;
|
||||||
|
IndexCountMax = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command& Add(const Vertex& vtx) {
|
Command& Add(const Vertex& vtx) {
|
||||||
FirstVertex[VertexCount++] = vtx;
|
if (VertexCount <= VertexCountMax)
|
||||||
|
PutVertex(FirstVertex + VertexCount++, vtx, (PD::ptr)this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Command& Add(u16 idx) {
|
Command& Add(u16 idx) {
|
||||||
FirstIndex[IndexCount++] = VertexCount + idx;
|
if (IndexCount <= IndexCountMax)
|
||||||
|
PutIndex(FirstIndex + IndexCount++, VertexCount + idx, (PD::ptr)this);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Command& Add(u16 a, u16 b, u16 c) {
|
Command& Add(u16 a, u16 b, u16 c) {
|
||||||
FirstIndex[IndexCount++] = VertexCount + a;
|
if (IndexCount + 3 <= IndexCountMax) {
|
||||||
FirstIndex[IndexCount++] = VertexCount + b;
|
size_t idx = FirstIndex + IndexCount;
|
||||||
FirstIndex[IndexCount++] = VertexCount + c;
|
PutIndex(idx + 0, VertexCount + a, (PD::ptr)this);
|
||||||
|
PutIndex(idx + 1, VertexCount + b, (PD::ptr)this);
|
||||||
|
PutIndex(idx + 2, VertexCount + c, (PD::ptr)this);
|
||||||
|
IndexCount += 3;
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Layer = 0;
|
int Layer = 0;
|
||||||
ptr Tex = 0;
|
ptr Tex = 0;
|
||||||
Vertex* FirstVertex = nullptr;
|
size_t FirstVertex = 0;
|
||||||
u16* FirstIndex = nullptr;
|
size_t FirstIndex = 0;
|
||||||
size_t VertexCount = 0;
|
size_t VertexCount = 0;
|
||||||
size_t IndexCount = 0;
|
size_t IndexCount = 0;
|
||||||
// Todo: implement
|
// Todo: implement
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <pd/lithium/atlas.hpp>
|
#include <pd/lithium/atlas.hpp>
|
||||||
|
#include <pd/lithium/command.hpp>
|
||||||
#include <pd/lithium/rect.hpp>
|
#include <pd/lithium/rect.hpp>
|
||||||
#include <pd/lithium/texture.hpp>
|
#include <pd/lithium/texture.hpp>
|
||||||
#include <pd/lithium/vertex.hpp>
|
#include <pd/lithium/vertex.hpp>
|
||||||
@@ -107,3 +108,15 @@ struct std::formatter<PD::Li::AtlasState> : std::formatter<std::string> {
|
|||||||
return std::format_to(ctx.out(), "{}", ret);
|
return std::format_to(ctx.out(), "{}", ret);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct std::formatter<PD::Li::Command> : std::formatter<std::string> {
|
||||||
|
constexpr auto parse(std::format_parse_context& ctx) { return ctx.begin(); }
|
||||||
|
|
||||||
|
template <typename FormatContext>
|
||||||
|
auto format(const PD::Li::Command& value, FormatContext& ctx) const {
|
||||||
|
return std::format_to(ctx.out(), "[0x{:X}, 0x{:X}] [{}, {}] 0x{:X}",
|
||||||
|
(PD::ptr)value.FirstVertex, (PD::ptr)value.FirstIndex,
|
||||||
|
value.VertexCount, value.IndexCount, value.Tex);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -5,8 +5,22 @@
|
|||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
namespace Li {
|
namespace Li {
|
||||||
PD_API Vertex* AllocateVertices(size_t count);
|
/**
|
||||||
PD_API u16* AllocateIndices(size_t count);
|
* Allocate an amount of vertices
|
||||||
|
* returns the index of the first vertex
|
||||||
|
*/
|
||||||
|
PD_API size_t AllocateVertices(size_t count, PD::ptr accessor);
|
||||||
|
/**
|
||||||
|
* Allocate an amount of indices
|
||||||
|
* returns the index of the first elem
|
||||||
|
*/
|
||||||
|
PD_API size_t AllocateIndices(size_t count, PD::ptr accessor);
|
||||||
|
PD_API bool ExpandVertices(size_t count, PD::ptr accessor);
|
||||||
|
PD_API bool EcpandIndices(size_t count, PD::ptr accessor);
|
||||||
|
PD_API void PutVertex(size_t loc, const Vertex& vtx, PD::ptr accessor);
|
||||||
|
PD_API void PutIndex(size_t loc, u16 idx, PD::ptr accessor);
|
||||||
|
PD_API const Vertex& GetVertex(size_t loc);
|
||||||
|
PD_API const u16& GetIndex(size_t loc);
|
||||||
PD_API void ResetPools();
|
PD_API void ResetPools();
|
||||||
} // namespace Li
|
} // namespace Li
|
||||||
} // namespace PD
|
} // namespace PD
|
||||||
@@ -11,6 +11,12 @@ class Vertex {
|
|||||||
: pos(pos), uv(uv), color(color) {}
|
: pos(pos), uv(uv), color(color) {}
|
||||||
~Vertex() {}
|
~Vertex() {}
|
||||||
|
|
||||||
|
void Reset() {
|
||||||
|
pos = fvec2(0.f);
|
||||||
|
uv = fvec2(0.f);
|
||||||
|
color = 0x00000000;
|
||||||
|
}
|
||||||
|
|
||||||
fvec2 pos;
|
fvec2 pos;
|
||||||
fvec2 uv;
|
fvec2 uv;
|
||||||
u32 color = 0x00000000;
|
u32 color = 0x00000000;
|
||||||
|
|||||||
+26
-2
@@ -1,6 +1,30 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <pd/common.hpp>
|
#include <pd/common.hpp>
|
||||||
|
|
||||||
PD_API void PD::Log(const std::string& txt) {
|
namespace PD {
|
||||||
std::cout << "[PD] " << txt << std::endl;
|
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() {
|
PD_API GfxDriver::~GfxDriver() {
|
||||||
if (pTextureRegestry.size()) {
|
if (pTextureRegestry.size()) {
|
||||||
PDLOG("GfxDriver: {} is still holding {} texture{}!", GetName(),
|
PDERR("GfxDriver: {} is still holding {} texture{}!", GetName(),
|
||||||
pTextureRegestry.size(), (pTextureRegestry.size() == 1 ? "" : "s"));
|
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()));
|
pTextureRegestry.erase(pTextureRegestry.find(tex.GetID()));
|
||||||
PDLOG("GfxDriver: Texture {{ {} }} has been deleted!", tex);
|
PDLOG("GfxDriver: Texture {{ {} }} has been deleted!", tex);
|
||||||
} else {
|
} else {
|
||||||
PDLOG("GfxDriver: WARNING Texture {{ {} }} does not exist in regestry!",
|
PDWARN("GfxDriver: WARNING Texture {{ {} }} does not exist in regestry!",
|
||||||
tex);
|
tex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
#include <iostream>
|
||||||
#include <pd/drivers/gfx.hpp>
|
#include <pd/drivers/gfx.hpp>
|
||||||
#include <pd/lithium/drawlist.hpp>
|
#include <pd/lithium/drawlist.hpp>
|
||||||
|
#include <pd/lithium/formatters.hpp>
|
||||||
#include <pd/lithium/math.hpp>
|
#include <pd/lithium/math.hpp>
|
||||||
|
|
||||||
namespace PD {
|
namespace PD {
|
||||||
@@ -16,9 +18,10 @@ PD_API void Drawlist::Optimize() {}
|
|||||||
|
|
||||||
PD_API void Drawlist::Clear() {
|
PD_API void Drawlist::Clear() {
|
||||||
UnbindTexture();
|
UnbindTexture();
|
||||||
pPath.Reset();
|
pPath.ResetFast();
|
||||||
pVertices.Reset();
|
pVertices.ResetFast();
|
||||||
pIndices.Reset();
|
pIndices.ResetFast();
|
||||||
|
pCommands.ResetFast();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Command Allocation */
|
/** 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);
|
uv_tl.y + ((points[i].y - minY) / (maxY - minY)) * (uv_bl.y - uv_tl.y);
|
||||||
cmd.Add(Vertex(points[i], fvec2(u, v), color));
|
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,
|
PD_API void Drawlist::PrimQuad(Command& cmd, const Rect& quad, const Rect& uv,
|
||||||
|
|||||||
@@ -5,12 +5,56 @@ namespace PD {
|
|||||||
namespace Li {
|
namespace Li {
|
||||||
PD::Pool<Vertex> pVtxPool;
|
PD::Pool<Vertex> pVtxPool;
|
||||||
PD::Pool<u16> pIdxPool;
|
PD::Pool<u16> pIdxPool;
|
||||||
|
PD::ptr pVertexAccessor = 0;
|
||||||
|
PD::ptr pIndexAccessor = 0;
|
||||||
|
|
||||||
PD_API Vertex* AllocateVertices(size_t count) {
|
PD_API size_t AllocateVertices(size_t count, PD::ptr accessor) {
|
||||||
return pVtxPool.Allocate(count);
|
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() {
|
PD_API void ResetPools() {
|
||||||
pVtxPool.Reset();
|
pVtxPool.Reset();
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ class App {
|
|||||||
pList.DrawRectFilled(0, 50, 0xff00ffff);
|
pList.DrawRectFilled(0, 50, 0xff00ffff);
|
||||||
pList.BindTexture(pTex);
|
pList.BindTexture(pTex);
|
||||||
pList.DrawRectFilled(50, pTex.GetSize(), 0xffffffff);
|
pList.DrawRectFilled(50, pTex.GetSize(), 0xffffffff);
|
||||||
pList.DrawCircleFilled(500, 100, 0xffffffff, 50);
|
pList.DrawCircleFilled(PD::fvec2(700, 500), 100, 0xffffffff, 50);
|
||||||
// pList.PathRect(300, 700, 40.f);
|
// pList.PathRect(300, 700, 40.f);
|
||||||
// pList.PathFill(0xffffffff);
|
// pList.PathFill(0xffffffff);
|
||||||
std::cout << "GfxDriver: " << PD::Gfx::GetDriverName() << std::endl;
|
std::cout << "GfxDriver: " << PD::Gfx::GetDriverName() << std::endl;
|
||||||
|
|||||||
Reference in New Issue
Block a user