diff --git a/config/SOUE01/config.yml b/config/SOUE01/config.yml index 6b4d9eb2..1058c731 100644 --- a/config/SOUE01/config.yml +++ b/config/SOUE01/config.yml @@ -21,6 +21,7 @@ force_active: [ "GetPaneRect__Q34nw4r3lyt4PaneCFRCQ34nw4r3lyt8DrawInfo", "SetFont__Q34nw4r3lyt7TextBoxFPCQ34nw4r2ut4Font", "GetTexMapAry__Q34nw4r3lyt8MaterialCFv", + "Set__Q34nw4r3lyt6TexMapFRC9_GXTexObj", ] # modules: diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 939fd8f0..7e9b5639 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -372,6 +372,10 @@ nw4r/lyt/lyt_material.cpp: .sdata2 start:0x8057F280 end:0x8057F2A0 .sbss2 start:0x8057FFB8 end:0x8057FFC0 +nw4r/lyt/lyt_texMap.cpp: + .text start:0x804905D0 end:0x80490980 + .sdata2 start:0x8057F2A0 end:0x8057F2B4 + nw4r/lyt/lyt_resourceAccessor.cpp: .text start:0x80492000 end:0x80492058 .data start:0x8056E7E0 end:0x8056E7F8 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 543d738a..99bac2dd 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -23909,8 +23909,8 @@ fn_804292D0 = .text:0x804292D0; // type:function size:0xFC fn_804293D0 = .text:0x804293D0; // type:function size:0x48 fn_80429420 = .text:0x80429420; // type:function size:0x230 fn_80429650 = .text:0x80429650; // type:function size:0x2D8 -fn_80429930 = .text:0x80429930; // type:function size:0x118 -fn_80429A50 = .text:0x80429A50; // type:function size:0x20 +TPLBind = .text:0x80429930; // type:function size:0x118 +TPLGet = .text:0x80429A50; // type:function size:0x20 fn_80429A70 = .text:0x80429A70; // type:function size:0x24 fn_80429A94 = .text:0x80429A94; // type:function size:0x24 fn_80429AB8 = .text:0x80429AB8; // type:function size:0x5C @@ -26049,8 +26049,8 @@ SetAnimationEnable__Q34nw4r3lyt8MaterialFRCQ34nw4r3lyt12AnimResourceb = .text:0x GetTextureSize__Q34nw4r3lyt6detailFPQ34nw4r3lyt8MaterialUc = .text:0x80490560; // type:function size:0x70 Get__Q34nw4r3lyt6TexMapCFP9_GXTexObj = .text:0x804905D0; // type:function size:0xEC Get__Q34nw4r3lyt6TexMapCFP10_GXTlutObj = .text:0x804906C0; // type:function size:0x1C -Set__Q34nw4r3lyt6TexMapFPCQ34nw4r3lyt6TexMap = .text:0x804906E0; // type:function size:0x14C -Set__Q34nw4r3lyt6TexMapFPC13TPLDescriptor = .text:0x80490830; // type:function size:0x74 +Set__Q34nw4r3lyt6TexMapFRC9_GXTexObj = .text:0x804906E0; // type:function size:0x14C +ReplaceImage__Q34nw4r3lyt6TexMapFRC9_GXTexObj = .text:0x80490830; // type:function size:0x74 ReplaceImage__Q34nw4r3lyt6TexMapFP10TPLPaletteUl = .text:0x804908B0; // type:function size:0xD0 __ct__Q34nw4r3lyt8DrawInfoFv = .text:0x80490980; // type:function size:0x74 __dt__Q34nw4r3lyt8DrawInfoFv = .text:0x80490A00; // type:function size:0x40 @@ -47582,7 +47582,7 @@ lbl_8057F290 = .sdata2:0x8057F290; // type:object size:0x4 data:float lbl_8057F298 = .sdata2:0x8057F298; // type:object size:0x8 data:double lbl_8057F2A0 = .sdata2:0x8057F2A0; // type:object size:0x4 data:float lbl_8057F2A8 = .sdata2:0x8057F2A8; // type:object size:0x8 data:double -lbl_8057F2B0 = .sdata2:0x8057F2B0; // type:object size:0x8 data:float +lbl_8057F2B0 = .sdata2:0x8057F2B0; // type:object size:0x4 data:float lbl_8057F2B8 = .sdata2:0x8057F2B8; // type:object size:0x4 data:float lbl_8057F2BC = .sdata2:0x8057F2BC; // type:object size:0x4 data:float lbl_8057F2C0 = .sdata2:0x8057F2C0; // type:object size:0x4 data:float diff --git a/configure.py b/configure.py index 8c4247ed..94e25745 100644 --- a/configure.py +++ b/configure.py @@ -361,6 +361,7 @@ config.libs = [ Object(Matching, "nw4r/lyt/lyt_window.cpp"), Object(Matching, "nw4r/lyt/lyt_bounding.cpp"), Object(Matching, "nw4r/lyt/lyt_material.cpp"), + Object(Matching, "nw4r/lyt/lyt_texMap.cpp"), Object(Matching, "nw4r/lyt/lyt_resourceAccessor.cpp"), Object(Matching, "nw4r/lyt/lyt_arcResourceAccessor.cpp"), Object(Matching, "nw4r/lyt/lyt_common.cpp"), diff --git a/include/nw4r/lyt/lyt_texMap.h b/include/nw4r/lyt/lyt_texMap.h index 5a6609a7..17898f4a 100644 --- a/include/nw4r/lyt/lyt_texMap.h +++ b/include/nw4r/lyt/lyt_texMap.h @@ -49,12 +49,28 @@ public: void Set(const TexMap &t) { *this = t; } + + // IDK how many of these Sets/ReplaceImage/SetNoWrap actually exist due to version changes + void Set(const GXTexObj &); + void Set(const GXTlutObj &); void Set(TPLPalette *, u32); void Set(const TPLDescriptor *); + void ReplaceImage(const TexMap &); + // guess, between set and replace image which just does the same thing as Set by only Image, Width, Height, and + // format + void ReplaceImage(const GXTexObj &); + void ReplaceImage(TPLPalette *, u32); + void ReplaceImage(const TPLDescriptor *); + void SetNoWrap(const TexMap &); + void SetNoWrap(const GXTexObj &); + void SetNoWrap(TPLPalette *, u32); void SetNoWrap(const TPLDescriptor *); + void SetTexParam(void *pImage, u16 width, u16 height, GXTexFmt format, GXTexWrapMode wrapS, GXTexWrapMode wrapT, + bool); + void *GetImage() const { return mpImage; } @@ -169,11 +185,6 @@ public: mBits.paletteFormat = fmt; } - // ReplaceImage__Q34nw4r3lyt6TexMapFP10TPLPaletteUl - void ReplaceImage(TPLPalette *pal, u32 id); - // ReplaceImage__Q34nw4r3lyt6TexMapFPC13TPLDescriptor - void ReplaceImage(TPLDescriptor *pTPLDesc); - private: void *mpImage; // at 0x00 void *mpPalette; // at 0x04 diff --git a/include/rvl/GX/GXInternal.h b/include/rvl/GX/GXInternal.h index 89507bfd..8d115a80 100644 --- a/include/rvl/GX/GXInternal.h +++ b/include/rvl/GX/GXInternal.h @@ -56,7 +56,27 @@ typedef struct _GXLightObjImpl { } GXLightObjImpl; typedef struct _GXTexObjImpl { - u8 todo[0x20]; + u32 dummy0; // at 0x00 + // -> 0x0x000003 | wrapS + // -> 0x0x00000C | wrapT + // -> 0x00000010 | magFilt + // -> 0x000000E0 | minFilt + // -> 0x00000100 | edgeLODEnable + // -> 0x0001FE00 | lodBias * 32 + // -> 0x00180000 | anisotropy + // -> 0x00200000 | biasClampEn + u32 dummy1; // at 0x04 + // -> 0x000000FF | minLOD * 16 + // -> 0x0000FF00 | maxLOD * 16 + u32 dummy2; // at 0x08 + // -> 0x000003FF | width - 1 + // -> 0x000FFC00 | height - 1 + u32 dummy3; // at 0x0C (( & 0xFFFFFF) << 5 -> ObjData) + u32 userData; // at 0x10 + u32 format; // at 0x14 + u32 tlutName; // at 0x18 + u32 dummy7; // at 0x1C + // -> 0x01000000 | MipMap } GXTexObjImpl; typedef struct _GXTlutObjImpl { diff --git a/include/rvl/GX/GXTexture.h b/include/rvl/GX/GXTexture.h index d6554e19..fa82a9e4 100644 --- a/include/rvl/GX/GXTexture.h +++ b/include/rvl/GX/GXTexture.h @@ -11,13 +11,23 @@ GX_DECL_PUBLIC_STRUCT(GXTlutObj, 12); void __GXSetSUTexRegs(void); -void GXInitTexObj(GXTexObj *, void *, u16, u16, GXTexFmt, GXTexWrapMode, GXTexWrapMode, u8); -void GXInitTexObjLOD(GXTexObj *, GXTexFilter, GXTexFilter, f32, f32, f32, u8, u8, GXAnisotropy); +void GXInitTexObj(GXTexObj *pTexObj, void *pImage, u16 width, u16 height, GXTexFmt format, GXTexWrapMode wrapS, + GXTexWrapMode wrapT, u8 mipmap); +void GXInitTexObjLOD(GXTexObj *pTexObj, GXTexFilter minFilter, GXTexFilter magFilter, f32 minLOD, f32 maxLOD, + f32 LODBias, u8 biasClampEnable, u8 edgeLODEnable, GXAnisotropy anisotropy); void GXInitTexObjTlut(GXTexObj *, u32); +void GXInitTexObjCI(GXTexObj *, void *, u16, u16, GXTexFmt, GXTexWrapMode, GXTexWrapMode, u8, u32); +void GXInitTlutObj(GXTlutObj *, void *, GXTlutFmt, u16); void GXLoadTlut(GXTlutObj *, u32); void GXLoadTexObj(GXTexObj *, GXTexMapID); +void GXGetTexObjAll(const GXTexObj *pTexObj, void **pImage, u16 *width, u16 *height, GXTexFmt *format, + GXTexWrapMode *wrapS, GXTexWrapMode *wrapT, u8 *mipmap); +void GXGetTexObjLODAll(const GXTexObj *pTexObj, GXTexFilter *minFilter, GXTexFilter *magFilter, f32 *minLOD, + f32 *maxLOD, f32 *LODBias, u8 *biasClampEnable, u8 *edgeLODEnable, GXAnisotropy *anisotropy); +u32 GXGetTexObjTlut(GXTexObj *); + #ifdef __cplusplus } #endif diff --git a/src/nw4r/lyt/lyt_texMap.cpp b/src/nw4r/lyt/lyt_texMap.cpp index e69de29b..6b65164a 100644 --- a/src/nw4r/lyt/lyt_texMap.cpp +++ b/src/nw4r/lyt/lyt_texMap.cpp @@ -0,0 +1,205 @@ +#include + +// NOTICE: This file seems to have been reworked. Not sure if all functions exist anymore, ReplaceImage doesnt even +// appear stripped in BBA, but is in tokyo friend park 2 DWARF. In NSMBW there seems to be more parameters for +// ReplaceImage as well. BBA map also shows calls to SetNoWrap from Set (GXTexObj variant), but the actual function +// shows no sign + +namespace nw4r { +namespace lyt { + +namespace { + +// CountLeadingZeros__24@unnamed@lyt_texMap_cpp@FUl + +} // namespace + +// Get__Q34nw4r3lyt6TexMapCFP9_GXTexObj +void TexMap::Get(GXTexObj *pTexObj) const { + if (detail::IsCITexelFormat(GetTexelFormat())) { + u32 tlutName = GXGetTexObjTlut(pTexObj); + GXInitTexObjCI(pTexObj, GetImage(), GetWidth(), GetHeight(), GetTexelFormat(), GetWrapModeS(), GetWrapModeT(), + IsMipMap(), tlutName); + } else { + GXInitTexObj(pTexObj, GetImage(), GetWidth(), GetHeight(), GetTexelFormat(), GetWrapModeS(), GetWrapModeT(), + IsMipMap()); + } + + GXInitTexObjLOD(pTexObj, GetMinFilter(), GetMagFilter(), GetMinLOD(), GetMaxLOD(), GetLODBias(), + IsBiasClampEnable(), IsEdgeLODEnable(), GetAnisotropy()); +} + +// Get__Q34nw4r3lyt6TexMapCFP10_GXTlutObj +void TexMap::Get(GXTlutObj *pTLUTObj) const { + GXInitTlutObj(pTLUTObj, GetPalette(), GetPaletteFormat(), GetPaletteEntryNum()); +} + +// Set__Q34nw4r3lyt6TexMapFRC9_GXTexObj +void TexMap::Set(const GXTexObj &pTexObj) { + void *pImage; + u16 width, height; + GXTexFmt format; + GXTexWrapMode wrapS, wrapT; + u8 mipmap; + GXGetTexObjAll(&pTexObj, &pImage, &width, &height, &format, &wrapS, &wrapT, &mipmap); + SetImage(pImage); + SetSize(width, height); + SetTexelFormat(format); + SetWrapMode(wrapS, wrapT); + SetMipMap(mipmap); + + GXTexFilter minFilter, magFilter; + f32 minLOD, maxLOD, LODBias; + u8 biasClampEnable, edgeLODEnable; + GXAnisotropy anisotropy; + GXGetTexObjLODAll(&pTexObj, &minFilter, &magFilter, &minLOD, &maxLOD, &LODBias, &biasClampEnable, &edgeLODEnable, + &anisotropy); + SetFilter(minFilter, magFilter); + SetLOD(minLOD, maxLOD); + SetLODBias(LODBias); + SetBiasClampEnable(biasClampEnable); + SetEdgeLODEnable(edgeLODEnable); + SetAnisotropy(anisotropy); +} + +// Set__Q34nw4r3lyt6TexMapFRC10_GXTlutObj + +// Set__Q34nw4r3lyt6TexMapFP10TPLPaletteUl +void TexMap::Set(TPLPalette *pal, u32 id) { + // Not yet converted from offset to pointer (unbound) + if ((unsigned int)pal->descriptors < 0x80000000) { + TPLBind(pal); + } + + Set(TPLGet(pal, id)); +} + +// Set__Q34nw4r3lyt6TexMapFPC13TPLDescriptor +void TexMap::Set(const TPLDescriptor *pTPLDesc) { + TPLHeader *tplHead = pTPLDesc->texHeader; + SetImage(tplHead->data); + SetSize(tplHead->width, tplHead->height); + SetTexelFormat(static_cast(tplHead->format)); + + bool bMipMap = (tplHead->minLod != tplHead->maxLod); + SetMipMap(bMipMap); + + SetFilter(tplHead->minFilt, tplHead->magFilt); + SetLOD(tplHead->minLod, tplHead->maxLod); + SetLODBias(tplHead->lodBias); + SetEdgeLODEnable(tplHead->edgeLodEnable); + + TPLClutHeader *pTPLCLUTHeader = pTPLDesc->clutHeader; + if (pTPLCLUTHeader != NULL) { + SetPalette(pTPLCLUTHeader->data); + SetPaletteFormat(pTPLCLUTHeader->format); + SetPaletteEntryNum(pTPLCLUTHeader->numEntries); + } else { + SetPalette(NULL); + SetPaletteFormat(GX_TL_IA8); + SetPaletteEntryNum(0); + } +} + +// ReplaceImage__Q34nw4r3lyt6TexMapFRC10_GXTlutObj +void TexMap::ReplaceImage(const GXTexObj &pTexObj) { + void *pImage; + u16 width, height; + GXTexFmt format; + GXTexWrapMode wrapS, wrapT; + u8 mipmap; + GXGetTexObjAll(&pTexObj, &pImage, &width, &height, &format, &wrapS, &wrapT, &mipmap); + SetImage(pImage); + SetSize(width, height); + SetTexelFormat(format); +} + +// ReplaceImage__Q34nw4r3lyt6TexMapFP10TPLPaletteUl +void TexMap::ReplaceImage(TPLPalette *pal, u32 id) { + // Not yet converted from offset to pointer (unbound) + if ((unsigned int)pal->descriptors < 0x80000000) { + TPLBind(pal); + } + + ReplaceImage(TPLGet(pal, id)); +} + +// ReplaceImage__Q34nw4r3lyt6TexMapFPC13TPLDescriptor +void TexMap::ReplaceImage(const TPLDescriptor *pTPLDesc) { + TPLHeader *tplHead = pTPLDesc->texHeader; + SetImage(tplHead->data); + SetSize(tplHead->width, tplHead->height); + SetTexelFormat(static_cast(tplHead->format)); + + TPLClutHeader *pTPLCLUTHeader = pTPLDesc->clutHeader; + if (pTPLCLUTHeader != NULL) { + SetPalette(pTPLCLUTHeader->data); + SetPaletteFormat(pTPLCLUTHeader->format); + SetPaletteEntryNum(pTPLCLUTHeader->numEntries); + } else { + SetPalette(NULL); + SetPaletteFormat(GX_TL_IA8); + SetPaletteEntryNum(0); + } +} + +// SetNoWrap__Q34nw4r3lyt6TexMapFRCQ34nw4r3lyt6TexMap +void TexMap::SetNoWrap(const TexMap &map) { + GXTexWrapMode wrapS = GetWrapModeS(); + GXTexWrapMode wrapT = GetWrapModeT(); + + Set(map); + SetWrapMode(wrapS, wrapT); +} + +// SetNoWrap__Q34nw4r3lyt6TexMapFRC9_GXTexObj +void TexMap::SetNoWrap(const GXTexObj &pTexObj) { + void *pImage; + u16 width, height; + GXTexFmt format; + GXTexWrapMode wrapS, wrapT; + u8 mipmap; + GXGetTexObjAll(&pTexObj, &pImage, &width, &height, &format, &wrapS, &wrapT, &mipmap); + SetImage(pImage); + SetSize(width, height); + SetTexelFormat(format); +} + +// SetNoWrap__Q34nw4r3lyt6TexMapFP10TPLPaletteUl +void TexMap::SetNoWrap(TPLPalette *pal, u32 id) {} + +// SetNoWrap__Q34nw4r3lyt6TexMapFPC13TPLDescriptor +void TexMap::SetNoWrap(const TPLDescriptor *pDescriptor) { + TPLHeader *tex = pDescriptor->texHeader; + SetImage(tex->data); + SetSize(tex->width, tex->height); + SetTexelFormat(static_cast(tex->format)); + + bool bMipMap = (tex->minLod != tex->maxLod); + SetMipMap(bMipMap); + + SetFilter(tex->minFilt, tex->magFilt); + SetLOD(tex->minLod, tex->maxLod); + SetLODBias(tex->lodBias); + SetEdgeLODEnable(tex->edgeLodEnable); + + TPLClutHeader *clut = pDescriptor->clutHeader; + if (clut != NULL) { + SetPalette(clut->data); + SetPaletteFormat(clut->format); + SetPaletteEntryNum(clut->numEntries); + } else { + SetPalette(NULL); + SetPaletteFormat(GX_TL_IA8); + SetPaletteEntryNum(0); + } +} + +// SetTexParam__Q34nw4r3lyt6TexMapFPvUsUs9_GXTexFmt14_GXTexWrapMode14_GXTexWrapModeb + +// SetLODParam__Q34nw4r3lyt6TexMapF12_GXTexFilter12_GXTexFilterfffbb13_GXAnisotropy + +// SetPaletteParam__Q34nw4r3lyt6TexMapFPv10_GXTlutFmtUs + +} // namespace lyt +} // namespace nw4r