8 Commits
Author SHA1 Message Date
tobid7 6547f64d13 fix resize sym 2026-09-18 22:11:08 +02:00
tobid7 2b37204763 remove Font::LoadDefaultFont 2026-09-17 21:35:19 +02:00
tobid7 8c2bcedc93 Testing around 2026-09-16 21:20:45 +02:00
tobid7 01d3eb771e remove the 3ds ifdefs out of the core mat lib
need to find a way to handle mtx stuff in the gfx driver or another way
2026-09-15 07:20:00 +02:00
tobid7 6de3683818 3ds: move ui7 to bottom screne 2026-09-13 14:10:07 +02:00
tobid7 ec49f70c0b Add more gfx backend flags (available features) 2026-09-13 01:24:55 +02:00
tobid7 6284ff885d citro3d: clipping 2026-09-13 01:06:23 +02:00
tobid7 91c245c1a6 dx9 clipping 2026-09-12 17:29:48 +02:00
16 changed files with 91 additions and 43 deletions
+10 -1
View File
@@ -141,6 +141,9 @@ void GfxCitro3D::SysInit() {
PDLOG("GfxCitro3D::SysInit();"); PDLOG("GfxCitro3D::SysInit();");
impl = new Impl(); impl = new Impl();
Flags |= PDGfxBackendFlags_FlipUV_Y; Flags |= PDGfxBackendFlags_FlipUV_Y;
Flags |= PDGfxBackendFlags_HasClipRect;
Flags |= PDGfxBackendFlags_ReqPow2;
Flags |= PDGfxBackendFlags_ApproxSDF;
impl->pShaderRaw = Pica::AssembleCode(LIShaderCTR); impl->pShaderRaw = Pica::AssembleCode(LIShaderCTR);
impl->pCode = DVLB_ParseFile((uint32_t*)impl->pShaderRaw.data(), impl->pCode = DVLB_ParseFile((uint32_t*)impl->pShaderRaw.data(),
impl->pShaderRaw.size()); impl->pShaderRaw.size());
@@ -265,7 +268,13 @@ void GfxCitro3D::UploadPools() {
BufInfo_Add(buf, GetVertexBufPtr(0), sizeof(Li::Vertex), 3, 0x210); BufInfo_Add(buf, GetVertexBufPtr(0), sizeof(Li::Vertex), 3, 0x210);
} }
void GfxCitro3D::ClipRect() {} void GfxCitro3D::ClipRect() {
// This is so cursed but it works
C3D_SetScissor(CurrentHasClip ? GPU_SCISSOR_NORMAL : GPU_SCISSOR_DISABLE,
ViewPort.y - CurrentClip.w - CurrentClip.y,
ViewPort.x - CurrentClip.z - CurrentClip.x,
ViewPort.y - CurrentClip.y, ViewPort.x - CurrentClip.x);
}
} // namespace PD } // namespace PD
#else #else
namespace PD { namespace PD {
+15 -1
View File
@@ -112,6 +112,7 @@ void GfxDirectX9::SysInit() {
} }
if (psBlob) psBlob->Release(); if (psBlob) psBlob->Release();
if (errBlob) errBlob->Release(); if (errBlob) errBlob->Release();
Flags |= PDGfxBackendFlags_HasClipRect;
} else { } else {
PDERR( PDERR(
"GfxDirectX9::SysInit Error: pDevice is not set!\nYOu need to include " "GfxDirectX9::SysInit Error: pDevice is not set!\nYOu need to include "
@@ -286,7 +287,20 @@ void GfxDirectX9::UploadPools() {
impl->IBO->Unlock(); impl->IBO->Unlock();
} }
void GfxDirectX9::ClipRect() {} void GfxDirectX9::ClipRect() {
if (CurrentHasClip) {
RECT r;
r.left = CurrentClip.x;
r.top = CurrentClip.y;
r.right = CurrentClip.x + CurrentClip.z;
r.bottom = CurrentClip.y + CurrentClip.w;
impl->Device->SetScissorRect(&r);
impl->Device->SetRenderState(D3DRS_SCISSORTESTENABLE, TRUE);
} else {
impl->Device->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
}
}
} // namespace PD } // namespace PD
#else #else
namespace PD { namespace PD {
+1
View File
@@ -73,6 +73,7 @@ void GfxOpenGL2::pSetupShaderAttribs(u32 shader) {
} }
void GfxOpenGL2::SysInit() { void GfxOpenGL2::SysInit() {
Flags |= PDGfxBackendFlags_HasClipRect;
pShader = CreateShaderProgram(pVertCode, pFragCode); pShader = CreateShaderProgram(pVertCode, pFragCode);
glUseProgram(pShader); glUseProgram(pShader);
glGenBuffers(1, &VBO); glGenBuffers(1, &VBO);
+1
View File
@@ -11,6 +11,7 @@
namespace PD { namespace PD {
void GfxOpenGL3::SysInit() { void GfxOpenGL3::SysInit() {
Flags |= PDGfxBackendFlags_HasClipRect;
std::string vcode = SpirvHelper::SPV2GLSL( std::string vcode = SpirvHelper::SPV2GLSL(
std::vector<unsigned int>( std::vector<unsigned int>(
Shaders::VertexShader, Shaders::VertexShader,
+1 -22
View File
@@ -56,21 +56,9 @@ struct PD_API Mat4 {
constexpr float* Ptr() { return m.data(); } constexpr float* Ptr() { return m.data(); }
constexpr const float* Ptr() const { return m.data(); } constexpr const float* Ptr() const { return m.data(); }
constexpr float& operator()(int row, int col) { constexpr float& operator()(int row, int col) { return m[col * 4 + row]; }
#ifdef __3DS__
// 3ds is full reverse order iirc
return m[row * 4 + (3 - col)];
#else
return m[col * 4 + row];
#endif
}
constexpr float operator()(int row, int col) const { constexpr float operator()(int row, int col) const {
#ifdef __3DS__
// 3ds is full reverse order iirc
return m[row * 4 + (3 - col)];
#else
return m[col * 4 + row]; return m[col * 4 + row];
#endif
} }
constexpr Mat4 operator*(const Mat4& v) const { constexpr Mat4 operator*(const Mat4& v) const {
@@ -122,21 +110,12 @@ struct PD_API Mat4 {
constexpr static Mat4 Ortho(float l, float r, float b, float t, float n, constexpr static Mat4 Ortho(float l, float r, float b, float t, float n,
float f) { float f) {
Mat4 ret; Mat4 ret;
#ifdef __3DS__ // Patch to rotate the Matrix correctly
ret(0, 1) = 2.f / (t - b);
ret(0, 3) = (b + t) / (b - t);
ret(1, 0) = 2.f / (l - r);
ret(1, 3) = (l + r) / (r - l);
ret(2, 2) = 1.f / (n - f);
ret(2, 3) = 0.5f * (n + f) / (n - f) - 0.5f;
#else
ret(0, 0) = 2.0f / (r - l); ret(0, 0) = 2.0f / (r - l);
ret(0, 3) = -(r + l) / (r - l); ret(0, 3) = -(r + l) / (r - l);
ret(1, 1) = 2.0f / (t - b); ret(1, 1) = 2.0f / (t - b);
ret(1, 3) = -(t + b) / (t - b); ret(1, 3) = -(t + b) / (t - b);
ret(2, 2) = -2.0f / (f - n); ret(2, 2) = -2.0f / (f - n);
ret(2, 3) = -(f + n) / (f - n); ret(2, 3) = -(f + n) / (f - n);
#endif
ret(3, 3) = 1.f; ret(3, 3) = 1.f;
return ret; return ret;
} }
+4 -1
View File
@@ -10,7 +10,10 @@ using PDGfxBackendFlags = PD::u32;
enum PDGfxBackendFlags_ { enum PDGfxBackendFlags_ {
PDGfxBackendFlags_None = 0, PDGfxBackendFlags_None = 0,
PDGfxBackendFlags_FlipUV_Y = 1 << 0, // Essential for font loading PDGfxBackendFlags_FlipUV_Y = 1 << 0, // Essential for font loading
PDGfxBackendFlags_WindingCW = 1 << 0, // Use CW instead of CCW winding PDGfxBackendFlags_WindingCW = 1 << 1, // Use CW instead of CCW winding
PDGfxBackendFlags_HasClipRect = 1 << 2, // Clip rects supported
PDGfxBackendFlags_ReqPow2 = 1 << 3, // Tex size must be pow of 2
PDGfxBackendFlags_ApproxSDF = 1 << 4, // Fake SDF for non smoothstep systems
}; };
namespace PD { namespace PD {
-6
View File
@@ -56,12 +56,6 @@ class PD_API Font {
*/ */
void LoadTTF(const std::vector<u8>& data, int px_height = 32, void LoadTTF(const std::vector<u8>& data, int px_height = 32,
LiFontFlags flags = LiFontFlags_None); LiFontFlags flags = LiFontFlags_None);
/**
* Function that loads a default integrated font...
* This will only work if PD_LI_INCLUDE_FONTS was set
* on lithium build cause otherwise the font data is not included
*/
void LoadDefaultFont(int id = 0, int pixel_height = 32);
/** /**
* Getter for Codepoint reference * Getter for Codepoint reference
* @return codepoint dataholder reference * @return codepoint dataholder reference
-5
View File
@@ -85,13 +85,8 @@ PD_API Mat4 Mat4::Perspective(float fov, float aspect, float n, float f) {
Mat4 ret; Mat4 ret;
ret(0, 0) = 1.f / (aspect * _fov); ret(0, 0) = 1.f / (aspect * _fov);
ret(1, 1) = 1.f / _fov; ret(1, 1) = 1.f / _fov;
#ifdef __3DS__
ret(2, 3) = f * n / (n - f);
ret(2, 2) = -(-1.f) * n / (n - f);
#else
ret(2, 2) = -(f + n) / (f - n); ret(2, 2) = -(f + n) / (f - n);
ret(2, 3) = -(2.f * f * n) / (f - n); ret(2, 3) = -(2.f * f * n) / (f - n);
#endif
ret(3, 2) = -1.f; ret(3, 2) = -1.f;
ret(3, 3) = 0.0f; ret(3, 3) = 0.0f;
return ret; return ret;
-2
View File
@@ -195,8 +195,6 @@ PD_API void Font::LoadTTF(const std::vector<u8>& data, int px_height,
} }
} }
PD_API void Font::LoadDefaultFont(int id, int pixel_height) {}
PD_API Font::Codepoint& Font::GetCodepoint(u32 c) { PD_API Font::Codepoint& Font::GetCodepoint(u32 c) {
if (c < 128) { if (c < 128) {
// Direct Access (~11% improvement) // Direct Access (~11% improvement)
+1 -1
View File
@@ -219,7 +219,7 @@ PD_API void Menu::DrawBaseLayout() {
if (!(Flags & UI7MenuFlags_NoResize)) { if (!(Flags & UI7MenuFlags_NoResize)) {
DynObj* r = pIO.DynObjPool.Allocate(); DynObj* r = pIO.DynObjPool.Allocate();
*r = UI7::DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) { *r = UI7::DynObj([](IO* io, Li::Drawlist* l, UI7::Container* self) {
l->SetLayer(1); l->SetLayer(21);
l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(0, 20)); l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(0, 20));
l->PathAdd(self->FinalPos() + self->GetSize()); l->PathAdd(self->FinalPos() + self->GetSize());
l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(20, 0)); l->PathAdd(self->FinalPos() + self->GetSize() - fvec2(20, 0));
+11 -1
View File
@@ -207,7 +207,17 @@ PD_API void Context::MetricsMenu(bool* show) {
} }
m->SeparatorText("Palladium Info"); m->SeparatorText("Palladium Info");
m->Label("Os Driver: {}", PD::Os::GetDriverName()); m->Label("Os Driver: {}", PD::Os::GetDriverName());
m->Label("Renderer: {}", PD::Gfx::GetDriverName()); if (m->BeginTreeNode(
std::format("Gfx Driver: {}", PD::Gfx::GetDriverName()))) {
m->SeparatorText("Features");
if (PD::Gfx::GetFlags() & PDGfxBackendFlags_HasClipRect)
m->Label("ClipRects");
if (PD::Gfx::GetFlags() & PDGfxBackendFlags_ReqPow2)
m->Label("Texture As Pow of 2");
if (PD::Gfx::GetFlags() & PDGfxBackendFlags_ApproxSDF)
m->Label("SDF Approximation");
m->EndTreeNode();
}
if (m->BeginTreeNode( if (m->BeginTreeNode(
std::string(std::string("Input: ") + PD::Hid::GetDriverName()))) { std::string(std::string("Input: ") + PD::Hid::GetDriverName()))) {
/* if (pIO.pCtx.Hid()->Flags & PD::HidDriver::Flags_HasKeyboard) { /* if (pIO.pCtx.Hid()->Flags & PD::HidDriver::Flags_HasKeyboard) {
+17
View File
@@ -20,9 +20,26 @@ bool ColorTests() {
return true; return true;
} }
bool IDTests() {
std::cout << std::format("HashID32(\"1234\") -> {:016X}",
PD::HashID32("1234").Get())
<< std::endl;
std::cout << std::format("HashID32(\"1235\") -> {:016X}",
PD::HashID32("1235").Get())
<< std::endl;
std::cout << std::format("HashID64(\"1234\") -> {:016X}",
PD::HashID64("1234").Get())
<< std::endl;
std::cout << std::format("HashID64(\"1235\") -> {:016X}",
PD::HashID64("1235").Get())
<< std::endl;
return true;
}
int main() { int main() {
PD::Os::UseDriver<PD::OsDriver>(); PD::Os::UseDriver<PD::OsDriver>();
ColorTests(); ColorTests();
IDTests();
std::cout << PD::Os::GetTime() << std::endl; std::cout << PD::Os::GetTime() << std::endl;
PD::Pool<int> pool; PD::Pool<int> pool;
pool.Init(90); pool.Init(90);
+2
View File
@@ -21,6 +21,8 @@ class OsCtx {
virtual bool Mainloop() { return false; } virtual bool Mainloop() { return false; }
virtual void ClearViewPort() {} virtual void ClearViewPort() {}
virtual void SwapBuffers() {} virtual void SwapBuffers() {}
virtual int GetScreenCount() { return 1; }
virtual void DrawOnScreen(int s = 0) {}
PD::fvec2 PositionTranslate(PD::fvec2 in) { PD::fvec2 PositionTranslate(PD::fvec2 in) {
return fvec2(in.x * pViewPort.x, in.y * pViewPort.y); return fvec2(in.x * pViewPort.x, in.y * pViewPort.y);
} }
+2
View File
@@ -13,6 +13,8 @@ class HorizonCtr : public PD::OsCtx {
bool Mainloop() override; bool Mainloop() override;
void ClearViewPort() override; void ClearViewPort() override;
void SwapBuffers() override; void SwapBuffers() override;
int GetScreenCount() override { return 2; }
void DrawOnScreen(int s) override;
private: private:
struct Impl; struct Impl;
+10
View File
@@ -208,11 +208,17 @@ int main(int argc, char** argv) {
RightStick.pColor = "#00ffff"; RightStick.pColor = "#00ffff";
PD::UI7::Context ui7; PD::UI7::Context ui7;
ui7.GetIO().Font = &font; ui7.GetIO().Font = &font;
#ifdef __3DS__
ui7.AddViewPort("Default", PD::ivec4(0, 0, 320, 240));
ui7.GetIO().FontScale = 0.5f;
#else
ui7.AddViewPort("Default", PD::ivec4(0, 0, 1280, 720)); ui7.AddViewPort("Default", PD::ivec4(0, 0, 1280, 720));
#endif
ui7.UseViewPort("Default"); ui7.UseViewPort("Default");
bool pMetricsWin = true; bool pMetricsWin = true;
while (pOs->Mainloop()) { while (pOs->Mainloop()) {
PD::TT::End("OSCTX::MainLoop"); PD::TT::End("OSCTX::MainLoop");
pOs->DrawOnScreen(0);
pOs->ClearViewPort(); pOs->ClearViewPort();
PD::TT::Scope __st("MainLoop"); PD::TT::Scope __st("MainLoop");
PD::TT::Beg("MainRaw"); PD::TT::Beg("MainRaw");
@@ -302,6 +308,7 @@ int main(int argc, char** argv) {
PD::TT::Beg("BuildUI7Menus"); PD::TT::Beg("BuildUI7Menus");
if (auto m = ui7.BeginMenu("Test")) { if (auto m = ui7.BeginMenu("Test")) {
m->Label("Hello World!"); m->Label("Hello World!");
m->Image(pTex, 128.f);
ui7.EndMenu(); ui7.EndMenu();
} }
if (auto m = ui7.BeginMenu("LI DBG INFO")) { if (auto m = ui7.BeginMenu("LI DBG INFO")) {
@@ -324,7 +331,10 @@ int main(int argc, char** argv) {
PD::TT::End("UI7::Context::Update"); PD::TT::End("UI7::Context::Update");
PD::Gfx::Reset(); PD::Gfx::Reset();
PD::TT::Beg("PD::Gfx::Draw"); PD::TT::Beg("PD::Gfx::Draw");
pOs->DrawOnScreen(1);
pOs->ClearViewPort();
PD::Gfx::Draw(ui7.GetDrawData()); PD::Gfx::Draw(ui7.GetDrawData());
pOs->DrawOnScreen(0);
PD::Gfx::Draw(pList); PD::Gfx::Draw(pList);
PD::TT::End("PD::Gfx::Draw"); PD::TT::End("PD::Gfx::Draw");
pList.Clear(); pList.Clear();
+15 -2
View File
@@ -16,6 +16,7 @@ struct HorizonCtr::Impl {
C3D_RenderTarget* Top = nullptr; C3D_RenderTarget* Top = nullptr;
C3D_RenderTarget* Bottom = nullptr; C3D_RenderTarget* Bottom = nullptr;
uint32_t* pSocBuf = nullptr; uint32_t* pSocBuf = nullptr;
int CurrentScreen = 0;
}; };
void HorizonCtr::Init() { void HorizonCtr::Init() {
@@ -63,13 +64,25 @@ bool HorizonCtr::Mainloop() {
pViewPort = ivec2(400, 240); pViewPort = ivec2(400, 240);
bool _kill = hidKeysUp() & KEY_START; bool _kill = hidKeysUp() & KEY_START;
C3D_FrameBegin(C3D_FRAME_SYNCDRAW); C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
impl->CurrentScreen = 0;
return aptMainLoop() && !_kill; return aptMainLoop() && !_kill;
} }
void HorizonCtr::ClearViewPort() { void HorizonCtr::ClearViewPort() {
PD::Gfx::SetViewPort(pViewPort); C3D_RenderTargetClear(impl->CurrentScreen ? impl->Bottom : impl->Top,
C3D_CLEAR_ALL, PD::Color(25, 25, 25, 25), 0);
}
void HorizonCtr::DrawOnScreen(int s) {
impl->CurrentScreen = s;
if (s == 0) {
C3D_FrameDrawOn(impl->Top); C3D_FrameDrawOn(impl->Top);
C3D_RenderTargetClear(impl->Top, C3D_CLEAR_ALL, PD::Color(25, 25, 25, 25), 0); pViewPort = PD::ivec2(400, 240);
} else if (s == 1) {
C3D_FrameDrawOn(impl->Bottom);
pViewPort = PD::ivec2(320, 240);
}
PD::Gfx::SetViewPort(pViewPort);
} }
void HorizonCtr::SwapBuffers() { C3D_FrameEnd(0); } void HorizonCtr::SwapBuffers() { C3D_FrameEnd(0); }