GXUtility has one weird issue

This commit is contained in:
robojumper
2025-03-28 20:22:57 +01:00
parent b6db4eb100
commit 2d95f92cfe
4 changed files with 91 additions and 4 deletions
+1
View File
@@ -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
+1 -1
View File
@@ -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
+5 -2
View File
@@ -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
+84 -1
View File
@@ -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