# Changes

3ds Backend:
  - switch to shaderProgramUse
Desktop Backend
  - Add Pre Alpha Text Input and Keyboard Support
  - Move Shader Attrib Setup into a function and callit every time we need a set up vbo
  - Move to Mat4 api
Core:
  - Add fquat support
  - Add LoadFile2Str
  - Move Mat4 Lib from Project     n73 to Palladium
  - Add full supprot for vec cross types
  - Add Normalize, Distance and Dot to all
  - Add Cross to vec3
Drivers:
  - Add a SetViewPort func to GFX
  - Add Keyboard keys and Flasg to Hid
Image:
  - Add Vertical Flipping
  - Add Horizontal flipping
UI7:
  - Fix Critical Bug in IO Viewport handler
  - Fix library list (error on MinGW for some reason)
Lazyvec:
  - Split into multiple source files
  - Generate new functions (see core updates)
This commit is contained in:
2025-07-23 23:21:34 +02:00
parent 31a0c3656f
commit 87910b57de
31 changed files with 1085 additions and 276 deletions

View File

@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include <array>
#include <chrono>
#include <cinttypes>
#include <cmath>
@ -33,6 +34,7 @@ SOFTWARE.
#include <iostream>
#include <map>
#include <memory>
#include <numbers>
#include <sstream>
#include <stack>
#include <string>

55
include/pd/core/fquat.hpp Normal file
View File

@ -0,0 +1,55 @@
#pragma once
/*
MIT License
Copyright (c) 2024 - 2025 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.
*/
// This file is based on fvec4
#include <pd/core/common.hpp>
#include <pd/core/vec4.hpp>
namespace PD {
class fquat : public fvec4 {
constexpr fquat() : fvec4(0.f, 0.f, 0.f, 1.f) {}
constexpr fquat(float x, float y, float z, float w) : fvec4(x, y, z, w) {}
constexpr fquat(const fvec4& v) : fvec4(v) {}
static fquat Identity() { return fquat(0.f, 0.f, 0.f, 1.f); }
constexpr fquat Conjugate() const { return fquat(-x, -y, -z, w); }
fquat Inverse() const {
float len = SqLen();
if (len == 0.0f) {
return fquat();
}
return Conjugate() / len;
}
fquat operator*(const fquat& v) const {
return fquat(w * v.x + x * v.w + y * v.z - z * v.y,
w * v.y - x * v.z + y * v.w + z * v.x,
w * v.z + x * v.y - y * v.x + z * v.w,
w * v.w - x * v.x - y * v.y - z * v.z);
}
};
} // namespace PD

View File

@ -36,6 +36,12 @@ namespace IO {
* @return 8Bit FileBuffer
*/
PD_CORE_API std::vector<u8> LoadFile2Mem(const std::string& path);
/**
* Load a File into a std::string
* @param path Path to the File
* @return std::string file content
*/
PD_CORE_API std::string LoadFile2Str(const std::string& path);
/**
* Hash a 8Bit Memory Buffer
* @param data 8Bit input Buffer

View File

@ -25,17 +25,118 @@ SOFTWARE.
*/
#include <pd/core/common.hpp>
#include <pd/core/vec3.hpp>
namespace PD {
class PD_CORE_API Mat4 {
public:
Mat4() { Zeros(); }
~Mat4() = default;
namespace Numbers {
constexpr float Tau = std::numbers::pi * 2.f;
}
constexpr float Radians(float v) { return v * (Numbers::Tau / 360.0f); }
/**
* Minimal Mtx4 Lib that precomputes
* basic stuff stuff at compiletime
*
* This Lib includes Patches for work with Citro3D as well
*
* @note That this is not a full Matrix Library
*/
void Zeros();
void Ortho(float left, float right, float bottom, float top, float near,
float far);
struct PD_CORE_API Mat4 {
std::array<float, 16> m;
constexpr Mat4() : m{} {}
constexpr static Mat4 Diagonal(float x, float y, float z, float w) {
Mat4 ret;
ret(0, 0) = x;
ret(1, 1) = y;
ret(2, 2) = z;
ret(3, 3) = w;
return ret;
}
constexpr static Mat4 Identity() { return Diagonal(1, 1, 1, 1); }
float m[16];
constexpr float* Ptr() { return m.data(); }
constexpr const float* Ptr() const { return m.data(); }
constexpr float& operator()(int row, int col) {
#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 {
#ifdef __3DS__
// 3ds is full reverse order iirc
return m[row * 4 + (3 - col)];
#else
return m[col * 4 + row];
#endif
}
constexpr Mat4 operator*(const Mat4& v) const {
Mat4 ret;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
float t = 0.f;
for (int k = 0; k < 4; k++) {
t += (*this)(i, k) * v(k, j);
}
ret(i, j) = t;
}
}
return ret;
}
constexpr Mat4& operator*=(const Mat4& v) {
*this = *this * v;
return *this;
}
constexpr static Mat4 Translate(float x, float y, float z) {
Mat4 ret = Identity();
ret(0, 3) = x;
ret(1, 3) = y;
ret(2, 3) = z;
return ret;
}
constexpr static Mat4 Scale(float x, float y, float z) {
Mat4 ret;
ret(0, 0) = x;
ret(1, 1) = y;
ret(2, 2) = z;
ret(3, 3) = 1.f;
return ret;
}
constexpr static Mat4 Ortho(float l, float r, float b, float t, float n,
float f) {
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, 3) = -(r + l) / (r - l);
ret(1, 1) = 2.0f / (t - b);
ret(1, 3) = -(t + b) / (t - b);
ret(2, 2) = -2.0f / (f - n);
ret(2, 3) = -(f + n) / (f - n);
#endif
ret(3, 3) = 1.f;
return ret;
}
static Mat4 Rotate(fvec3 axis, float a);
static Mat4 RotateX(float a);
static Mat4 RotateY(float a);
static Mat4 RotateZ(float a);
static Mat4 Perspective(float fov, float aspect, float n, float f);
static Mat4 LookAt(const fvec3& pos, const fvec3& center, const fvec3& up);
};
} // namespace PD

View File

@ -23,7 +23,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// This file is generated by lazyvec
// This file is generated by lazyvec 2.0.0
#include <pd/core/common.hpp>
namespace PD {
@ -33,20 +34,24 @@ class vec2 {
T x;
T y;
vec2() : x(0), y(0) {}
// Constructors
constexpr vec2() : x(0), y(0) {}
template <typename T1>
vec2(T1 v) {
constexpr vec2(T1 v) {
x = (T)v;
y = (T)v;
}
template <typename T1>
vec2(vec2<T1> v) {
constexpr vec2(const vec2<T1>& v) {
x = (T)v.x;
y = (T)v.y;
}
vec2(T x, T y) : x(x), y(y) {}
constexpr explicit vec2(T x, T y) : x(x), y(y) {}
// Operations
template <typename T1>
vec2<T>& operator+=(T1 v) {
@ -144,14 +149,42 @@ class vec2 {
return vec2<T>(x / (T)v.x, y / (T)v.y);
}
vec2 operator-() const { return vec2(-x, -y); }
// Generic Operations
bool operator==(const vec2& v) const { return x == v.x && y == v.y; }
bool operator!=(const vec2& v) const { return !(*this == v); }
vec2 operator-() const { return vec2(-x, -y); }
template <typename T1>
bool operator==(const vec2<T1>& v) const {
return x == (T)v.x && y == (T)v.y;
}
template <typename T1>
bool operator!=(const vec2<T1>& v) const {
return !(*this == v);
}
// Functions
double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y; }
template <typename T1>
double Distance(const vec2<T1>& v) const {
return (*this - v).Len();
}
vec2<T> Normalize() const {
double l = Len();
if (l == 0) {
return *this;
}
return *this / (T)l;
}
template <typename T1>
T Dot(const vec2<T1>& v) const {
return x * (T)v.x + y * (T)v.y;
}
// Swap Functions
void SwapXY() {
T t = x;
x = y;
@ -159,6 +192,6 @@ class vec2 {
}
};
using fvec2 = vec2<float>;
using dvec2 = vec2<double>;
using ivec2 = vec2<int>;
using dvec2 = vec2<double>;
} // namespace PD

View File

@ -23,8 +23,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// This file is generated by lazyvec
// This file is generated by lazyvec 2.0.0
#include <pd/core/common.hpp>
// Extended includes (rename if you use other filenames/paths)
#include <pd/core/vec2.hpp>
namespace PD {
template <typename T>
@ -34,22 +37,36 @@ class vec3 {
T y;
T z;
vec3() : x(0), y(0), z(0) {}
// Constructors
constexpr vec3() : x(0), y(0), z(0) {}
template <typename T1>
explicit vec3(T1 v) {
constexpr vec3(T1 v) {
x = (T)v;
y = (T)v;
z = (T)v;
}
template <typename T1>
explicit vec3(vec3<T1> v) {
constexpr vec3(const vec3<T1>& v) {
x = (T)v.x;
y = (T)v.y;
z = (T)v.z;
}
vec3(T x, T y, T z) : x(x), y(y), z(z) {}
constexpr explicit vec3(T x, T y, T z) : x(x), y(y), z(z) {}
// Extended Constructors
template <typename T1>
constexpr explicit vec3(const vec2<T1>& xy, T1 z) {
{
x = (T)xy.x;
y = (T)xy.y;
this->z = (T)z;
}
}
// Operations
template <typename T1>
vec3<T>& operator+=(T1 v) {
@ -155,16 +172,47 @@ class vec3 {
return vec3<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z);
}
vec3 operator-() const { return vec3(-x, -y, -z); }
// Generic Operations
bool operator==(const vec3& v) const {
return x == v.x && y == v.y && z == v.z;
vec3 operator-() const { return vec3(-x, -y, -z); }
template <typename T1>
bool operator==(const vec3<T1>& v) const {
return x == (T)v.x && y == (T)v.y && z == (T)v.z;
}
bool operator!=(const vec3& v) const { return !(*this == v); }
template <typename T1>
bool operator!=(const vec3<T1>& v) const {
return !(*this == v);
}
// Functions
double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y + z * z; }
template <typename T1>
double Distance(const vec3<T1>& v) const {
return (*this - v).Len();
}
vec3<T> Normalize() const {
double l = Len();
if (l == 0) {
return *this;
}
return *this / (T)l;
}
template <typename T1>
T Dot(const vec3<T1>& v) const {
return x * (T)v.x + y * (T)v.y + z * (T)v.z;
}
template <typename T1>
vec3<T> Cross(const vec3<T1>& v) const {
return vec3<T>(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
}
// Swap Functions
void SwapXY() {
T t = x;
x = y;
@ -182,6 +230,6 @@ class vec3 {
}
};
using fvec3 = vec3<float>;
using dvec3 = vec3<double>;
using ivec3 = vec3<int>;
using dvec3 = vec3<double>;
} // namespace PD

View File

@ -23,9 +23,12 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
// This file is generated by lazyvec
// This file is generated by lazyvec 2.0.0
#include <pd/core/common.hpp>
#include <pd/core/vec2.hpp> // Extended
// Extended includes (rename if you use other filenames/paths)
#include <pd/core/vec2.hpp>
#include <pd/core/vec3.hpp>
namespace PD {
template <typename T>
@ -36,9 +39,11 @@ class vec4 {
T z;
T w;
vec4() : x(0), y(0), z(0), w(0) {}
// Constructors
constexpr vec4() : x(0), y(0), z(0), w(0) {}
template <typename T1>
explicit vec4(T1 v) {
constexpr vec4(T1 v) {
x = (T)v;
y = (T)v;
z = (T)v;
@ -46,23 +51,37 @@ class vec4 {
}
template <typename T1>
explicit vec4(vec4<T1> v) {
constexpr vec4(const vec4<T1>& v) {
x = (T)v.x;
y = (T)v.y;
z = (T)v.z;
w = (T)v.w;
}
/** Extended Constructor */
constexpr explicit vec4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {}
// Extended Constructors
template <typename T1>
explicit vec4(vec2<T1> a, vec2<T1> b) {
x = (T)a.x;
y = (T)a.y;
z = (T)b.x;
w = (T)b.y;
constexpr explicit vec4(const vec2<T1>& xy, const vec2<T1>& zw) {
{
x = (T)xy.x;
y = (T)xy.y;
z = (T)zw.x;
w = (T)zw.y;
}
}
vec4(T x, T y, T z, T w) : x(x), y(y), z(z), w(w) {}
template <typename T1>
constexpr explicit vec4(const vec3<T1>& xyz, T1 w) {
{
x = (T)xyz.x;
y = (T)xyz.y;
z = (T)xyz.z;
this->w = (T)w;
}
}
// Operations
template <typename T1>
vec4<T>& operator+=(T1 v) {
@ -176,16 +195,42 @@ class vec4 {
return vec4<T>(x / (T)v.x, y / (T)v.y, z / (T)v.z, w / (T)v.w);
}
vec4 operator-() const { return vec4(-x, -y, -z, -w); }
// Generic Operations
bool operator==(const vec4& v) const {
return x == v.x && y == v.y && z == v.z && w == v.w;
vec4 operator-() const { return vec4(-x, -y, -z, -w); }
template <typename T1>
bool operator==(const vec4<T1>& v) const {
return x == (T)v.x && y == (T)v.y && z == (T)v.z && w == (T)v.w;
}
bool operator!=(const vec4& v) const { return !(*this == v); }
template <typename T1>
bool operator!=(const vec4<T1>& v) const {
return !(*this == v);
}
// Functions
double Len() const { return std::sqrt(SqLen()); }
double SqLen() const { return x * x + y * y + z * z + w * w; }
template <typename T1>
double Distance(const vec4<T1>& v) const {
return (*this - v).Len();
}
vec4<T> Normalize() const {
double l = Len();
if (l == 0) {
return *this;
}
return *this / (T)l;
}
template <typename T1>
T Dot(const vec4<T1>& v) const {
return x * (T)v.x + y * (T)v.y + z * (T)v.z + w * (T)v.w;
}
// Swap Functions
void SwapXY() {
T t = x;
x = y;
@ -218,6 +263,6 @@ class vec4 {
}
};
using fvec4 = vec4<float>;
using dvec4 = vec4<double>;
using ivec4 = vec4<int>;
using dvec4 = vec4<double>;
} // namespace PD