WIP Backend System Redesign Step 1

- Created 1 Context for Backend Management and Sharing
- Made every class that used a static Backend require the Context or specific Backend
- Bring Back 3ds support
This commit is contained in:
2026-01-26 20:46:27 +01:00
parent 892f8ce0c4
commit e8072a064c
47 changed files with 350 additions and 242 deletions

View File

@@ -28,6 +28,7 @@ set(PD_SOURCES
source/core/timetrace.cpp
# Drivers
source/drivers/context.cpp
source/drivers/gfx.cpp
source/drivers/hid.cpp
source/drivers/os.cpp
@@ -85,6 +86,10 @@ file(GLOB_RECURSE PD_FMTFILES CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/include/pd/image/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/pd/lithium/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/include/pd/ui7/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/backends/desktop/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/backends/3ds/include/*.hpp
${CMAKE_CURRENT_SOURCE_DIR}/backends/desktop/include/*.cpp
${CMAKE_CURRENT_SOURCE_DIR}/backends/3ds/include/*.cpp
)
add_custom_target(pd-clang-format

View File

@@ -27,6 +27,6 @@ SOFTWARE.
#include <pd-3ds/bknd-hid.hpp>
namespace PD {
PD::Li::Font::Ref LoadSystemFont();
PD::Li::Font::Ref LoadSystemFont(Context& ctx);
void Init(void* data = nullptr);
} // namespace PD

View File

@@ -32,7 +32,7 @@ SOFTWARE.
namespace PD {
class GfxC3D : public GfxDriver {
public:
GfxC3D() : GfxDriver("Citro3D") {}
GfxC3D(PDDriverData data = nullptr) : GfxDriver("Citro3D") {}
~GfxC3D() = default;
PD_SHARED(GfxC3D);

View File

@@ -28,7 +28,7 @@ SOFTWARE.
namespace PD {
class Hid3DS : public HidDriver {
public:
Hid3DS();
Hid3DS(PDDriverData data = nullptr);
~Hid3DS() = default;
PD_SHARED(Hid3DS);

View File

@@ -42,7 +42,7 @@ class LinearAllocator {
T* allocate(std::size_t n) {
if (n > max_size()) {
throw std::runtime_error("[PD] LinearAllocator: Bad alloc!");
PD::Throw("[PD] LinearAllocator: Bad alloc!");
}
return static_cast<T*>(linearAlloc(n * sizeof(T)));
}

View File

@@ -156,7 +156,7 @@ void GfxC3D::RenderDrawData(const PD::Li::CmdPool& Commands) {
// C3D_FVUnifMtx4x4(GPU_VERTEX_SHADER, pLocProjection, (C3D_Mtx*)&proj);
size_t index = 0;
while (index < Commands.Size()) {
PD::Li::Texture::Ref Tex = Commands.GetCmd(index)->Tex;
PD::Li::TexAddress Tex = Commands.GetCmd(index)->Tex;
if (!Tex) {
index++;
continue;
@@ -186,8 +186,8 @@ void GfxC3D::RenderDrawData(const PD::Li::CmdPool& Commands) {
} else {
C3D_SetScissor(GPU_SCISSOR_DISABLE, 0, 0, 0, 0);
}
FragCfg(((C3D_Tex*)Tex->Address)->fmt);
BindTex(Tex->Address);
FragCfg(((C3D_Tex*)Tex)->fmt);
BindTex(Tex);
auto bufInfo = C3D_GetBufInfo();
BufInfo_Init(bufInfo);
BufInfo_Add(bufInfo, VertexBuffer.data(), sizeof(Li::Vertex), 3, 0x210);

View File

@@ -26,7 +26,7 @@ SOFTWARE.
#include <pd-3ds/bknd-hid.hpp>
namespace PD {
Hid3DS::Hid3DS() : HidDriver("Hid3DS") {
Hid3DS::Hid3DS(PDDriverData data) : HidDriver("Hid3DS") {
this->Flags |= Flags_HasTouch;
this->Flags |= FLags_HasGamepad;
pBinds[KEY_A] = A;
@@ -64,7 +64,7 @@ void Hid3DS::Update() {
u32 kd = hidKeysDown();
u32 kh = hidKeysHeld();
u32 ku = hidKeysUp();
for (auto &b : pBinds) {
for (auto& b : pBinds) {
if (b.first & kd) {
KeyEvents[0][Event_Down] |= b.second;
}

View File

@@ -27,9 +27,9 @@ SOFTWARE.
#include <pd-3ds.hpp>
namespace PD {
PD::Li::Font::Ref LoadSystemFont() {
TT::Scope st("LI_SystemFont"); // Trace loading time
Li::Font::Ref ret = Li::Font::New();
PD::Li::Font::Ref LoadSystemFont(Context& ctx) {
TT::Scope st(*ctx.Os(), "LI_SystemFont"); // Trace loading time
Li::Font::Ref ret = Li::Font::New(ctx);
fontEnsureMapped(); // Call this to be sure the font is mapped
// Get some const references for system font loading
const auto fnt = fontGetSystemFont();
@@ -124,8 +124,8 @@ PD::Li::Font::Ref LoadSystemFont() {
void Init(void* data) {
// Dekstop Init Stage
// First use default OS Driver
PD::OS::Init();
PD::Gfx::Init(PD::GfxC3D::New());
PD::Hid::Init(PD::Hid3DS::New());
// PD::OS::Init();
// PD::Gfx::Init(PD::GfxC3D::New());
// PD::Hid::Init(PD::Hid3DS::New());
}
} // namespace PD

View File

@@ -34,7 +34,7 @@ SOFTWARE.
namespace PD {
class GfxGL2 : public GfxDriver {
public:
GfxGL2() : GfxDriver("OpenGL2") {}
GfxGL2(PDDriverData data = nullptr) : GfxDriver("OpenGL2") {}
~GfxGL2() = default;
PD_SHARED(GfxGL2);

View File

@@ -30,7 +30,7 @@ SOFTWARE.
namespace PD {
class HidGLFW : public HidDriver {
public:
HidGLFW(GLFWwindow* win);
HidGLFW(PDDriverData data);
~HidGLFW() = default;
PD_SHARED(HidGLFW);
@@ -44,7 +44,7 @@ class HidGLFW : public HidDriver {
pTimings.erase(k);
return false;
}
return (PD::OS::GetTime() - pTimings[k]) > 50;
return 0; //(PD::OS::GetTime() - pTimings[k]) > 50;
}
if (!IsEvent(Event_Held, k)) {
if (pTimings.count(k)) {
@@ -53,7 +53,7 @@ class HidGLFW : public HidDriver {
}
}
if (IsEvent(Event_Held, k)) {
pTimings[k] = PD::OS::GetTime();
pTimings[k] = 0; // PD::OS::GetTime();
return true;
}
return false;

View File

@@ -337,6 +337,8 @@ PD::Li::Texture::Ref GfxGL2::LoadTex(const std::vector<PD::u8>& pixels, int w,
}
glBindTexture(GL_TEXTURE_2D, 0);
auto res = PD::Li::Texture::New(texID, PD::ivec2(w, h));
std::cout << std::format("Texture loaded: {} {}", texID, PD::ivec2(w, h))
<< std::endl;
return res;
}

View File

@@ -43,8 +43,11 @@ void TextCB(GLFWwindow* win, unsigned int c) {
}
*HidGLFW::pText += (char)c;
}
HidGLFW::HidGLFW(GLFWwindow* win) : HidDriver("HidGLFW") {
Window = win;
HidGLFW::HidGLFW(PDDriverData data) : HidDriver("HidGLFW") {
if (!data) {
std::cout << "[HidGLFW] Error: Data pointer was null" << std::endl;
}
Window = reinterpret_cast<GLFWwindow*>(data);
HidGLFW::pOldTextCB = glfwSetCharCallback(Window, NullTextCB);
Flags |= Flags_HasKeyboard;
Flags |= Flags_HasMouse;
@@ -148,10 +151,10 @@ void HidGLFW::Update() {
glfwGetCursorPos(Window, &x, &y);
pMouse[1] = pMouse[0]; // Cycle pMouse pos
pMouse[0] = fvec2(x, y);
if (pInTextMode && (PD::OS::GetTime() - pLastUpdate) > 50) {
pLastUpdate = PD::OS::GetTime();
HandleTextOps();
}
/*if (pInTextMode && (PD::OS::GetTime() - pLastUpdate) > 50) {
pLastUpdate = PD::OS::GetTime();
HandleTextOps();
}*/
}
void HidGLFW::GetInputStr(std::string& str) {

View File

@@ -26,7 +26,7 @@ SOFTWARE.
namespace PD {
void Init(void* data) {
if (!data) {
/*if (!data) {
std::cout << "[PD-DRIVERS] Error: pd-desktop requires GLFWwindow* "
"reference as data "
"input!"
@@ -37,6 +37,6 @@ void Init(void* data) {
// First use default OS Driver
PD::OS::Init();
PD::Gfx::Init(PD::GfxGL2::New());
PD::Hid::Init(PD::HidGLFW::New(reinterpret_cast<GLFWwindow*>(data)));
PD::Hid::Init(PD::HidGLFW::New(reinterpret_cast<GLFWwindow*>(data)));*/
}
} // namespace PD

View File

View File

View File

View File

View File

View File

@@ -78,7 +78,7 @@ class PD_API Color {
*/
constexpr Color& Hex(const std::string_view& hex) {
if (!(hex.length() == 7 || hex.length() == 9)) {
throw "[PD] Color: hex string is not rgb or rgba!";
PD::Throw("[PD] Color: hex string is not rgb or rgba!");
}
r = PD::Strings::HexChar2Int(hex[1]) * 16 +
PD::Strings::HexChar2Int(hex[2]);

View File

@@ -74,7 +74,12 @@ SOFTWARE.
namespace PD {
[[noreturn]] inline void Throw(const std::string& str) {
throw std::runtime_error("[PD] " + str);
#ifdef _EXCEPTIONS
throw std::runtime_error("PD Error " + str);
#else
std::cout << "PD Error " << str << std::endl;
std::abort();
#endif
}
/** Types */
using u8 = unsigned char;

View File

@@ -26,6 +26,7 @@ SOFTWARE.
#include <pd/core/common.hpp>
namespace PD {
class OsDriver;
/**
* Timer class
*/
@@ -35,7 +36,7 @@ class PD_API Timer {
* Constructor
* @param auto_start [default true] sets if timer should start after creation
*/
Timer(bool auto_start = true);
Timer(OsDriver& os, bool auto_start = true);
/**
* Unused Deconstructor
*/
@@ -81,5 +82,7 @@ class PD_API Timer {
u64 pNow;
/** Is Running */
bool pIsRunning = false;
/** Os Driver reference */
OsDriver& pOs;
};
} // namespace PD

View File

@@ -26,6 +26,7 @@ SOFTWARE.
#include <pd/core/common.hpp>
namespace PD {
class OsDriver;
/**
* Class to calculate Maximum/Minimum and Average Timings
*/
@@ -218,12 +219,12 @@ class Res {
* Begin a Trace
* @param id Name of the Trace
*/
PD_API void Beg(const std::string& id);
PD_API void Beg(OsDriver& os, const std::string& id);
/**
* End a Trace
* @param id Name of the Trace
*/
PD_API void End(const std::string& id);
PD_API void End(OsDriver& os, const std::string& id);
/**
* Collect Start end end of the trace by tracking
* when the Scope object goes out of scope
@@ -245,18 +246,20 @@ class Scope {
* Constructor requiring a Name for the Trace
* @param id Name of the Trace
*/
Scope(const std::string& id) {
Scope(OsDriver& os, const std::string& id) : pOs(os) {
this->ID = id;
Beg(id);
Beg(pOs, id);
}
/**
* Deconstructor getting the end time when going out of scope
*/
~Scope() { End(ID); }
~Scope() { End(pOs, ID); }
private:
/** Trace Name/ID */
std::string ID;
/** Os Driver Reference */
OsDriver& pOs;
};
} // namespace TT
} // namespace PD

View File

@@ -0,0 +1,79 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/drivers/gfx.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/drivers/os.hpp>
namespace PD {
class PD_API Context {
public:
Context()
: pOs(OsDriver::New()), pGfx(GfxDriver::New()), pHid(HidDriver::New()) {}
~Context() {}
PD_RAW(Context);
static Context::Ref Create();
template <typename Driver>
void UseGfxDriver(PDDriverData data) {
static_assert(std::is_base_of<GfxDriver, Driver>::value,
"Driver must extend GfxDriver");
pGfx.reset();
pGfx = Driver::New(data);
}
template <typename Driver>
void UseHidDriver(PDDriverData data) {
static_assert(std::is_base_of<HidDriver, Driver>::value,
"Driver must extend HidDriver");
pHid.reset();
pHid = Driver::New(data);
}
template <typename Driver>
void UseOsDriver(PDDriverData data) {
static_assert(std::is_base_of<OsDriver, Driver>::value,
"Driver must extend OsDriver");
pOs.reset();
pOs = Driver::New(data);
}
PD::Li::Texture::Ref GetSolidTex();
OsDriver::Ref Os() { return pOs; }
GfxDriver::Ref Gfx() { return pGfx; }
HidDriver::Ref Hid() { return pHid; }
private:
OsDriver::Ref pOs = nullptr;
GfxDriver::Ref pGfx = nullptr;
HidDriver::Ref pHid = nullptr;
PD::Li::Texture::Ref pSolidTex = nullptr;
};
} // namespace PD

View File

@@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/drivers/context.hpp>
#include <pd/drivers/gfx.hpp>
#include <pd/drivers/hid.hpp>
#include <pd/drivers/os.hpp>

View File

@@ -24,6 +24,7 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/drivers/types.hpp>
#include <pd/lithium/command.hpp>
#include <pd/lithium/texture.hpp>
@@ -61,7 +62,8 @@ class GfxDriver2 {
};
class GfxDriver {
public:
GfxDriver(const std::string& name = "NullGfx") : pName(name) {};
GfxDriver(const std::string& name = "NullGfx") : pName(name) {}
GfxDriver(PDDriverData data) : pName("NullGfx") {}
~GfxDriver() = default;
PD_SHARED(GfxDriver);
@@ -77,6 +79,7 @@ class GfxDriver {
virtual void RenderDrawData(const Li::CmdPool& Commands) {}
void SetViewPort(const ivec2& vp) { ViewPort = vp; }
void SetViewPort(int w, int h) { ViewPort = PD::ivec2(w, h); }
virtual Li::Texture::Ref LoadTex(
const std::vector<u8>& pixels, int w, int h,
@@ -90,6 +93,8 @@ class GfxDriver {
Li::Texture::Ref GetSolidTex() { return pSolid; }
const std::string& GetName() const { return pName; }
const std::string pName = "NullGfx";
LiBackendFlags Flags = 0;
ivec2 ViewPort;
@@ -107,38 +112,4 @@ class GfxDriver {
// Optional Frame Counter
u64 FrameCounter;
};
/** Static Gfx Controller */
class Gfx {
public:
Gfx() = default;
~Gfx() = default;
static void Init(GfxDriver::Ref d);
static void Deinit() { pGfx->Deinit(); }
static void NewFrame() { pGfx->NewFrame(); }
static void BindTex(Li::TexAddress addr) { pGfx->BindTex(addr); }
static void SetViewPort(const ivec2& vp) { pGfx->SetViewPort(vp); }
static void SetViewPort(int w, int h) { pGfx->SetViewPort(PD::ivec2(w, h)); }
static void RenderDrawData(const Li::CmdPool& Commands) {
pGfx->RenderDrawData(Commands);
}
static LiBackendFlags Flags() { return pGfx->Flags; }
static Li::Texture::Ref LoadTex(
const std::vector<u8>& pixels, int w, int h,
Li::Texture::Type type = Li::Texture::Type::RGBA32,
Li::Texture::Filter filter = Li::Texture::Filter::LINEAR) {
return pGfx->LoadTex(pixels, w, h, type, filter);
}
static void DestroyTex(Li::Texture::Ref tex) { pGfx->DestroyTex(tex); }
static Li::Texture::Ref GetSolidTex() { return pGfx->GetSolidTex(); }
static GfxDriver::Ref pGfx;
};
} // namespace PD

View File

@@ -24,6 +24,7 @@ SOFTWARE.
*/
#include <pd/core/core.hpp>
#include <pd/drivers/types.hpp>
namespace PD {
/** Did not found a better solution yet sadly */
@@ -134,7 +135,8 @@ class HidDriver {
Event_Up, ///< Key released
};
HidDriver(const std::string& name = "NullHid") : pName(name) {};
HidDriver(const std::string& name = "NullHid") : pName(name) {}
HidDriver(PDDriverData data) : pName("NullHid") {}
virtual ~HidDriver() = default;
PD_SHARED(HidDriver);
@@ -233,6 +235,8 @@ class HidDriver {
*/
virtual void GetInputStr(std::string& str) {}
const std::string& GetName() const { return pName; }
/** Data Section */
/** Backend Identification Name */
@@ -255,42 +259,8 @@ class HidDriver {
/** Keyboard Key Event Table Setup */
std::unordered_map<Event, u128> KbKeyEvents[2];
};
/** Static Hid Controller */
class Hid {
public:
Hid() = default;
~Hid() = default;
/** Referenec to Drivers enums */
using Key = HidDriver::Key;
using KbKey = HidKb::KbKey;
using Event = HidDriver::Event;
static void Init(HidDriver::Ref v = nullptr) {
if (v) {
pHid = v;
} else {
pHid = HidDriver::New();
}
}
static bool IsEvent(Event e, Key keys) { return pHid->IsEvent(e, keys); }
static bool IsEvent(Event e, KbKey key) { return pHid->IsEvent(e, key); }
static bool IsDown(Key keys) { return pHid->IsDown(keys); }
static bool IsUp(Key keys) { return pHid->IsUp(keys); }
static bool IsHeld(Key keys) { return pHid->IsHeld(keys); }
static fvec2 MousePos() { return pHid->MousePos(); }
static fvec2 MousePosLast() { return pHid->MousePosLast(); }
static void Clear() { pHid->Clear(); }
static void Lock() { pHid->Lock(); }
static void Lock(bool v) { pHid->Lock(v); }
static void Unlock() { pHid->Unlock(); }
static bool Locked() { return pHid->Locked(); }
static void Update() { pHid->Update(); }
static u32 GetFlags() { return pHid->Flags; }
static void GetStrInput(std::string& str) { pHid->GetInputStr(str); }
static HidDriver::Ref pHid;
};
namespace Hid {
using Event = HidDriver::Event;
using Key = HidDriver::Key;
} // namespace Hid
} // namespace PD

View File

@@ -25,13 +25,15 @@ SOFTWARE.
#include <pd/core/common.hpp>
#include <pd/core/timetrace.hpp>
#include <pd/drivers/types.hpp>
namespace PD {
using TraceMap = std::map<std::string, TT::Res::Ref>;
class OsDriver {
public:
OsDriver() = default;
OsDriver(const std::string& name = "StdPd") : pName(name) {}
OsDriver(PDDriverData data) : pName("StdPd") {}
virtual ~OsDriver() = default;
PD_SHARED(OsDriver);
@@ -40,32 +42,11 @@ class OsDriver {
TraceMap& GetTraceMap();
TT::Res::Ref& GetTraceRef(const std::string& id);
bool TraceExist(const std::string& id);
const std::string& GetName() const { return pName; }
TraceMap pTraces;
};
/** Static Os Controller */
class OS {
public:
OS() = default;
~OS() = default;
static void Init(OsDriver::Ref v = nullptr) {
if (v) {
pOs = v;
} else {
pOs = OsDriver::New();
}
}
static u64 GetTime() { return pOs->GetTime(); }
static u64 GetNanoTime() { return pOs->GetNanoTime(); }
static TraceMap& GetTraceMap() { return pOs->GetTraceMap(); }
static TT::Res::Ref& GetTraceRef(const std::string& id) {
return pOs->GetTraceRef(id);
}
static bool TraceExist(const std::string& id) { return pOs->TraceExist(id); }
static OsDriver::Ref pOs;
private:
const std::string pName = "StdPd";
};
} // namespace PD

View File

@@ -0,0 +1,3 @@
#pragma once
using PDDriverData = void*;

View File

@@ -47,7 +47,7 @@ namespace PD {
namespace Li {
class PD_API DrawList {
public:
DrawList(int initial_size = 64);
DrawList(Context& ctx, int initial_size = 64);
~DrawList();
/** Require Copy and Move Constructors */
@@ -218,6 +218,7 @@ class PD_API DrawList {
std::vector<fvec2> pPath;
u32 pNumIndices = 0;
u32 pNumVertices = 0;
Context* pCtx = nullptr;
};
} // namespace Li
} // namespace PD

View File

@@ -42,6 +42,7 @@ enum LiTextFlags_ {
};
namespace PD {
class Context;
namespace Li {
class PD_API Font {
public:
@@ -56,7 +57,7 @@ class PD_API Font {
};
/** Constructore doesnt need Backand anymore */
Font() = default;
Font(Context& ctx) : pCtx(ctx) {}
~Font() = default;
PD_SHARED(Font);
@@ -128,6 +129,7 @@ class PD_API Font {
u64 TimeStamp;
};
std::unordered_map<u32, TMELEM> pTMS;
Context& pCtx;
};
} // namespace Li
} // namespace PD

View File

@@ -32,7 +32,9 @@ namespace PD {
namespace UI7 {
class InputHandler {
public:
InputHandler() { DragTime = Timer::New(false); }
InputHandler(PD::Context& ctx) : pCtx(ctx) {
DragTime = Timer::New(*pCtx.Os().get(), false);
}
~InputHandler() = default;
PD_SHARED(InputHandler);
@@ -55,10 +57,10 @@ class InputHandler {
}
}
// Get a Short define for touch pos
fvec2 p = Hid::MousePos();
fvec2 p = pCtx.Hid()->MousePos();
// Check if Drag starts in the area position
if ((Hid::IsDown(Hid::Key::Touch) ||
Hid::IsEvent(PD::Hid::Event::Event_Down, HidKb::Kb_MouseLeft)) &&
if ((pCtx.Hid()->IsDown(pCtx.Hid()->Key::Touch) ||
pCtx.Hid()->IsEvent(PD::HidDriver::Event_Down, HidKb::Kb_MouseLeft)) &&
Li::Renderer::InBox(p, area)) {
// Set ID and iniatial Positions
DraggedObject = id;
@@ -70,15 +72,16 @@ class InputHandler {
DragTime->Reset();
DragTime->Rseume();
return false; // To make sure the Object is "Dragged"
} else if ((Hid::IsHeld(Hid::Key::Touch) ||
Hid::IsEvent(PD::Hid::Event::Event_Held,
HidKb::Kb_MouseLeft)) &&
} else if ((pCtx.Hid()->IsHeld(pCtx.Hid()->Key::Touch) ||
pCtx.Hid()->IsEvent(PD::HidDriver::Event_Held,
HidKb::Kb_MouseLeft)) &&
IsObjectDragged()) {
// Update DragLast and DragPoisition
DragLastPosition = DragPosition;
DragPosition = p;
} else if ((Hid::IsUp(Hid::Key::Touch) ||
Hid::IsEvent(PD::Hid::Event::Event_Up, HidKb::Kb_MouseLeft)) &&
} else if ((pCtx.Hid()->IsUp(pCtx.Hid()->Key::Touch) ||
pCtx.Hid()->IsEvent(PD::HidDriver::Event_Up,
HidKb::Kb_MouseLeft)) &&
IsObjectDragged()) {
// Released... Everything gets reset
DraggedObject = 0;
@@ -88,9 +91,9 @@ class InputHandler {
DragDestination = fvec4(0);
// Set Drag released to true (only one frame)
// and Only if still in Box
DragReleased = Li::Renderer::InBox(Hid::MousePosLast(), area);
DragReleased = Li::Renderer::InBox(pCtx.Hid()->MousePosLast(), area);
DragReleasedAW = true; // Advanced
u64 d_rel = PD::OS::GetTime();
u64 d_rel = pCtx.Os()->GetTime();
if (d_rel - DragLastReleased < DoubleClickTime) {
DragDoubleRelease = true;
DragLastReleased = 0; // Set 0 to prevent double exec
@@ -129,6 +132,7 @@ class InputHandler {
bool DragReleased = false; ///< Drag Releaded in Box
bool DragReleasedAW = false; ///< Drag Released Anywhere
bool DragDoubleRelease = false; ///< Double Click
PD::Context& pCtx;
/** Check if an object is Dragged already */
bool IsObjectDragged() const { return DraggedObject != 0; }
};

View File

@@ -30,20 +30,21 @@ SOFTWARE.
#include <pd/ui7/viewport.hpp>
namespace PD {
class Context;
namespace UI7 {
class PD_API IO {
public:
IO() {
Time = Timer::New();
InputHandler = InputHandler::New();
IO(PD::Context& ctx) : pCtx(ctx) {
Time = Timer::New(*pCtx.Os().get());
InputHandler = InputHandler::New(pCtx);
Theme = UI7::Theme::New();
Back = Li::DrawList::New();
Front = Li::DrawList::New();
FDL = Li::DrawList::New();
Back = Li::DrawList::New(pCtx);
Front = Li::DrawList::New(pCtx);
FDL = Li::DrawList::New(pCtx);
DeltaStats = TimeStats::New(60);
/** Probably not the best solution i guess */
CurrentViewPort.z = PD::Gfx::pGfx->ViewPort.x;
CurrentViewPort.w = PD::Gfx::pGfx->ViewPort.y;
CurrentViewPort.z = pCtx.Gfx()->ViewPort.x;
CurrentViewPort.w = pCtx.Gfx()->ViewPort.y;
}
~IO() {}
@@ -90,6 +91,8 @@ class PD_API IO {
u32 NumIndices = 0; ///< Debug Indices Num
std::vector<u32> MenuOrder;
PD::Context& pCtx; // Palladium base context
// DrawListApi
void RegisterDrawList(const UI7::ID& id, Li::DrawList::Ref v) {
DrawListRegestry.push_back(std::make_pair(id, v));

View File

@@ -38,7 +38,7 @@ class PD_API Layout {
public:
Layout(const ID& id, IO::Ref io) : ID(id) {
this->IO = io;
DrawList = Li::DrawList::New();
DrawList = Li::DrawList::New(io->pCtx);
DrawList->SetFont(IO->Font);
DrawList->SetFontScale(io->FontScale);
Scrolling[0] = false;

View File

@@ -49,7 +49,7 @@ PD_API std::string GetVersion(bool show_build = false);
/** Base Context for UI7 */
class PD_API Context {
public:
Context() { pIO = IO::New(); }
Context(PD::Context& ctx) { pIO = IO::New(ctx); }
~Context() = default;
PD_SHARED(Context);

View File

@@ -25,19 +25,19 @@ SOFTWARE.
#include <pd/drivers/drivers.hpp>
namespace PD {
PD_API Timer::Timer(bool autostart) {
PD_API Timer::Timer(OsDriver& os, bool autostart) : pOs(os) {
pIsRunning = autostart;
Reset();
}
PD_API void Timer::Reset() {
pStart = OS::GetTime();
pStart = pOs.GetTime();
pNow = pStart;
}
PD_API void Timer::Update() {
if (pIsRunning) {
pNow = OS::GetTime();
pNow = pOs.GetTime();
}
}

View File

@@ -25,13 +25,13 @@ SOFTWARE.
#include <pd/drivers/drivers.hpp>
namespace PD::TT {
PD_API void Beg(const std::string& id) {
auto trace = OS::GetTraceRef(id);
trace->SetStart(PD::OS::GetNanoTime());
PD_API void Beg(OsDriver& os, const std::string& id) {
auto trace = os.GetTraceRef(id);
trace->SetStart(os.GetNanoTime());
}
PD_API void End(const std::string& id) {
auto trace = OS::GetTraceRef(id);
trace->SetEnd(PD::OS::GetNanoTime());
PD_API void End(OsDriver& os, const std::string& id) {
auto trace = os.GetTraceRef(id);
trace->SetEnd(os.GetNanoTime());
}
} // namespace PD::TT

View File

@@ -0,0 +1,42 @@
/*
MIT License
Copyright (c) 2024 - 2026 René Amthor (tobid7)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <pd/drivers/context.hpp>
namespace PD {
PD_API Context::Ref Context::Create() {
Context::Ref ctx = Context::New();
ctx->pGfx = GfxDriver::New();
ctx->pOs = OsDriver::New();
ctx->pHid = HidDriver::New();
return ctx;
}
PD_API PD::Li::Texture::Ref Context::GetSolidTex() {
if (pSolidTex == nullptr) {
std::vector<u8> data(16 * 16 * 4, 0xff);
pSolidTex = pGfx->LoadTex(data, 16, 16);
}
return pSolidTex;
}
} // namespace PD

View File

@@ -23,20 +23,4 @@ SOFTWARE.
#include <pd/drivers/gfx.hpp>
namespace PD {
GfxDriver::Ref Gfx::pGfx = nullptr;
void Gfx::Init(GfxDriver::Ref d) {
if (!d) {
return;
}
pGfx = d;
pGfx->Init();
pGfx->PostInit();
}
void GfxDriver::PostInit() {
std::vector<PD::u8> white(16 * 16 * 4, 0xff);
pSolid = this->LoadTex(white, 16, 16);
}
} // namespace PD
namespace PD {} // namespace PD

View File

@@ -24,9 +24,8 @@ SOFTWARE.
#include <pd/drivers/hid.hpp>
namespace PD {
HidDriver::Ref Hid::pHid = nullptr;
bool HidDriver::IsEvent(Event e, Key keys) { return KeyEvents[0][e] & keys; }
bool HidDriver::IsEvent(Event e, KbKey keys) {
return KbKeyEvents[0][e].Has(keys);
}

View File

@@ -24,8 +24,6 @@ SOFTWARE.
#include <pd/drivers/os.hpp>
namespace PD {
OsDriver::Ref OS::pOs = nullptr;
TT::Res::Ref& OsDriver::GetTraceRef(const std::string& id) {
if (!pTraces.count(id)) {
pTraces[id] = TT::Res::New();

View File

@@ -30,7 +30,7 @@ SOFTWARE.
namespace PD {
namespace Li {
PD_API DrawList::DrawList(int initial_size) {
PD_API DrawList::DrawList(Context& ctx, int initial_size) : pCtx(&ctx) {
DrawSolid();
pPool.Init(initial_size);
}
@@ -40,7 +40,7 @@ PD_API DrawList::~DrawList() {
pPool.Deinit();
}
PD_API void DrawList::DrawSolid() { CurrentTex = Gfx::GetSolidTex(); }
PD_API void DrawList::DrawSolid() { CurrentTex = pCtx->GetSolidTex(); }
PD_API void DrawList::Clear() {
pNumIndices = 0;
@@ -70,9 +70,6 @@ PD_API void DrawList::Merge(DrawList::Ref list) {
PD_API void DrawList::Copy(DrawList::Ref list) { pPool.Copy(list->pPool); }
PD_API void DrawList::Optimize() {
#ifndef NDEBUG
PD::TT::Scope s("Optimize");
#endif
/*std::sort(pDrawList.begin(), pDrawList.end(),
[](const PD::Li::Command::Ref &a, const PD::Li::Command::Ref &b) {
if (a->Layer == b->Layer) { // Same layer

View File

@@ -53,15 +53,15 @@ PD_API void Font::LoadTTF(const std::string& path, int height) {
* and helps not having the font loading code twice
* when adding LoadTTF with mem support
*/
TT::Scope st("LI_LoadTTF_" + path);
TT::Scope st(*pCtx.Os().get(), "LI_LoadTTF_" + path);
auto font = PD::IO::LoadFile2Mem(path);
LoadTTF(font, height);
}
PD_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);
auto t = pCtx.Gfx()->LoadTex(font_tex, texszs, texszs, Texture::RGBA32,
Texture::LINEAR);
tex->CopyFrom(t);
Textures.push_back(tex);
}
@@ -147,7 +147,7 @@ PD_API void Font::LoadTTF(const std::vector<u8>& data, int height) {
uvs.z = (off.x + w) / static_cast<float>(texszs);
uvs.w = (off.y + h) / static_cast<float>(texszs);
// Flip if needed
if (Gfx::Flags() & LiBackendFlags_FlipUV_Y) {
if (pCtx.Gfx()->Flags & LiBackendFlags_FlipUV_Y) {
uvs.y = 1.f - uvs.y;
uvs.w = 1.f - uvs.w;
}
@@ -196,7 +196,7 @@ PD_API Font::Codepoint& Font::GetCodepoint(u32 cp) {
PD_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();
pTMS[id].TimeStamp = pCtx.Os()->GetTime();
return pTMS[id].Size;
}
// Use wstring for exemple for german äöü
@@ -242,7 +242,7 @@ PD_API fvec2 Font::GetTextBounds(const std::string& text, float scale) {
res.y += lh;
pTMS[id].ID = id;
pTMS[id].Size = res;
pTMS[id].TimeStamp = PD::OS::GetTime();
pTMS[id].TimeStamp = pCtx.Os()->GetTime();
return res;
}
@@ -341,7 +341,7 @@ PD_API std::string Font::pWrapText(const std::string& txt, float scale,
if (pTMS.find(id) != pTMS.end()) {
if (pTMS[id].Text.size()) {
dim = pTMS[id].Size;
pTMS[id].TimeStamp = PD::OS::GetTime();
pTMS[id].TimeStamp = pCtx.Os()->GetTime();
return pTMS[id].Text;
}
}
@@ -367,7 +367,7 @@ PD_API std::string Font::pWrapText(const std::string& txt, float scale,
pTMS[id].ID = id;
pTMS[id].Size = dim;
pTMS[id].Text = ret;
pTMS[id].TimeStamp = PD::OS::GetTime();
pTMS[id].TimeStamp = pCtx.Os()->GetTime();
return ret;
}
@@ -377,7 +377,7 @@ PD_API std::string Font::pShortText(const std::string& txt, float scale,
if (pTMS.find(id) != pTMS.end()) {
if (pTMS[id].Text.size()) {
dim = pTMS[id].Size;
pTMS[id].TimeStamp = PD::OS::GetTime();
pTMS[id].TimeStamp = pCtx.Os()->GetTime();
return pTMS[id].Text;
}
}
@@ -410,12 +410,12 @@ PD_API std::string Font::pShortText(const std::string& txt, float scale,
pTMS[id].ID = id;
pTMS[id].Size = dim;
pTMS[id].Text = ret;
pTMS[id].TimeStamp = PD::OS::GetTime();
pTMS[id].TimeStamp = pCtx.Os()->GetTime();
return ret;
}
PD_API void Font::CleanupTMS() {
u64 t = PD::OS::GetTime();
u64 t = pCtx.Os()->GetTime();
for (auto it = pTMS.begin(); it != pTMS.end();) {
if (t - it->second.TimeStamp > 1000) {
it = pTMS.erase(it);

View File

@@ -26,10 +26,10 @@ SOFTWARE.
namespace PD {
namespace UI7 {
PD_API void Container::HandleScrolling(fvec2 scrolling, fvec4 viewport) {
if (last_use != 0 && OS::GetTime() - last_use > 5000) {
if (last_use != 0 && io->pCtx.Os()->GetTime() - last_use > 5000) {
rem = true;
}
last_use = OS::GetTime();
last_use = io->pCtx.Os()->GetTime();
pos -= fvec2(0, scrolling.y);
skippable = !Li::Renderer::InBox(
pos, size,

View File

@@ -27,7 +27,7 @@ SOFTWARE.
namespace PD {
PD_API void UI7::IO::Update() {
/** Todo: find out if we even still use the Drawlist regestry */
u64 current = OS::GetNanoTime();
u64 current = pCtx.Os()->GetNanoTime();
Delta = static_cast<float>(current - LastTime) / 1000000.f;
LastTime = current;
DeltaStats->Add(Delta * 1000);

View File

@@ -132,10 +132,10 @@ PD_API void Menu::HandleFocus() {
if (!pIsOpen) {
newarea = fvec4(pLayout->Pos, fvec2(pLayout->Size.x, TitleBarHeight));
}
if ((Hid::IsDown(Hid::Key::Touch) ||
Hid::IsEvent(Hid::Event::Event_Down, HidKb::Kb_MouseLeft)) &&
Li::Renderer::InBox(Hid::MousePos(), newarea) &&
!Li::Renderer::InBox(Hid::MousePos(),
if ((pIO->pCtx.Hid()->IsDown(Hid::Key::Touch) ||
pIO->pCtx.Hid()->IsEvent(Hid::Event::Event_Down, HidKb::Kb_MouseLeft)) &&
Li::Renderer::InBox(pIO->pCtx.Hid()->MousePos(), newarea) &&
!Li::Renderer::InBox(pIO->pCtx.Hid()->MousePos(),
pIO->InputHandler->FocusedMenuRect)) {
pIO->InputHandler->FocusedMenu = pID;
}
@@ -150,7 +150,7 @@ PD_API void Menu::HandleScrolling() {
bool allowed =
pLayout->MaxPosition.y > (pLayout->WorkRect.w - pLayout->WorkRect.y);
if (allowed) {
if (PD::Hid::IsDown(PD::Hid::Key::Touch)) {
if (pIO->pCtx.Hid()->IsDown(PD::Hid::Key::Touch)) {
pLayout->ScrollStart = pLayout->ScrollOffset;
}
if (pIO->InputHandler->DragObject(

View File

@@ -190,9 +190,10 @@ PD_API void Context::MetricsMenu(bool* show) {
m->Label("Menus: " + std::to_string(pMenus.size()));
/** Section TimeTrace */
m->SeparatorText("TimeTrace");
if (m->BeginTreeNode("Traces (" + std::to_string(OS::GetTraceMap().size()) +
if (m->BeginTreeNode("Traces (" +
std::to_string(pIO->pCtx.Os()->GetTraceMap().size()) +
")")) {
for (auto& it : OS::GetTraceMap()) {
for (auto& it : pIO->pCtx.Os()->GetTraceMap()) {
if (m->BeginTreeNode(it.second->GetID())) {
m->Label("Diff: " + UI7DTF(it.second->GetLastDiff()));
m->Label("Protocol Len: " +
@@ -207,18 +208,18 @@ PD_API void Context::MetricsMenu(bool* show) {
m->EndTreeNode();
}
m->SeparatorText("Palladium Info");
m->Label("Renderer: " + PD::Gfx::pGfx->pName);
if (m->BeginTreeNode(std::string("Input: " + PD::Hid::pHid->pName))) {
if (PD::Hid::GetFlags() & PD::HidDriver::Flags_HasKeyboard) {
m->Label("Renderer: " + pIO->pCtx.Gfx()->GetName());
if (m->BeginTreeNode(std::string("Input: " + pIO->pCtx.Hid()->GetName()))) {
if (pIO->pCtx.Hid()->Flags & PD::HidDriver::Flags_HasKeyboard) {
m->Label("- Keyboard Supported");
}
if (PD::Hid::GetFlags() & PD::HidDriver::Flags_HasMouse) {
if (pIO->pCtx.Hid()->Flags & PD::HidDriver::Flags_HasMouse) {
m->Label("- Mouse Supported");
}
if (PD::Hid::GetFlags() & PD::HidDriver::Flags_HasTouch) {
if (pIO->pCtx.Hid()->Flags & PD::HidDriver::Flags_HasTouch) {
m->Label("- Touch Supported");
}
if (PD::Hid::GetFlags() & PD::HidDriver::FLags_HasGamepad) {
if (pIO->pCtx.Hid()->Flags & PD::HidDriver::FLags_HasGamepad) {
m->Label("- Gamepad Supported");
}
m->EndTreeNode();

View File

@@ -73,10 +73,19 @@ int main() {
C3D_RenderTargetSetOutput(Bottom, GFX_BOTTOM, GFX_LEFT, DisplayTransferFlags);
#endif
/** Init Palaldium Drivers */
PD::Init(PD_INIT_DATA);
PD::Context Ctx;
#ifdef __3DS__
Ctx.UseGfxDriver<PD::GfxC3D>(PD_INIT_DATA);
Ctx.UseHidDriver<PD::Hid3DS>(PD_INIT_DATA);
#else
Ctx.UseGfxDriver<PD::GfxGL2>(PD_INIT_DATA);
Ctx.UseHidDriver<PD::HidGLFW>(PD_INIT_DATA);
#endif
Ctx.Gfx()->Init();
/** Create DrawList and Load Font */
PD::Li::DrawList::Ref List = PD::Li::DrawList::New();
PD::Li::Font::Ref font = PD::Li::Font::New();
PD::Li::DrawList::Ref List = PD::Li::DrawList::New(Ctx);
PD::Li::Font::Ref font = PD::Li::Font::New(Ctx);
#ifdef __3DS__
font->LoadTTF("sdmc:/ComicNeue.ttf", 32);
auto img = PD::Image::New("sdmc:/pb.png");
@@ -86,10 +95,10 @@ int main() {
#endif
List->SetFont(font);
PD::Image::Convert(img, img->RGBA);
auto tex = PD::Gfx::LoadTex(img->pBuffer, img->pWidth, img->pHeight);
auto tex = Ctx.Gfx()->LoadTex(img->pBuffer, img->pWidth, img->pHeight);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
auto ui7 = PD::UI7::Context::New();
auto ui7 = PD::UI7::Context::New(Ctx);
PD::UI7::ID VpTop("Default");
ui7->AddViewPort(VpTop, PD::ivec4(0, 0, 400, 240));
ui7->UseViewPort(VpTop);
@@ -100,15 +109,15 @@ int main() {
font->DefaultPixelHeight = 32;
while (!glfwWindowShouldClose(win)) {
#else
PD::Gfx::pGfx->ViewPort = PD::ivec2(400, 240);
Ctx.Gfx()->SetViewPort(400, 240);
while (aptMainLoop()) {
#endif
PD::Hid::Update();
Ctx.Hid()->Update();
#ifndef __3DS__
/** Auto ViewPort Resize */
int wx, wy;
glfwGetWindowSize(win, &wx, &wy);
PD::Gfx::pGfx->ViewPort = PD::ivec2(wx, wy);
Ctx.Gfx()->SetViewPort(wx, wy);
ui7->GetIO()->CurrentViewPort = PD::ivec4(0, 0, wx, wy);
glViewport(0, 0, wx, wy);
glClearColor(0.1, 0.1, 0.1, 1);
@@ -121,7 +130,7 @@ int main() {
RoundedRect(List, PD::fvec2(15, 183), PD::fvec2(100, 40), 0xaa222222);
List->DrawTexture(tex);
RoundedRect(List, PD::fvec2(200, 50), 100, 0xffffffff,
((1 + std::sin(PD::OS::GetTime() / 1000.f)) * 0.5f) * 100.f);
((1 + std::sin(Ctx.Os()->GetTime() / 1000.f)) * 0.5f) * 100.f);
List->DrawText(PD::fvec2(50, 190), "OK", 0xffffffff);
// List->DrawLine(PD::fvec2(0), PD::fvec2(1000, 600), 0xffffffff);
List->PathAdd(500);
@@ -135,8 +144,8 @@ int main() {
"Test String oder So\nPalladium 0.6.0\n" +
std::format("{}\nMousePos: {}",
PD::Strings::FormatNanos(
PD::OS::GetTraceRef("REN")->GetLastDiff()),
PD::Hid::MousePos()) +
Ctx.Os()->GetTraceRef("REN")->GetLastDiff()),
Ctx.Hid()->MousePos()) +
"\nUI7 Version: " + PD::UI7::GetVersion(),
0xff000000);
if (auto menu = ui7->BeginMenu("Test")) {
@@ -147,20 +156,20 @@ int main() {
if (menu->Button("Test")) {
break;
}
menu->Label(std::format("MousePos: {}", PD::Hid::MousePos()));
menu->Label(std::format("MousePos: {}", Ctx.Hid()->MousePos()));
menu->Label(std::format("this->Pos: {}", menu->pLayout->GetPosition()));
menu->Label(std::format("Dragged; #{:08X}",
menu->Label(std::format("Dragged: #{:08X}",
ui7->pIO->InputHandler->DraggedObject));
menu->Label(
std::format("Left: {}", PD::Hid::IsHeld(PD::Hid::Key::Touch)));
std::format("Left: {}", Ctx.Hid()->IsHeld(PD::Hid::Key::Touch)));
menu->DragData("Value", &v, 1);
menu->Slider("Value 2", &v);
ui7->EndMenu();
}
if (auto menu = ui7->BeginMenu("Yet another Window")) {
menu->Label(std::format("this->Pos: {}", menu->pLayout->GetPosition()));
menu->Label(std::format("Vertices: {}", PD::Gfx::pGfx->VertexCounter));
menu->Label(std::format("Indices: {}", PD::Gfx::pGfx->IndexCounter));
menu->Label(std::format("Vertices: {}", Ctx.Gfx()->VertexCounter));
menu->Label(std::format("Indices: {}", Ctx.Gfx()->IndexCounter));
ui7->EndMenu();
}
if (auto menu = ui7->BeginMenu("#Debug (UI7)")) {
@@ -192,22 +201,22 @@ int main() {
ui7->AboutMenu(&AboutOderSo);
ui7->MetricsMenu();
ui7->StyleEditor();
PD::TT::Beg("ui7->Update");
PD::TT::Beg(*Ctx.Os(), "ui7->Update");
ui7->Update();
PD::TT::End("ui7->Update");
PD::TT::End(*Ctx.Os(), "ui7->Update");
/** Render DrawData */
#ifdef __3DS__
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C3D_FrameDrawOn(Top);
C3D_RenderTargetClear(Top, C3D_CLEAR_ALL, 0x00000000, 0);
#endif
PD::TT::Beg("REN");
PD::Gfx::NewFrame();
PD::Gfx::RenderDrawData(List->Data());
PD::Gfx::RenderDrawData(ui7->GetDrawData()->Data());
PD::TT::Beg(*Ctx.Os(), "REN");
Ctx.Gfx()->NewFrame();
Ctx.Gfx()->RenderDrawData(List->Data());
Ctx.Gfx()->RenderDrawData(ui7->GetDrawData()->Data());
/** Clear The List */
List->Clear();
PD::TT::End("REN");
PD::TT::End(*Ctx.Os(), "REN");
#ifndef __3DS__
/** Do OS Specifc Stuff (swapp buffers / window buttan events) */
glfwPollEvents();
@@ -221,3 +230,45 @@ int main() {
#endif
return 0;
}
#ifndef __3DS__
int main2() {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
#ifdef __APPLE__
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_COCOA_RETINA_FRAMEBUFFER, 0);
#else
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
#endif
glfwWindowHint(GLFW_SAMPLES, 8);
auto win = glfwCreateWindow(1280, 720, "Test", nullptr, nullptr);
glfwMakeContextCurrent(win);
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
auto Ctx = PD::Context::Create();
Ctx->UseOsDriver<PD::OsDriver>(nullptr);
Ctx->UseGfxDriver<PD::GfxGL2>(nullptr);
Ctx->UseHidDriver<PD::HidGLFW>(win);
Ctx->Gfx()->Init(); // Need to get rid of this
PD::Li::DrawList pDL(*Ctx);
pDL.DrawRectFilled(0, 50, 0xffffffff);
std::cout << Ctx->Os()->GetName() << std::endl;
std::cout << Ctx->Gfx()->GetName() << std::endl;
std::cout << Ctx->Hid()->GetName() << std::endl;
while (!glfwWindowShouldClose(win)) {
Ctx->Hid()->Update();
int wx, wy;
glfwGetWindowSize(win, &wx, &wy);
Ctx->Gfx()->SetViewPort(wx, wy);
glViewport(0, 0, wx, wy);
glClearColor(0.1, 0.1, 0.1, 1);
glClear(GL_COLOR_BUFFER_BIT);
Ctx->Gfx()->NewFrame();
Ctx->Gfx()->RenderDrawData(pDL.Data());
glfwPollEvents();
glfwSwapBuffers(win);
}
return 0;
}
#endif