From c76d6277a8a631740119f3bb219bba61f4e1ea98 Mon Sep 17 00:00:00 2001 From: Sonic Dreamcaster Date: Tue, 18 Feb 2025 20:12:11 -0300 Subject: [PATCH] Float precision rendering --- .vscode/c_cpp_properties.json | 3 ++- CMakeLists.txt | 1 + src/engine/fox_bg.c | 3 ++- src/libultra/gu/mtxutil.c | 24 ++++++++++++++++++------ src/sys/sys_matrix.c | 2 +- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index d2f8dd83..a8bccffc 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -17,7 +17,8 @@ "_LANGUAGE_C", "__sgi", "_MIPS_SZLONG=32", - "F3DEX_GBI" + "F3DEX_GBI", + "GBI_FLOATS" ], "cStandard": "gnu89", // C89 + some GNU extensions from C99 like C++ comments "cppStandard": "${default}" diff --git a/CMakeLists.txt b/CMakeLists.txt index 525123b7..f949fa0b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,7 @@ add_compile_definitions( NON_MATCHING=1 NON_EQUIVALENT=1 AVOID_UB=1 + GBI_FLOATS=1 ) # Find necessary libraries diff --git a/src/engine/fox_bg.c b/src/engine/fox_bg.c index 9af4f76c..983b5ca4 100644 --- a/src/engine/fox_bg.c +++ b/src/engine/fox_bg.c @@ -1249,6 +1249,7 @@ void AllRangeGround_Draw(void) { Matrix_Push(&gGfxMatrix); + // @port: Tag the transform. FrameInterpolation_RecordOpenChild("360Ground", i); Matrix_Translate(gGfxMatrix, sGroundPositions360x_FIX[i], 0.0f, sGroundPositions360z_FIX[i], MTXF_APPLY); @@ -1287,7 +1288,7 @@ void AllRangeGround_Draw(void) { } Matrix_Pop(&gGfxMatrix); - // @port: Tag the transform. + // @port: Pop the transform. FrameInterpolation_RecordCloseChild(); } } diff --git a/src/libultra/gu/mtxutil.c b/src/libultra/gu/mtxutil.c index e2da48e8..d68fc103 100644 --- a/src/libultra/gu/mtxutil.c +++ b/src/libultra/gu/mtxutil.c @@ -12,8 +12,13 @@ #include +#ifdef GBI_FLOATS +#include +#endif + +#ifndef GBI_FLOATS void guMtxF2L(float mf[4][4], Mtx* m) { - unsigned int r, c; + int r, c; s32 tmp1; s32 tmp2; s32* m1 = &m->m[0][0]; @@ -29,7 +34,7 @@ void guMtxF2L(float mf[4][4], Mtx* m) { } void guMtxL2F(float mf[4][4], Mtx* m) { - unsigned int r, c; + int r, c; u32 tmp1; u32 tmp2; u32* m1; @@ -48,9 +53,14 @@ void guMtxL2F(float mf[4][4], Mtx* m) { } } } +#else +void guMtxF2L(float mf[4][4], Mtx* m) { + memcpy(m, mf, sizeof(Mtx)); +} +#endif -void guMtxIdentF(f32 mf[4][4]) { - unsigned int r, c; +void guMtxIdentF(float mf[4][4]) { + int r, c; for (r = 0; r < 4; r++) { for (c = 0; c < 4; c++) { if (r == c) { @@ -63,9 +73,11 @@ void guMtxIdentF(f32 mf[4][4]) { } void guMtxIdent(Mtx* m) { +#ifndef GBI_FLOATS float mf[4][4]; - guMtxIdentF(mf); - guMtxF2L(mf, m); +#else + guMtxIdentF(m->mf); +#endif } diff --git a/src/sys/sys_matrix.c b/src/sys/sys_matrix.c index 6be1ea62..52c39180 100644 --- a/src/sys/sys_matrix.c +++ b/src/sys/sys_matrix.c @@ -493,7 +493,7 @@ void Matrix_ToMtx(Mtx* dest) { // Converts the Mtx src to a Matrix, putting the result in dest void Matrix_FromMtx(Mtx* src, Matrix* dest) { FrameInterpolation_RecordMatrixMtxFToMtx(src, dest); - guMtxF2L(src->m, dest->m); + guMtxF2L(src->mf, dest->m); } // Applies the transform matrix mtx to the vector src, putting the result in dest