summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobojumper <robojumper@gmail.com>2025-03-28 20:22:57 +0100
committerrobojumper <robojumper@gmail.com>2025-03-28 20:22:57 +0100
commit2d95f92cfec09e95cd6e559e9c76a23110376205 (patch)
tree19d390949c5e90b60ea81a55547c8ec0fc484a70
parentb6db4eb1005d7daf4d5f235a7f5b140e411856c4 (diff)
GXUtility has one weird issue
-rw-r--r--config/SOUE01/splits.txt1
-rw-r--r--config/SOUE01/symbols.txt2
-rw-r--r--include/egg/gfx/eggGXUtility.h7
-rw-r--r--src/egg/gfx/eggGXUtility.cpp85
4 files changed, 91 insertions, 4 deletions
diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt
index 03669cd1..f4ce347e 100644
--- a/config/SOUE01/splits.txt
+++ b/config/SOUE01/splits.txt
@@ -2252,6 +2252,7 @@ egg/gfx/eggGlobalDrawState.cpp:
egg/gfx/eggGXUtility.cpp:
.text start:0x804A7820 end:0x804A7BC0
+ .sdata2 start:0x8057F640 end:0x8057F678
egg/gfx/eggIScnProc.cpp:
.text start:0x804A7BC0 end:0x804A7F7C
diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt
index 7f9823ab..81f62ff6 100644
--- a/config/SOUE01/symbols.txt
+++ b/config/SOUE01/symbols.txt
@@ -48096,7 +48096,7 @@ lbl_8057F62C = .sdata2:0x8057F62C; // type:object size:0x4 data:float
lbl_8057F630 = .sdata2:0x8057F630; // type:object size:0x4 data:float
lbl_8057F634 = .sdata2:0x8057F634; // type:object size:0x4 data:float
lbl_8057F638 = .sdata2:0x8057F638; // type:object size:0x4 data:float
-EGG__GXUtility__sTexMtxIDs = .sdata2:0x8057F640; // type:object size:0x8
+s_texMtxIds__Q23EGG9GXUtility = .sdata2:0x8057F640; // type:object size:0x8
lbl_8057F648 = .sdata2:0x8057F648; // type:object size:0x4 data:float
lbl_8057F64C = .sdata2:0x8057F64C; // type:object size:0x4 data:float
lbl_8057F650 = .sdata2:0x8057F650; // type:object size:0x4 data:float
diff --git a/include/egg/gfx/eggGXUtility.h b/include/egg/gfx/eggGXUtility.h
index cba929e6..f85f56e0 100644
--- a/include/egg/gfx/eggGXUtility.h
+++ b/include/egg/gfx/eggGXUtility.h
@@ -12,11 +12,14 @@ namespace EGG {
class GXUtility {
public:
static int getTexMtxID(int);
- static void getTexObj(GXTexObj *, const EGG::ResTIMG &);
+ static void setScaleOffsetPerspective(f32*, f32, f32, f32, f32);
+ static void getTexObj(GXTexObj *, const ResTIMG &);
static void getTexObj(GXTexObj *, nw4r::g3d::ResTex, GXTexWrapMode, GXTexWrapMode, GXTexFilter, GXTexFilter);
static void getNormalColor(GXColor &outColor, const Vector3f &vec);
- static void setScaleOffsetPerspective(f32*, f32, f32, f32, f32);
+
+private:
+ static const u8 s_texMtxIds[8];
};
} // namespace EGG
diff --git a/src/egg/gfx/eggGXUtility.cpp b/src/egg/gfx/eggGXUtility.cpp
index 43963b51..09f0390c 100644
--- a/src/egg/gfx/eggGXUtility.cpp
+++ b/src/egg/gfx/eggGXUtility.cpp
@@ -1,3 +1,86 @@
#include "egg/gfx/eggGXUtility.h"
-namespace EGG {} // namespace EGG
+#include "egg/gfx/eggTexture.h"
+#include "rvl/GX/GXTexture.h"
+#include "rvl/GX/GXTypes.h"
+
+namespace EGG {
+
+const u8 GXUtility::s_texMtxIds[8] = {30, 33, 36, 39, 42, 45, 48, 51};
+
+int GXUtility::getTexMtxID(int idx) {
+ return s_texMtxIds[idx];
+}
+
+void GXUtility::setScaleOffsetPerspective(f32 *pOut, f32 f1, f32 f2, f32 f3, f32 f4) {
+ pOut[1] *= (1.0f / f1);
+ pOut[3] *= (1.0f / f2);
+ pOut[2] += f3;
+ pOut[4] += f4;
+}
+
+void GXUtility::getTexObj(GXTexObj *obj, const ResTIMG &img) {
+ u32 offset = img.imageOffset != 0 ? img.imageOffset : sizeof(ResTIMG);
+ void *pImage = const_cast<void *>(reinterpret_cast<const void *>(reinterpret_cast<const u8 *>(&img) + offset));
+ // Missing a redundant register move here (obj r30->r3)
+ GXInitTexObj(
+ obj, pImage, img.width, img.height, static_cast<GXTexFmt>(img.format), static_cast<GXTexWrapMode>(img.wrapS),
+ static_cast<GXTexWrapMode>(img.wrapT), img.mipmapEnabled != 0
+ );
+ GXInitTexObjLOD(
+ obj, static_cast<GXTexFilter>(img.minFilter), static_cast<GXTexFilter>(img.magFilter), img.minLOD / 8.0f,
+ img.maxLOD / 8.0f, img.LODBias / 100.0f, img.biasClamp, img.doEdgeLOD,
+ static_cast<GXAnisotropy>(img.maxAnisotropy)
+ );
+}
+
+void GXUtility::getTexObj(
+ GXTexObj *obj, nw4r::g3d::ResTex resTex, GXTexWrapMode wrapS, GXTexWrapMode wrapT, GXTexFilter minFilter,
+ GXTexFilter magFilter
+) {
+ void *pTexData;
+ u16 width;
+ u16 height;
+ GXTexFmt format;
+ f32 minLod;
+ f32 maxLod;
+ GXBool mipMap;
+ if (resTex.GetTexObjParam(&pTexData, &width, &height, &format, &minLod, &maxLod, &mipMap)) {
+ GXInitTexObj(obj, pTexData, width, height, format, wrapS, wrapT, mipMap);
+ GXInitTexObjLOD(obj, minFilter, magFilter, minLod, maxLod, 0.0f, false, false, GX_ANISO_1);
+ }
+}
+
+void GXUtility::getNormalColor(GXColor &outColor, const Vector3f &vec) {
+ // Are there inlines that might work here? Probably!
+ f32 fs[3];
+ f32 g = vec.z < 0.0f ? vec.y * 128.0f + 128.0f - 0.5f : vec.z * 127.0f + 128.0f + 0.5f;
+ f32 b = vec.y < 0.0f ? vec.y * 128.0f + 128.0f - 0.5f : vec.y * 127.0f + 128.0f + 0.5f;
+ f32 a = vec.x < 0.0f ? vec.x * 128.0f + 128.0f - 0.5f : vec.x * 127.0f + 128.0f + 0.5f;
+
+ fs[0] = a;
+ fs[1] = b;
+ fs[2] = g;
+
+ if (fs[0] < 0.0f) {
+ fs[0] = 0.0f;
+ } else if (fs[0] > 255.0f) {
+ fs[0] = 255.0f;
+ }
+ if (fs[1] < 0.0f) {
+ fs[1] = 0.0f;
+ } else if (fs[1] > 255.0f) {
+ fs[1] = 255.0f;
+ }
+ if (fs[2] < 0.0f) {
+ fs[2] = 0.0f;
+ } else if (fs[2] > 255.0f) {
+ fs[2] = 255.0f;
+ }
+
+ outColor.a = fs[0];
+ outColor.b = fs[1];
+ outColor.g = fs[2];
+}
+
+} // namespace EGG