Add Nee Backend Structure

Use TexAddress instead of Texture::Ref in Cmds
Add a .clang-format??
This commit is contained in:
2026-01-25 00:04:40 +01:00
parent da79db223f
commit d2806b2061
8 changed files with 594 additions and 44 deletions

View File

@@ -91,7 +91,7 @@ PD_LITHIUM_API void DrawList::Optimize() {
PD_LITHIUM_API Command::Ref DrawList::GetNewCmd() {
Command::Ref cmd = pPool.NewCmd();
cmd->Index = pPool.Size() - 1;
cmd->Tex = CurrentTex;
cmd->Tex = CurrentTex->Address;
pClipCmd(cmd);
return cmd;
}
@@ -103,7 +103,7 @@ PD_LITHIUM_API void DrawList::pClipCmd(Command::Ref cmd) {
}
}
PD_LITHIUM_API void DrawList::PathArcToN(const fvec2 &c, float radius,
PD_LITHIUM_API void DrawList::PathArcToN(const fvec2& c, float radius,
float a_min, float a_max,
int segments) {
// Path.push_back(c);
@@ -114,7 +114,7 @@ PD_LITHIUM_API void DrawList::PathArcToN(const fvec2 &c, float radius,
}
}
PD_LITHIUM_API void DrawList::PathFastArcToN(const fvec2 &c, float r,
PD_LITHIUM_API void DrawList::PathFastArcToN(const fvec2& c, float r,
float amin, float amax, int s) {
/**
* Funcion with less division overhead
@@ -210,19 +210,19 @@ PD_LITHIUM_API void DrawList::PathRectEx(fvec2 a, fvec2 b, float rounding,
}
}
PD_LITHIUM_API void DrawList::DrawRect(const fvec2 &pos, const fvec2 &size,
PD_LITHIUM_API void DrawList::DrawRect(const fvec2& pos, const fvec2& size,
u32 color, int thickness) {
PathRect(pos, pos + size);
// Flags is currently hardcoded (1 = close)
PathStroke(color, thickness, 1);
}
void DrawList::DrawRectFilled(const fvec2 &pos, const fvec2 &size, u32 color) {
void DrawList::DrawRectFilled(const fvec2& pos, const fvec2& size, u32 color) {
PathRect(pos, pos + size);
PathFill(color);
}
PD_LITHIUM_API void DrawList::DrawTriangle(const fvec2 &a, const fvec2 &b,
const fvec2 &c, u32 color,
PD_LITHIUM_API void DrawList::DrawTriangle(const fvec2& a, const fvec2& b,
const fvec2& c, u32 color,
int thickness) {
PathAdd(a);
PathAdd(b);
@@ -230,15 +230,15 @@ PD_LITHIUM_API void DrawList::DrawTriangle(const fvec2 &a, const fvec2 &b,
PathStroke(color, thickness, 1);
}
PD_LITHIUM_API void DrawList::DrawTriangleFilled(const fvec2 &a, const fvec2 &b,
const fvec2 &c, u32 color) {
PD_LITHIUM_API void DrawList::DrawTriangleFilled(const fvec2& a, const fvec2& b,
const fvec2& c, u32 color) {
PathAdd(a);
PathAdd(b);
PathAdd(c);
PathFill(color);
}
PD_LITHIUM_API void DrawList::DrawCircle(const fvec2 &center, float rad,
PD_LITHIUM_API void DrawList::DrawCircle(const fvec2& center, float rad,
u32 color, int num_segments,
int thickness) {
if (num_segments <= 0) {
@@ -251,7 +251,7 @@ PD_LITHIUM_API void DrawList::DrawCircle(const fvec2 &center, float rad,
PathStroke(color, thickness, (1 << 0));
}
PD_LITHIUM_API void DrawList::DrawCircleFilled(const fvec2 &center, float rad,
PD_LITHIUM_API void DrawList::DrawCircleFilled(const fvec2& center, float rad,
u32 color, int num_segments) {
if (num_segments <= 0) {
// Auto Segment
@@ -263,7 +263,7 @@ PD_LITHIUM_API void DrawList::DrawCircleFilled(const fvec2 &center, float rad,
}
// TODO: Don't render OOS
PD_LITHIUM_API void DrawList::DrawPolyLine(const std::vector<fvec2> &points,
PD_LITHIUM_API void DrawList::DrawPolyLine(const std::vector<fvec2>& points,
u32 clr, u32 flags, int thickness) {
if (points.size() < 2) {
return;
@@ -285,7 +285,7 @@ PD_LITHIUM_API void DrawList::DrawPolyLine(const std::vector<fvec2> &points,
}
PD_LITHIUM_API void DrawList::DrawConvexPolyFilled(
const std::vector<fvec2> &points, u32 clr) {
const std::vector<fvec2>& points, u32 clr) {
if (points.size() < 3) {
return; // Need at least three points
}
@@ -293,24 +293,24 @@ PD_LITHIUM_API void DrawList::DrawConvexPolyFilled(
Renderer::CmdConvexPolyFilled(cmd, points, clr, CurrentTex);
}
PD_LITHIUM_API void DrawList::DrawText(const fvec2 &pos,
const std::string &text, u32 color) {
PD_LITHIUM_API void DrawList::DrawText(const fvec2& pos,
const std::string& text, u32 color) {
if (!pCurrentFont) {
return;
}
pCurrentFont->CmdTextEx(pPool, pos, color, pFontScale, text);
}
PD_LITHIUM_API void DrawList::DrawTextEx(const fvec2 &p,
const std::string &text, u32 color,
LiTextFlags flags, const fvec2 &box) {
PD_LITHIUM_API void DrawList::DrawTextEx(const fvec2& p,
const std::string& text, u32 color,
LiTextFlags flags, const fvec2& box) {
if (!pCurrentFont) {
return;
}
pCurrentFont->CmdTextEx(pPool, p, color, pFontScale, text, flags, box);
}
PD_LITHIUM_API void DrawList::DrawLine(const fvec2 &a, const fvec2 &b,
PD_LITHIUM_API void DrawList::DrawLine(const fvec2& a, const fvec2& b,
u32 color, int t) {
PathAdd(a);
PathAdd(b);

View File

@@ -49,7 +49,7 @@ PD_LITHIUM_API void Font::LoadDefaultFont(int id, int pixel_height) {
#endif
}
PD_LITHIUM_API void Font::LoadTTF(const std::string &path, int height) {
PD_LITHIUM_API void Font::LoadTTF(const std::string& path, int height) {
/**
* Just use LoadFile2Mem which looks way cleaner
* and helps not having the font loading code twice
@@ -60,7 +60,7 @@ PD_LITHIUM_API void Font::LoadTTF(const std::string &path, int height) {
LoadTTF(font, height);
}
PD_LITHIUM_API void Font::pMakeAtlas(bool final, std::vector<u8> &font_tex,
PD_LITHIUM_API void Font::pMakeAtlas(bool final, std::vector<u8>& font_tex,
int texszs, PD::Li::Texture::Ref tex) {
auto t =
Gfx::LoadTex(font_tex, texszs, texszs, Texture::RGBA32, Texture::LINEAR);
@@ -68,7 +68,7 @@ PD_LITHIUM_API void Font::pMakeAtlas(bool final, std::vector<u8> &font_tex,
Textures.push_back(tex);
}
PD_LITHIUM_API void Font::LoadTTF(const std::vector<u8> &data, int height) {
PD_LITHIUM_API void Font::LoadTTF(const std::vector<u8>& data, int height) {
/**
* Some additional Info:
* Removed the stbtt get bitmapbox as we dont need to place
@@ -107,7 +107,7 @@ PD_LITHIUM_API void Font::LoadTTF(const std::vector<u8> &data, int height) {
if (stbtt_IsGlyphEmpty(&inf, gi)) continue;
int w = 0, h = 0, xo = 0, yo = 0;
unsigned char *bitmap =
unsigned char* bitmap =
stbtt_GetCodepointBitmap(&inf, scale, scale, ii, &w, &h, &xo, &yo);
if (!bitmap || w <= 0 || h <= 0) {
if (bitmap) free(bitmap);
@@ -184,7 +184,7 @@ PD_LITHIUM_API void Font::LoadTTF(const std::vector<u8> &data, int height) {
}
}
PD_LITHIUM_API Font::Codepoint &Font::GetCodepoint(u32 cp) {
PD_LITHIUM_API Font::Codepoint& Font::GetCodepoint(u32 cp) {
// Check if codepoijt exist or return a static invalid one
auto res = CodeMap.find(cp);
if (res == CodeMap.end()) {
@@ -195,7 +195,7 @@ PD_LITHIUM_API Font::Codepoint &Font::GetCodepoint(u32 cp) {
return res->second;
}
PD_LITHIUM_API fvec2 Font::GetTextBounds(const std::string &text, float scale) {
PD_LITHIUM_API fvec2 Font::GetTextBounds(const std::string& text, float scale) {
u32 id = PD::FNV1A32(text);
if (pTMS.find(id) != pTMS.end()) {
pTMS[id].TimeStamp = PD::OS::GetTime();
@@ -210,7 +210,7 @@ PD_LITHIUM_API fvec2 Font::GetTextBounds(const std::string &text, float scale) {
float cfs = (DefaultPixelHeight * scale) / (float)PixelHeight;
float lh = (float)PixelHeight * cfs;
size_t index = 0;
for (auto &it : wtext) {
for (auto& it : wtext) {
if (it == L'\0') {
break;
}
@@ -248,9 +248,9 @@ PD_LITHIUM_API fvec2 Font::GetTextBounds(const std::string &text, float scale) {
return res;
}
PD_LITHIUM_API void Font::CmdTextEx(CmdPool &cmds, const fvec2 &pos, u32 color,
float scale, const std::string &text,
LiTextFlags flags, const fvec2 &box) {
PD_LITHIUM_API void Font::CmdTextEx(CmdPool& cmds, const fvec2& pos, u32 color,
float scale, const std::string& text,
LiTextFlags flags, const fvec2& box) {
fvec2 off;
float cfs = (DefaultPixelHeight * scale) / (float)PixelHeight;
float lh = (float)PixelHeight * cfs;
@@ -278,7 +278,7 @@ PD_LITHIUM_API void Font::CmdTextEx(CmdPool &cmds, const fvec2 &pos, u32 color,
lines.push_back(tmp);
}
for (auto &it : lines) {
for (auto& it : lines) {
if (flags & LiTextFlags_NoOOS) {
if (rpos.y + off.y + lh < 0) {
off.y += lh;
@@ -295,8 +295,10 @@ PD_LITHIUM_API void Font::CmdTextEx(CmdPool &cmds, const fvec2 &pos, u32 color,
auto wline = Strings::MakeWstring(it);
auto cmd = cmds.NewCmd();
auto Tex = GetCodepoint(wline[0]).Tex;
cmd->Tex = Tex;
for (auto &jt : wline) {
if (Tex) {
cmd->Tex = Tex->Address;
}
for (auto& jt : wline) {
auto cp = GetCodepoint(jt);
if ((cp.pInvalid && jt != L' ' && jt != L'\n' && jt != L'\t') &&
jt != L'\r') {
@@ -305,7 +307,9 @@ PD_LITHIUM_API void Font::CmdTextEx(CmdPool &cmds, const fvec2 &pos, u32 color,
if (Tex != cp.Tex) {
cmd = cmds.NewCmd();
Tex = cp.Tex;
cmd->Tex = Tex;
if (Tex) {
cmd->Tex = Tex->Address;
}
}
if (jt == L'\t') {
off.x += 16 * cfs;
@@ -314,7 +318,7 @@ PD_LITHIUM_API void Font::CmdTextEx(CmdPool &cmds, const fvec2 &pos, u32 color,
if (flags & LiTextFlags_Shaddow) {
// Draw
Rect rec = Renderer::PrimRect(
rpos + vec2(off.x + 1, off.y + (cp.Offset * cfs)) + 1,
rpos + fvec2(off.x + 1, off.y + (cp.Offset * cfs)) + 1,
cp.Size * cfs, 0.f);
Renderer::CmdQuad(cmd, rec, cp.SimpleUV, 0xff111111);
}
@@ -333,9 +337,9 @@ PD_LITHIUM_API void Font::CmdTextEx(CmdPool &cmds, const fvec2 &pos, u32 color,
}
}
PD_LITHIUM_API std::string Font::pWrapText(const std::string &txt, float scale,
const PD::fvec2 &max,
PD::fvec2 &dim) {
PD_LITHIUM_API std::string Font::pWrapText(const std::string& txt, float scale,
const PD::fvec2& max,
PD::fvec2& dim) {
u32 id = PD::FNV1A32(txt);
if (pTMS.find(id) != pTMS.end()) {
if (pTMS[id].Text.size()) {
@@ -370,9 +374,9 @@ PD_LITHIUM_API std::string Font::pWrapText(const std::string &txt, float scale,
return ret;
}
PD_LITHIUM_API std::string Font::pShortText(const std::string &txt, float scale,
const PD::fvec2 &max,
PD::fvec2 &dim) {
PD_LITHIUM_API std::string Font::pShortText(const std::string& txt, float scale,
const PD::fvec2& max,
PD::fvec2& dim) {
u32 id = PD::FNV1A32(txt);
if (pTMS.find(id) != pTMS.end()) {
if (pTMS[id].Text.size()) {
@@ -398,7 +402,7 @@ PD_LITHIUM_API std::string Font::pShortText(const std::string &txt, float scale,
maxlen -= GetTextBounds(ext, scale).x;
maxlen -= GetTextBounds(ph, scale).x;
for (auto &it : tmp) {
for (auto& it : tmp) {
if (GetTextBounds(ret, scale).x > maxlen) {
ret += ph;
ret += ext;