# 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

@ -39,6 +39,20 @@ PD_CORE_API std::vector<u8> LoadFile2Mem(const std::string& path) {
return res;
}
PD_CORE_API std::string LoadFile2Str(const std::string& path) {
std::ifstream iff(path, std::ios::binary);
if (!iff) {
return "";
}
std::string ret;
std::string line;
while (std::getline(iff, line)) {
ret += line;
}
iff.close();
return ret;
}
PD_CORE_API u32 HashMemory(const std::vector<u8>& data) {
u32 hash = 4477;
for (auto& it : data) {

View File

@ -25,32 +25,98 @@ SOFTWARE.
#include <pd/core/mat.hpp>
namespace PD {
PD_CORE_API void Mat4::Zeros() {
for (int i = 0; i < 16; i++) {
m[i] = 0.0f;
}
PD_CORE_API Mat4 Mat4::RotateX(float a) {
float c = std::cos(a);
float s = std::sin(a);
Mat4 ret = Identity();
ret(1, 1) = c;
ret(1, 2) = -s;
ret(2, 1) = s;
ret(2, 2) = c;
return ret;
}
PD_CORE_API void Mat4::Ortho(float left, float right, float bottom, float top,
float near, float far) {
m[0] = 2.0f / (right - left);
m[1] = 0.0f;
m[2] = 0.0f;
m[3] = -(right + left) / (right - left);
PD_CORE_API Mat4 Mat4::RotateY(float a) {
float c = std::cos(a);
float s = std::sin(a);
Mat4 ret = Identity();
ret(0, 0) = c;
ret(0, 2) = s;
ret(2, 0) = -s;
ret(2, 2) = c;
return ret;
}
m[4] = 0.0f;
m[5] = 2.0f / (top - bottom);
m[6] = 0.0f;
m[7] = -(top + bottom) / (top - bottom);
PD_CORE_API Mat4 Mat4::RotateZ(float a) {
float c = std::cos(a);
float s = std::sin(a);
Mat4 ret = Identity();
ret(0, 0) = c;
ret(0, 1) = -s;
ret(1, 0) = s;
ret(1, 1) = c;
return ret;
}
m[8] = 0.0f;
m[9] = 0.0f;
m[10] = -2.0f / (far - near);
m[11] = -(far + near) / (far - near);
PD_CORE_API Mat4 Mat4::Rotate(fvec3 axis, float a) {
float s = std::sin(a);
float c = std::cos(a);
float t = 1.f - c;
axis = axis.Normalize();
float x = axis.x;
float y = axis.y;
float z = axis.z;
Mat4 ret = Identity();
ret(0, 0) = t * x * x + c;
ret(0, 1) = t * x * y - z * s;
ret(0, 2) = t * x * z + y * s;
m[12] = 0.0f;
m[13] = 0.0f;
m[14] = 0.0f;
m[15] = 1.0f;
ret(1, 0) = t * x * y + z * s;
ret(1, 1) = t * y * y + c;
ret(1, 2) = t * y * z - x * s;
ret(2, 0) = t * x * z - y * s;
ret(2, 1) = t * y * z + x * s;
ret(2, 2) = t * z * z + c;
return ret;
}
PD_CORE_API Mat4 Mat4::Perspective(float fov, float aspect, float n, float f) {
float _fov = std::tan(fov / 2.f);
Mat4 ret;
ret(0, 0) = 1.f / (aspect * _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, 3) = -(2.f * f * n) / (f - n);
#endif
ret(3, 2) = -1.f;
ret(3, 3) = 0.0f;
return ret;
}
PD_CORE_API Mat4 Mat4::LookAt(const fvec3& pos, const fvec3& center,
const fvec3& up) {
auto f = fvec3(center - pos).Normalize();
auto s = f.Cross(up).Normalize();
auto u = s.Cross(f);
Mat4 ret = Identity();
ret(0, 0) = s.x;
ret(0, 1) = s.y;
ret(0, 2) = s.z;
ret(1, 0) = u.x;
ret(1, 1) = u.y;
ret(1, 2) = u.z;
ret(2, 0) = -f.x;
ret(2, 1) = -f.y;
ret(2, 2) = -f.z;
ret(0, 3) = -s.Dot(pos);
ret(1, 3) = -u.Dot(pos);
ret(2, 3) = f.Dot(pos);
return ret;
}
} // namespace PD

View File

@ -5,6 +5,12 @@ namespace PD {
PD_DEF_EXP(HidDriver::Ref, Hid::pHid);
bool HidDriver::IsEvent(Event e, Key keys) { return KeyEvents[0][e] & keys; }
bool HidDriver::IsEvent(Event e, KbKey key) {
if (!KbKeyEvents[0].count(key)) {
return false;
}
return KbKeyEvents[0][key] == e;
}
void HidDriver::SwapTab() {
auto tkd = KeyEvents[1][Event_Down];

View File

@ -77,6 +77,46 @@ PD_IMAGE_API void Image::Copy(const std::vector<u8>& buf, int w, int h,
}
}
PD_IMAGE_API void Image::FlipHorizontal() {
/**
* Dont know if i am brain dead but i think this code
* should Horizpntal flip an image
* Probably this needs some optimisation like not always calling
* Fmt2Bpp and use `* 0.5` instead of `/ 2` i guess
*/
for (int i = 0; i < pWidth / 2; i++) {
for (int j = 0; j < pHeight; j++) {
int src = (j * pWidth + i) * Fmt2Bpp(pFmt);
int dst = (j * pWidth + (pWidth - 1 - i)) * Fmt2Bpp(pFmt);
for (int k = 0; k < Fmt2Bpp(pFmt); k++) {
PD::u8 tmp = pBuffer[dst + k];
pBuffer[dst + k] = pBuffer[src + k];
pBuffer[src + k] = tmp;
}
}
}
}
PD_IMAGE_API void Image::FlipVertical() {
/**
* Dont know if i am brain dead but i think this code
* should Vertical flip an image
* Probably this needs some optimisation like not always calling
* Fmt2Bpp and use `* 0.5` instead of `/ 2` i guess
*/
for (int i = 0; i < pWidth; i++) {
for (int j = 0; j < pHeight / 2; j++) {
int src = (j * pWidth + i) * Fmt2Bpp(pFmt);
int dst = ((pHeight - 1 - j) * pWidth + i) * Fmt2Bpp(pFmt);
for (int k = 0; k < Fmt2Bpp(pFmt); k++) {
PD::u8 tmp = pBuffer[dst + k];
pBuffer[dst + k] = pBuffer[src + k];
pBuffer[src + k] = tmp;
}
}
}
}
PD_IMAGE_API void Image::Convert(Image::Ref img, Image::Format dst) {
if (img->pFmt == dst) {
return;

View File

@ -25,4 +25,4 @@ else()
pd_add_lib(pd-ui7 SRC_FILES ${SRC})
endif()
target_link_libraries(pd-ui7 PUBLIC pd-core)
target_link_libraries(pd-ui7 PUBLIC pd-lithium pd-core)