diff --git a/libs/JSystem/include/JSystem/J3DGraphBase/J3DTexture.h b/libs/JSystem/include/JSystem/J3DGraphBase/J3DTexture.h index 5b05b08bcc..516ddac887 100644 --- a/libs/JSystem/include/JSystem/J3DGraphBase/J3DTexture.h +++ b/libs/JSystem/include/JSystem/J3DGraphBase/J3DTexture.h @@ -20,7 +20,7 @@ private: /* 0x4 */ ResTIMG* mpRes; #if TARGET_PC - GXTlutObj* mpTlutObj; + TGXTlutObj* mpTlutObj; TGXTexObj* mpTexObj; u8** mpImgDataPtr; u8** mpTlutDataPtr; @@ -31,20 +31,22 @@ public: J3D_ASSERT_NULLPTR(52, res != NULL || num == 0); #if TARGET_PC mpTexObj = new TGXTexObj[num]; - mpTlutObj = new GXTlutObj[num]; + mpTlutObj = new TGXTlutObj[num]; mpImgDataPtr = new u8*[num]; mpTlutDataPtr = new u8*[num]; for (u16 i = 0; i < num; i++) { mpImgDataPtr[i] = (u8*)(&mpRes[i]) + mpRes[i].imageOffset; mpTlutDataPtr[i] = (u8*)(&mpRes[i]) + mpRes[i].paletteOffset; - loadGXTexObj(i); + initGXTexObj(i); } #endif } void loadGX(u16, GXTexMapID) const; #if TARGET_PC - void loadGXTexObj(u16); + void initGXTexObj(u16); + TGXTexObj* getTexObj(u16 i) const { return &mpTexObj[i]; } + TGXTlutObj* getTlutObj(u16 i) const { return &mpTlutObj[i]; } #endif void entryNum(u16); void addResTIMG(u16, ResTIMG const*); @@ -77,7 +79,7 @@ public: #if TARGET_PC mpImgDataPtr[index] = ((u8*)&timg) + timg.imageOffset; mpTlutDataPtr[index] = ((u8*)&timg) + timg.paletteOffset; - loadGXTexObj(index); + initGXTexObj(index); #else mpRes[index].imageOffset = ((mpRes[index].imageOffset + (uintptr_t)&timg - (uintptr_t)(mpRes + index))); mpRes[index].paletteOffset = ((mpRes[index].paletteOffset + (uintptr_t)&timg - (uintptr_t)(mpRes + index))); diff --git a/libs/JSystem/src/J3DGraphBase/J3DMatBlock.cpp b/libs/JSystem/src/J3DGraphBase/J3DMatBlock.cpp index f401f16c43..dada6a19e8 100644 --- a/libs/JSystem/src/J3DGraphBase/J3DMatBlock.cpp +++ b/libs/JSystem/src/J3DGraphBase/J3DMatBlock.cpp @@ -246,22 +246,37 @@ s32 J3DTexGenBlockBasic::countDLSize() { } s32 J3DTevBlockPatched::countDLSize() { +#if TARGET_PC + return 2048; +#endif return 560; } s32 J3DTevBlock1::countDLSize() { +#if TARGET_PC + return 256; +#endif return 105; } s32 J3DTevBlock2::countDLSize() { +#if TARGET_PC + return 512; +#endif return 335; } s32 J3DTevBlock4::countDLSize() { +#if TARGET_PC + return 1024; +#endif return 580; } s32 J3DTevBlock16::countDLSize() { +#if TARGET_PC + return 2048; +#endif return 1000; } diff --git a/libs/JSystem/src/J3DGraphBase/J3DMaterial.cpp b/libs/JSystem/src/J3DGraphBase/J3DMaterial.cpp index ac3b393c81..38462ba171 100644 --- a/libs/JSystem/src/J3DGraphBase/J3DMaterial.cpp +++ b/libs/JSystem/src/J3DGraphBase/J3DMaterial.cpp @@ -218,9 +218,6 @@ void J3DMaterial::makeSharedDisplayList() { void J3DMaterial::load() { j3dSys.setMaterialMode(mMaterialMode); -#if TARGET_PC - mTevBlock->loadTexture(); -#endif if (!j3dSys.checkFlag(2)) { loadNBTScale(*mTexGenBlock->getNBTScale()); } @@ -228,9 +225,6 @@ void J3DMaterial::load() { void J3DMaterial::loadSharedDL() { j3dSys.setMaterialMode(mMaterialMode); -#if TARGET_PC - mTevBlock->loadTexture(); -#endif if (!j3dSys.checkFlag(2)) { mSharedDLObj->callDL(); loadNBTScale(*mTexGenBlock->getNBTScale()); @@ -409,9 +403,6 @@ void J3DPatchedMaterial::makeSharedDisplayList() {} void J3DPatchedMaterial::load() { j3dSys.setMaterialMode(mMaterialMode); -#if TARGET_PC - mTevBlock->loadTexture(); -#endif if (j3dSys.checkFlag(2)) { return; } @@ -419,9 +410,6 @@ void J3DPatchedMaterial::load() { void J3DPatchedMaterial::loadSharedDL() { j3dSys.setMaterialMode(mMaterialMode); -#if TARGET_PC - mTevBlock->loadTexture(); -#endif if (!j3dSys.checkFlag(0x02)) mSharedDLObj->callDL(); } @@ -440,9 +428,6 @@ void J3DLockedMaterial::makeSharedDisplayList() {} void J3DLockedMaterial::load() { j3dSys.setMaterialMode(mMaterialMode); -#if TARGET_PC - mTevBlock->loadTexture(); -#endif if (j3dSys.checkFlag(2)) { return; } @@ -450,9 +435,6 @@ void J3DLockedMaterial::load() { void J3DLockedMaterial::loadSharedDL() { j3dSys.setMaterialMode(mMaterialMode); -#if TARGET_PC - mTevBlock->loadTexture(); -#endif if (!j3dSys.checkFlag(0x02)) mSharedDLObj->callDL(); } diff --git a/libs/JSystem/src/J3DGraphBase/J3DPacket.cpp b/libs/JSystem/src/J3DGraphBase/J3DPacket.cpp index fb82b8244d..354dee4130 100644 --- a/libs/JSystem/src/J3DGraphBase/J3DPacket.cpp +++ b/libs/JSystem/src/J3DGraphBase/J3DPacket.cpp @@ -212,9 +212,6 @@ bool J3DMatPacket::isSame(J3DMatPacket* pOther) const { void J3DMatPacket::draw() { ZoneScoped; -#if TARGET_PC - j3dSys.setTexture(mpTexture); -#endif mpMaterial->load(); #if DEBUG && TARGET_PC @@ -228,9 +225,6 @@ void J3DMatPacket::draw() { callDL(); J3DShapePacket* packet = getShapePacket(); -#if TARGET_PC - packet->mpModel->getVertexBuffer()->setArray(); -#endif packet->getShape()->loadPreDrawSetting(); while (packet != NULL) { diff --git a/libs/JSystem/src/J3DGraphBase/J3DTevs.cpp b/libs/JSystem/src/J3DGraphBase/J3DTevs.cpp index 1bfb22e73e..77e363737b 100644 --- a/libs/JSystem/src/J3DGraphBase/J3DTevs.cpp +++ b/libs/JSystem/src/J3DGraphBase/J3DTevs.cpp @@ -11,6 +11,10 @@ #include "JSystem/J3DGraphBase/J3DTransform.h" #include "global.h" +#if TARGET_PC +#include "aurora/lib/gfx/texture.hpp" +#endif + static void J3DGDLoadTexMtxImm(f32 (*)[4], u32, GXTexMtxType); static void J3DGDLoadPostTexMtxImm(f32 (*)[4], u32); @@ -280,6 +284,46 @@ u16 getTexNoReg(void* pDL) { return var_r31 & 0xFFFFFF; } +#if TARGET_PC +inline void J3DGDWrite_u64(u64 data) { + __GDWrite((u8)((data >> 56) & 0xFF)); + __GDWrite((u8)((data >> 48) & 0xFF)); + __GDWrite((u8)((data >> 40) & 0xFF)); + __GDWrite((u8)((data >> 32) & 0xFF)); + __GDWrite((u8)((data >> 24) & 0xFF)); + __GDWrite((u8)((data >> 16) & 0xFF)); + __GDWrite((u8)((data >> 8) & 0xFF)); + __GDWrite((u8)((data >> 0) & 0xFF)); +} + +void J3D_emit_loaded_texobj_metadata(const GXTexObj_& obj, GXTexMapID id) { + GDOverflowCheck(38); + J3DGDWrite_u8(GX_AURORA); + J3DGDWrite_u16(GX_AURORA_LOAD_TEXOBJ); + J3DGDWrite_u8(static_cast(id)); + J3DGDWrite_u64(reinterpret_cast(obj.data)); + J3DGDWrite_u32(obj.width()); + J3DGDWrite_u32(obj.height()); + J3DGDWrite_u32(obj.format()); + J3DGDWrite_u32(static_cast(obj.tlut)); + J3DGDWrite_u8(static_cast(obj.has_mips())); + J3DGDWrite_u32(obj.texObjId); + J3DGDWrite_u32(obj.texDataVersion); +} + +void J3D_emit_loaded_tlut_metadata(const GXTlutObj_& obj, u32 idx) { + GDOverflowCheck(22); + J3DGDWrite_u8(GX_AURORA); + J3DGDWrite_u16(GX_AURORA_LOAD_TLUT); + J3DGDWrite_u8(static_cast(idx)); + J3DGDWrite_u64(reinterpret_cast(obj.data)); + J3DGDWrite_u32(static_cast(obj.format)); + J3DGDWrite_u16(obj.numEntries); + J3DGDWrite_u32(obj.tlutObjId); + J3DGDWrite_u32(obj.tlutDataVersion); +} +#endif + void loadTexNo(u32 param_0, const u16& texNo) { ResTIMG* resTIMG = j3dSys.getTexture()->getResTIMG(texNo); J3D_ASSERT_NULLPTR(462, resTIMG != NULL); @@ -287,6 +331,14 @@ void loadTexNo(u32 param_0, const u16& texNo) { J3DSys::sTexCoordScaleTable[param_0].field_0x00 = (u16)resTIMG->width; J3DSys::sTexCoordScaleTable[param_0].field_0x02 = (u16)resTIMG->height; +#if TARGET_PC + J3D_emit_loaded_texobj_metadata( + *reinterpret_cast(j3dSys.getTexture()->getTexObj(texNo)), GXTexMapID(param_0)); + if (resTIMG->indexTexture) { + J3D_emit_loaded_tlut_metadata( + *reinterpret_cast(j3dSys.getTexture()->getTlutObj(texNo)), param_0); + } +#else GDOverflowCheck(0x14); J3DGDSetTexImgPtr(GXTexMapID(param_0), (u8*)resTIMG + resTIMG->imageOffset); J3DGDSetTexImgAttr(GXTexMapID(param_0), resTIMG->width, resTIMG->height, GXTexFmt(resTIMG->format & 0x0f)); @@ -298,6 +350,7 @@ void loadTexNo(u32 param_0, const u16& texNo) { J3DGDLoadTlut((u8*)resTIMG + resTIMG->paletteOffset, (param_0 << 13) + 0xf0000, tlutSize); J3DGDSetTexTlut(GXTexMapID(param_0), (param_0 << 13) + 0xf0000, GXTlutFmt(resTIMG->colorFormat)); } +#endif } void patchTexNo_PtrToIdx(u32 texID, const u16& idx) { diff --git a/libs/JSystem/src/J3DGraphBase/J3DTexture.cpp b/libs/JSystem/src/J3DGraphBase/J3DTexture.cpp index a01e605abb..971d5d08dd 100644 --- a/libs/JSystem/src/J3DGraphBase/J3DTexture.cpp +++ b/libs/JSystem/src/J3DGraphBase/J3DTexture.cpp @@ -49,7 +49,7 @@ void J3DTexture::loadGX(u16 idx, GXTexMapID texMapID) const { } #if TARGET_PC -void J3DTexture::loadGXTexObj(u16 idx) { +void J3DTexture::initGXTexObj(u16 idx) { J3D_ASSERT_RANGE(29, idx < mNum); ResTIMG* timg = getResTIMG(idx); @@ -89,7 +89,7 @@ void J3DTexture::entryNum(u16 num) { delete[] mpImgDataPtr; delete[] mpTlutDataPtr; mpTexObj = new TGXTexObj[num](); - mpTlutObj = new GXTlutObj[num](); + mpTlutObj = new TGXTlutObj[num](); mpImgDataPtr = new u8*[num](); mpTlutDataPtr = new u8*[num](); diff --git a/src/d/actor/d_a_midna.cpp b/src/d/actor/d_a_midna.cpp index 794dbe1d64..8517c6a7c0 100644 --- a/src/d/actor/d_a_midna.cpp +++ b/src/d/actor/d_a_midna.cpp @@ -513,7 +513,7 @@ int daMidna_c::createHeap() { if (name != NULL && strcmp(name, "midona_eye") == 0) { ResTIMG* timg = tex->getResTIMG(i); timg->mipmapEnabled = false; - tex->loadGXTexObj(i); + tex->initGXTexObj(i); break; } }