Files
dusklight/libs/JSystem/include/JSystem/J3DGraphBase/J3DTexture.h
T
qwertyquerty 767ba3bb14 Ongoing gameplay dev (#49)
* launch.json cwd

* bodge to load gci for testing

* stub card stat

* gameplay bodges

* viewport, ub fixes

* add release with debug info cmake variant

* be fixes, sound stub

* viewport h

* d_msg_flow BE

* be fopAcM_createItemFromEnemyID

* update launch configuration to use iso

* more audio stubs

* Attempt to set viewport and get messages for brightness check

* skip opening scene again, fixed JMessage::TResourceContainer::TCResource::Do_destroy

* add guards for viewport changes

* moar endian swapping to get Link sitting in PROC_OPENING_SCENE and for dialogues

* BE d_msg_class i_data

* stub bgm start

* fix div by 0 error (for now)

* TEMP_BROKEN in d_menu_ring

* REQUIRES_GX_LINES

* properly stub renderingAmap::draw with REQUIRES_GX_LINES

* better stubbing outside of stubs

* fix event data getting swapped multiple times

* evil draw vp fix

* Stub log imgui

This redirects all spammy logs to an imgui window that is cleared per frame.

This fixes the serious performance dip of the logging, and makes the regular log readable.

* Oops move those optimization changes I accidentally committed behind a flag

DUSK_SELECTED_OPT

* gx_line macro in map

* fix audio stubbing

* switch to CARD API aurora impl

* remove kabufuda from link libs

* refactor imgui stuff and add input viewer

* merge stub log with refactor

* accidentally committed a metaforce header shh

* basic map loader

* ImGuiConsole: Add missing <thread> include

* you may now play as luigi (you may now load stages with bridges)

* bloom fix

* bloom leak fix

* cloud shadow fix

* add soft reset button to imgui menu

* if it broke dont not fix it

* i swear i committed this

* BE swap indMtx in JPAResource::setPTev

* wnark ct fix

* frsqrte implementation from kinoko

* Fix Clang compile error in JAISeq::prepare_getSeqData_

* Add endian conversions to dMsgFlow_c::getInitNodeIndex

This fixes a freeze when Fado tries to stop you from leaving the
starting area.

* Add RAII GXTexObj wrapper; fix almost all leaks

* Update aurora for indirect texturing

* Update aurora for CARD fix

* Fix Clang build

* More d_msg_flow endian fixes

Fixes softlock when trying to talk to Fado and possibly other NPCs.

* no frame limiter

* get pause menu working

* proper frame limiting

* particle pointer size fix

* improve map loader a bit

---------

Co-authored-by: Jasper St. Pierre <jstpierre@mecheye.net>
Co-authored-by: TakaRikka <takarikka@outlook.com>
Co-authored-by: CraftyBoss <talibabdulmaalik@gmail.com>
Co-authored-by: Luke Street <luke@street.dev>
Co-authored-by: Lurs <2795933+Lurs@users.noreply.github.com>
Co-authored-by: PJB3005 <pieterjan.briers+git@gmail.com>
Co-authored-by: tgsm <doodrabbit@hotmail.com>
Co-authored-by: Max Roncace <me@caseif.net>
Co-authored-by: Phillip Stephens <antidote.crk@gmail.com>
2026-03-12 04:01:03 -07:00

163 lines
4.1 KiB
C++

#ifndef J3DTEXTURE_H
#define J3DTEXTURE_H
#include "JSystem/J3DGraphBase/J3DStruct.h"
#include "JSystem/J3DAssert.h"
#include "JSystem/JUtility/JUTTexture.h"
#include "global.h"
#include <stdint.h>
#include "dusk/gx_helper.h"
/**
* @ingroup jsystem-j3d
*
*/
class J3DTexture {
private:
/* 0x0 */ u16 mNum;
/* 0x2 */ u16 unk_0x2;
/* 0x4 */ ResTIMG* mpRes;
#if TARGET_PC
GXTlutObj* mpTlutObj;
TGXTexObj* mpTexObj;
u8** mpImgDataPtr;
u8** mpTlutDataPtr;
#endif
public:
J3DTexture(u16 num, ResTIMG* res) : mNum(num), unk_0x2(0), mpRes(res) {
J3D_ASSERT_NULLPTR(52, res != NULL || num == 0);
#if TARGET_PC
mpTexObj = new TGXTexObj[num];
mpTlutObj = new GXTlutObj[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);
}
#endif
}
void loadGX(u16, GXTexMapID) const;
#if TARGET_PC
void loadGXTexObj(u16);
#endif
void entryNum(u16);
void addResTIMG(u16, ResTIMG const*);
virtual ~J3DTexture(){
#if TARGET_PC
delete[] mpTexObj;
delete[] mpTlutObj;
delete[] mpImgDataPtr;
delete[] mpTlutDataPtr;
#endif
}
u16 getNum() const { return mNum; }
ResTIMG* getResTIMG(u16 index) const {
J3D_ASSERT_RANGE(72, index < mNum);
return &mpRes[index];
}
#if TARGET_PC
u8* getImgDataPtr(u16 index) const {
return mpImgDataPtr[index];
}
#endif
void setResTIMG(u16 index, const ResTIMG& timg) {
J3D_ASSERT_RANGE(81, index < mNum);
mpRes[index] = timg;
#if TARGET_PC
mpImgDataPtr[index] = ((u8*)&timg) + timg.imageOffset;
mpTlutDataPtr[index] = ((u8*)&timg) + timg.paletteOffset;
loadGXTexObj(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)));
#endif
}
};
extern J3DTexMtxInfo const j3dDefaultTexMtxInfo;
/**
* @ingroup jsystem-j3d
*
*/
class J3DTexMtx {
public:
J3DTexMtx() {
mTexMtxInfo = j3dDefaultTexMtxInfo;
}
J3DTexMtx(const J3DTexMtxInfo& info) {
mTexMtxInfo = info;
}
void load(u32) const;
void calc(const Mtx);
void calcTexMtx(const Mtx);
void calcPostTexMtx(const Mtx);
void loadTexMtx(u32) const;
void loadPostTexMtx(u32) const;
J3DTexMtxInfo& getTexMtxInfo() { return mTexMtxInfo; }
Mtx& getMtx() { return mMtx; }
void setEffectMtx(Mtx effectMtx) { mTexMtxInfo.setEffectMtx(effectMtx); }
private:
/* 0x00 */ J3DTexMtxInfo mTexMtxInfo;
/* 0x64 */ Mtx mMtx;
}; // Size: 0x94
extern J3DTexCoordInfo const j3dDefaultTexCoordInfo[8];
/**
* @ingroup jsystem-j3d
*
*/
struct J3DTexCoord : public J3DTexCoordInfo {
J3DTexCoord() {
J3DTexCoordInfo::operator=(j3dDefaultTexCoordInfo[0]);
mTexMtxReg = mTexGenMtx;
}
J3DTexCoord(const J3DTexCoordInfo& info) {
J3DTexCoordInfo::operator=(info);
mTexMtxReg = mTexGenMtx;
}
void setTexCoordInfo(const J3DTexCoordInfo& info) {
J3DTexCoordInfo::operator=(info);
}
u8 getTexGenType() const { return mTexGenType; }
u8 getTexGenSrc() const { return mTexGenSrc; }
u8 getTexGenMtx() const { return mTexGenMtx; }
u32 getTexMtxReg() const { return mTexMtxReg & 0xff; }
void setTexGenMtx(u8 param_1) { mTexGenMtx = param_1; }
void setTexMtxReg(u16 reg) { mTexMtxReg = reg; }
J3DTexCoord& operator=(const J3DTexCoord& other) {
#if DEBUG
J3DTexCoordInfo::operator=(other);
#else
// Fakematch: Instruction order is wrong with __memcpy or J3DTexCoordInfo::operator=
*(u32*)this = *(u32*)&other;
#endif
return *this;
}
void resetTexMtxReg() {
mTexMtxReg = mTexGenMtx;
}
/* 0x4 */ u16 mTexMtxReg;
}; // Size: 0x6
#endif /* J3DTEXTURE_H */