Get it finally working (somehow)

- Add working example
- Add Namespace defs for Iron Ctr and C3D
- Add Exit func / Vertex / Index counter to Iron
- Add format bytes function to utils
- Make stb_image optional
- Compute texture uv's
- Clear Everything in Drawlist::Clear
- Use Amy::mat4 as matrix lib
- Fix the most stupid rendering bug (i -> m_idx)
This commit is contained in:
2025-12-01 22:10:18 +01:00
parent 078af99ae5
commit 777b23f4c8
15 changed files with 138 additions and 376 deletions

View File

@@ -16,24 +16,32 @@ enum LiPathRectFlags_ : Amy::ui {
namespace Amy {
constexpr auto __pi = std::numbers::pi;
void Iron::Drawlist::Merge(Iron::Drawlist *list) {
void Iron::Drawlist::Merge(Iron::Drawlist* list) {
for (size_t i = 0; i < list->pData.size(); i++) {
pData.push_back(std::move(list->pData[i]));
}
list->Clear();
}
void Iron::Drawlist::Clear() { pData.clear(); }
void Iron::Drawlist::Clear() {
pData.clear();
pPath.clear();
DrawSolid();
while (!ClipRects.empty()) {
ClipRects.pop();
}
pLayer = 0;
}
Iron::Command::ref Iron::Drawlist::NewCommand() {
auto ret = std::make_unique<Command>();
ret->Layer = pLayer;
ret->Index = pData.size();
ret->Tex = pTex;
return ret;
return std::move(ret);
}
void Iron::Drawlist::clipCmd(Command *ptr) {
void Iron::Drawlist::clipCmd(Command* ptr) {
if (!ClipRects.empty()) {
ptr->ScissorOn = true;
ptr->ScissorRect = ivec4(ClipRects.top());
@@ -44,7 +52,7 @@ void Iron::Drawlist::Push(Command::ref cmd) { pData.push_back(std::move(cmd)); }
void Iron::Drawlist::DrawSolid() { pTex = Iron::WhiteTex(); }
void Iron::Drawlist::PathArcToN(const fvec2 &c, float radius, float a_min,
void Iron::Drawlist::PathArcToN(const fvec2& c, float radius, float a_min,
float a_max, int segments) {
// pathAdd(c)
PathReserve(segments + 1);
@@ -54,7 +62,7 @@ void Iron::Drawlist::PathArcToN(const fvec2 &c, float radius, float a_min,
}
}
void Iron::Drawlist::PathFastArcToN(const fvec2 &c, float r, float amin,
void Iron::Drawlist::PathFastArcToN(const fvec2& c, float r, float amin,
float amax, int s) {
/**
* Funcion with less division overhead
@@ -68,7 +76,7 @@ void Iron::Drawlist::PathFastArcToN(const fvec2 &c, float r, float amin,
}
}
void Iron::Drawlist::PathRect(const fvec2 &a, const fvec2 &b, float rounding) {
void Iron::Drawlist::PathRect(const fvec2& a, const fvec2& b, float rounding) {
if (rounding == 0.f) {
PathAdd(a);
PathAdd(fvec2(b.x, a.y));
@@ -100,7 +108,7 @@ void Iron::Drawlist::PathRect(const fvec2 &a, const fvec2 &b, float rounding) {
}
}
void Iron::Drawlist::PathRectEx(const fvec2 &a, const fvec2 &b, float rounding,
void Iron::Drawlist::PathRectEx(const fvec2& a, const fvec2& b, float rounding,
ui flags) {
if (rounding == 0.f) {
PathAdd(a);
@@ -150,35 +158,35 @@ void Iron::Drawlist::PathRectEx(const fvec2 &a, const fvec2 &b, float rounding,
}
}
void Iron::Drawlist::DrawRect(const fvec2 &pos, const fvec2 &size, ui color,
void Iron::Drawlist::DrawRect(const fvec2& pos, const fvec2& size, ui color,
int thickness) {
PathRect(pos, pos + size);
PathStroke(color, thickness, 1);
}
void Iron::Drawlist::DrawRectFilled(const fvec2 &pos, const fvec2 &size,
void Iron::Drawlist::DrawRectFilled(const fvec2& pos, const fvec2& size,
ui color) {
PathRect(pos, pos + size);
PathFill(color);
}
void Iron::Drawlist::DrawTriangle(const fvec2 &a, const fvec2 &b,
const fvec2 &c, ui color, int thickness) {
void Iron::Drawlist::DrawTriangle(const fvec2& a, const fvec2& b,
const fvec2& c, ui color, int thickness) {
PathAdd(a);
PathAdd(b);
PathAdd(c);
PathStroke(color, thickness, 1);
}
void Iron::Drawlist::DrawTriangleFilled(const fvec2 &a, const fvec2 &b,
const fvec2 &c, ui color) {
void Iron::Drawlist::DrawTriangleFilled(const fvec2& a, const fvec2& b,
const fvec2& c, ui color) {
PathAdd(a);
PathAdd(b);
PathAdd(c);
PathFill(color);
}
void Iron::Drawlist::DrawCircle(const fvec2 &center, float rad, ui color,
void Iron::Drawlist::DrawCircle(const fvec2& center, float rad, ui color,
int segments, int thickness) {
if (segments <= 0) {
// Auto Segment
@@ -186,11 +194,11 @@ void Iron::Drawlist::DrawCircle(const fvec2 &center, float rad, ui color,
float am = (__pi * 2.0f) * ((float)segments) / (float)segments;
PathArcToN(center, rad, 0.f, am, segments);
}
DrawSolid(); // Only Solid Color Supported
DrawSolid(); // Only Solid Color Supported
PathStroke(color, thickness, 1);
}
void Iron::Drawlist::DrawCircleFilled(const fvec2 &center, float rad, ui color,
void Iron::Drawlist::DrawCircleFilled(const fvec2& center, float rad, ui color,
int segments) {
if (segments <= 0) {
// Auto Segment
@@ -201,7 +209,7 @@ void Iron::Drawlist::DrawCircleFilled(const fvec2 &center, float rad, ui color,
PathFill(color);
}
void Iron::Drawlist::DrawPolyLine(const std::vector<fvec2> &points, ui clr,
void Iron::Drawlist::DrawPolyLine(const std::vector<fvec2>& points, ui clr,
ui flags, int thickness) {
if (points.size() < 2) {
return;
@@ -223,17 +231,17 @@ void Iron::Drawlist::DrawPolyLine(const std::vector<fvec2> &points, ui clr,
Push(std::move(cmd));
}
void Iron::Drawlist::DrawConvexPolyFilled(const std::vector<fvec2> &points,
void Iron::Drawlist::DrawConvexPolyFilled(const std::vector<fvec2>& points,
ui clr) {
if (points.size() < 3) {
return; // Need at least three points
return; // Need at least three points
}
auto cmd = NewCommand();
CmdConvexPolyFilled(cmd.get(), points, clr, pTex);
Push(std::move(cmd));
}
void Iron::Drawlist::DrawText(const fvec2 &pos, const std::string &text,
void Iron::Drawlist::DrawText(const fvec2& pos, const std::string& text,
ui color) {
/*if (!pCurrentFont) {
return;
@@ -247,8 +255,8 @@ void Iron::Drawlist::DrawText(const fvec2 &pos, const std::string &text,
}*/
}
void Iron::Drawlist::DrawTextEx(const fvec2 &p, const std::string &text,
ui color, ui flags, const fvec2 &box) {
void Iron::Drawlist::DrawTextEx(const fvec2& p, const std::string& text,
ui color, ui flags, const fvec2& box) {
/*if (!pCurrentFont) {
return;
}
@@ -261,9 +269,9 @@ void Iron::Drawlist::DrawTextEx(const fvec2 &p, const std::string &text,
}*/
}
void Iron::Drawlist::DrawLine(const fvec2 &a, const fvec2 &b, ui color, int t) {
void Iron::Drawlist::DrawLine(const fvec2& a, const fvec2& b, ui color, int t) {
PathAdd(a);
PathAdd(b);
PathStroke(color, t);
}
} // namespace Amy
} // namespace Amy

View File

@@ -3,18 +3,6 @@
#include <fstream>
#include <iostream>
#define catch2() \
; \
({ \
std::cout << std::format("{}:{}", __FILE__, __LINE__) << std::endl; \
while (aptMainLoop()) { \
hidScanInput(); \
if (hidKeysDown() & KEY_A) { \
break; \
} \
} \
})
namespace Amy {
const char* __ironshader__ = R"(; LI7 Shader
; Constants
@@ -64,7 +52,8 @@ C3D::Shader* Iron::m_shader = nullptr;
mat4 Iron::m_mtx;
int Iron::m_idx = 0, Iron::m_vtx = 0;
Texture* Iron::m_solid = nullptr;
C3D_Mtx __m;
ui Iron::VertexCount = 0;
ui Iron::IndexCount = 0;
void Iron::Init() {
pSetupShader();
@@ -73,20 +62,25 @@ void Iron::Init() {
pInitSolidTex();
}
void Iron::Exit() {
delete m_solid;
delete m_shader;
m_vbuf.clear();
m_ibuf.clear();
}
void Iron::NewFrame() {
VertexCount = m_vtx;
IndexCount = m_idx;
m_idx = 0;
m_vtx = 0;
}
void Iron::DrawOn(C3D::Screen* screen) {
m_shader->Use();
Mtx_Identity(&__m);
Mtx_OrthoTilt(&__m, 0, (float)screen->Width(), (float)screen->Height(), 0.f,
1.f, -1.f, true);
// m_mtx = mat4::ortho(0.f, (float)screen->Width(), (float)screen->Height(),
// 0.f,
// 1.f, -1.f);
m_shader->SetMat4(uLocProj, &__m);
m_mtx = mat4::ortho(0.f, (float)screen->Width(), (float)screen->Height(), 0.f,
1.f, -1.f);
m_shader->SetMat4(uLocProj, m_mtx);
}
void Iron::Draw(const std::vector<Iron::Command::ref>& data) {
@@ -102,7 +96,7 @@ void Iron::Draw(const std::vector<Iron::Command::ref>& data) {
}
auto scissorOn = data[i]->ScissorOn;
auto scissor = data[i]->ScissorRect;
auto start = i;
auto start = m_idx;
// Loop until a statgechange and copy all data into Vertex/index buf
while (i < data.size() && scissorOn == data[i]->ScissorOn &&
@@ -119,7 +113,7 @@ void Iron::Draw(const std::vector<Iron::Command::ref>& data) {
m_ibuf[m_idx++] = m_vtx + c->IndexBuf[j];
}
for (int j = 0; j < c->VertexBuf.size(); j++) {
m_vbuf[m_vtx++] = c->VertexBuf[j];
m_vbuf[m_vtx++] = std::move(c->VertexBuf[j]);
}
i++;
}
@@ -127,17 +121,9 @@ void Iron::Draw(const std::vector<Iron::Command::ref>& data) {
///// SCISSOR LOGIC END /////
tex->Bind();
C3D::BufCfg<3>(m_vbuf.data(), sizeof(Vertex));
C3D::DrawElements(i - start, m_ibuf.data() + start);
C3D::DrawElements(m_idx - start, m_ibuf.data() + start);
}
C3D::DepthTest(true);
/*std::ofstream off("hello.txt");
for (int i = 0; i < m_idx; i++) {
auto& v = m_vbuf[m_ibuf[i]];
off << std::format("{} -> [{}] [{}] #{:08X}\n", m_ibuf[i], v.pos, v.uv,
v.color);
}
off.close();
throw std::runtime_error("halt");*/
}
bool Iron::pCheckSize(size_t idx, size_t vtx) {
@@ -153,12 +139,13 @@ void Iron::pSetupShader() {
AttrInfo_AddLoader(&m_shader->pInfo, 0, GPU_FLOAT, 2);
AttrInfo_AddLoader(&m_shader->pInfo, 1, GPU_FLOAT, 2);
AttrInfo_AddLoader(&m_shader->pInfo, 2, GPU_UNSIGNED_BYTE, 4);
/* m_shader->Load("romfs:/shaders/lithium.shbin");
// m_shader->Compile(__ironshader__);
m_shader->Input(GPU_FLOAT, 2); // pos
m_shader->Input(GPU_FLOAT, 2); // uv
m_shader->Input(GPU_UNSIGNED_BYTE, 4); // color*/
uLocProj = m_shader->loc("projection");
// TODO: FUNKTIONIRT NICHT AHHHHHHHHHH
/*m_shader->Load("romfs:/shaders/lithium.shbin");
// m_shader->Compile(__ironshader__);
m_shader->Input(GPU_FLOAT, 2); // pos
m_shader->Input(GPU_FLOAT, 2); // uv
m_shader->Input(GPU_UNSIGNED_BYTE, 4); // color
uLocProj = m_shader->loc("projection");*/
}
void Iron::pFragConfig() {