Files
dusklight/libs/JSystem/include/JSystem/J3DGraphBase/J3DTevs.h
T
Pieter-Jan Briers b289dece80 26 02 27 pjb dev 2 (#41)
* fix kankyo UB

* Fix TEV Stage DL writing

BE issue

* BE Fixes in materials/shapes

* Move to Aurora GD impl

* JUTDataFileHeader

* j3d: load vertex and texture not through GD

* Endian swap vertex data (mostly)

* Just exit(0) when closing the game

Fix crashes :godo:

* fix fopAcM_ct_placement and remove memcpy

* J3D: track vertex arrays correctly, swap work

* fix visibility, turn off overridden new/delete when we call into aurora

* event: cut name be

* Default window improvements

Double size, allow OS to decide position

* survive TParse::parseHeader_next

* color swap fix

* swap endian/fixes oob function pointer

* Remove GXGetViewportv stub

Aurora has it now

* Set array pointers via GD again

Relies on https://github.com/encounter/aurora/pull/35

* Let Aurora decide graphics backend

* disable procbar drawing

* Fix TColor endianness conversion issues

Fixes the wrong color for the flashing logo

* cam param swap

* simplify vtx loading, mat/amb color fix

* endian swap stb/fvb data

* aurora stat changes

* fix storage buffer crash

dont unnecessarily reassign vertex buffers in a way that forces aurora to recache things

* set bgobj spec fix

* add camera debug, endian swap more stb data, d_a_bg_obj::spec_data_c swapped

* JKRExpHeap: fix bad allocator slowdown

* solid tex

* texture caching

* log level

* fix window aspect ratio, disable bloom, endian swap camera type data

camera is now actually playing opening cutscene!!!!

* add GXDestroyTexObj to a couple stack init'd GXTexObjs, remove some diag printfs

* endian swap joint weight envelope data

* move to dusk config

* verbose arg errors

* better stub logging (for now)

* less logging, more BE

* more stubbing, move logging stuff around

* move all logging to aurora logging

* fix STUB_LOG, __FUNCTION__ isn't a string literal, wasn't building as it
was.

* update aurora

* fix heap alignment mismatch and always head align for now

* prevent them from fucking up my shit

* forward jut warning to DuskLog

* remove report logging

* maybe and i must emphasize maybe fix JMessage parsing

* this was a dumb idea

* preserve negative alignment for JKRHeap

* use normal free on macos and linux

* ^

* fix JMAHermiteInterpolation c impl

* endian swap J2DScreen mColor (oops)

* swap more J3D anim data, remove weird pointer addr check in J3DMaterial getMaterialAnm

* typo fix

* Fix aligned_alloc() size issues on POSIX

aligned_alloc() requires its input size to be a multiple of alignment. This wasn't being upheld so there were allocation failures in init code that made the game fail to start outside Windows.

Also just cleaned up some of this code a bit and removed fallback cases that *shouldn't* get hit.

* _Exit instead of exit()

Seriously I don't want destructors to run. Let the OS reclaim that shit.

* Reapply "Isolate JKRHeap operator overloads" (#39)

This reverts commit 3623b27f37.

* Fix some oopsies

* Fix hardcoded pointer size in JUTCacheFont::allocArray

* More operator overload fixes

Add void template specialization for jkrDelete

Add new[] placement overload. Apparently.

* Fix delete macros on nullptr

TIL C++ allows that.

* fix delete[]

* fix new(std::nothrow) overload

* fix avoid ub

* swap remaining anim data needed for title logo

* get rid of op 7

* move aurora_end_frame to correct spot

* juttexture destroy tex

* j2d animation be

* shutdown crash

* link warp material fix

* mDoExt_3DlineMat1_c fix

* hacky keyboard controls

* endian swap J2DResReference, add kb_pad to files.cmake

* fix some missing endian swaps in J2D, remove addr alignment check

* Remove heap unsetting in aurora calls

Never worked properly and not the right solution even if it did

* Don't print in DC stubs

They're fine to never implement

* Fix alignment stuff again

* Compile GF from dolphin lib

Doesn't seem to break anything and shuts up some stub warnings

* j3dtexture tlut obj fix

* addTexMtxIndexInDL fix

* don't recreate null tex data every frame

* the actual fix i wanted to push

* its kinda fakematch city over here

* insert hte efb copy

* limited window size / viewport support

* IsDelete FIX

---------

Co-authored-by: madeline <qwertytrogi@gmail.com>
Co-authored-by: Jasper St. Pierre <jstpierre@mecheye.net>
Co-authored-by: Jeffrey Crowell <jeff@crowell.biz>
Co-authored-by: TakaRikka <takarikka@outlook.com>
Co-authored-by: CraftyBoss <talibabdulmaalik@gmail.com>
Co-authored-by: Lurs <2795933+Lurs@users.noreply.github.com>
2026-03-08 15:27:15 -07:00

311 lines
10 KiB
C++

#ifndef J3DTEVS_H
#define J3DTEVS_H
#include <types.h>
#include <gx.h>
#include "JSystem/J3DGraphBase/J3DGD.h"
#include "JSystem/J3DGraphBase/J3DStruct.h"
extern u8 j3dTevSwapTableTable[1024];
extern const J3DLightInfo j3dDefaultLightInfo;
extern const J3DTexCoordInfo j3dDefaultTexCoordInfo[8];
extern const J3DTexMtxInfo j3dDefaultTexMtxInfo;
extern const J3DIndTexMtxInfo j3dDefaultIndTexMtxInfo;
extern const J3DTevStageInfo j3dDefaultTevStageInfo;
extern const J3DIndTevStageInfo j3dDefaultIndTevStageInfo;
extern const J3DFogInfo j3dDefaultFogInfo;
extern const J3DNBTScaleInfo j3dDefaultNBTScaleInfo;
extern const GXColor j3dDefaultColInfo;
extern const GXColor j3dDefaultAmbInfo;
extern const u8 j3dDefaultColorChanNum;
extern const J3DTevOrderInfo j3dDefaultTevOrderInfoNull;
extern const J3DIndTexOrderInfo j3dDefaultIndTexOrderNull;
extern const GXColorS10 j3dDefaultTevColor;
extern const J3DIndTexCoordScaleInfo j3dDefaultIndTexCoordScaleInfo;
extern const GXColor j3dDefaultTevKColor;
extern const J3DTevSwapModeInfo j3dDefaultTevSwapMode;
extern const J3DTevSwapModeTableInfo j3dDefaultTevSwapModeTable;
extern const J3DBlendInfo j3dDefaultBlendInfo;
extern const J3DColorChanInfo j3dDefaultColorChanInfo;
extern const u8 j3dDefaultTevSwapTableID;
extern const u16 j3dDefaultAlphaCmpID;
extern const u16 j3dDefaultZModeID;
/**
* @ingroup jsystem-j3d
*
*/
struct J3DTevStage {
J3DTevStage() {
setTevStageInfo(j3dDefaultTevStageInfo);
setTevSwapModeInfo(j3dDefaultTevSwapMode);
}
void setTevColorOp(u8 param_1, u8 param_2, u8 param_3, u8 param_4, u8 param_5) {
mTevColorOp = mTevColorOp & ~(0x01 << 2) | param_1 << 2;
if (param_1 <= 1) {
mTevColorOp = mTevColorOp & ~(0x03 << 4) | param_3 << 4;
mTevColorOp = mTevColorOp & ~0x03 | param_2;
} else {
mTevColorOp = mTevColorOp & ~(0x03 << 4) | (param_1 >> 1 & 3) << 4;
mTevColorOp = mTevColorOp & ~0x03 | 3;
}
mTevColorOp = mTevColorOp & ~(0x01 << 3) | param_4 << 3;
mTevColorOp = mTevColorOp & ~(0x03 << 6) | param_5 << 6;
}
void setTevColorAB(u8 a, u8 b) { mTevColorAB = a << 4 | b; }
void setTevColorCD(u8 c, u8 d) { mTevColorCD = c << 4 | d; }
void setAlphaA(u8 a) { mTevAlphaAB = mTevAlphaAB & ~(0x07 << 5) | a << 5; }
void setAlphaB(u8 b) { mTevAlphaAB = mTevAlphaAB & ~(0x07 << 2) | b << 2; }
void setAlphaC(u8 c) {
mTevAlphaAB = mTevAlphaAB & ~0x03 | c >> 1;
mTevSwapModeInfo = mTevSwapModeInfo & ~(0x01 << 7) | c << 7;
}
void setAlphaD(u8 d) { mTevSwapModeInfo = mTevSwapModeInfo & ~(0x07 << 4) | d << 4; }
void setAlphaABCD(u8 a, u8 b, u8 c, u8 d) {
setAlphaA(a);
setAlphaB(b);
setAlphaC(c);
setAlphaD(d);
}
void setTevAlphaOp(u8 param_1, u8 param_2, u8 param_3, u8 param_4, u8 param_5) {
mTevAlphaOp = mTevAlphaOp & ~(0x01 << 2) | param_1 << 2;
if (param_1 <= 1) {
mTevAlphaOp = mTevAlphaOp & ~0x03 | param_2;
mTevAlphaOp = mTevAlphaOp & ~(0x03 << 4) | param_3 << 4;
} else {
mTevAlphaOp = mTevAlphaOp & ~(0x03 << 4) | (param_1 >> 1 & 3) << 4;
mTevAlphaOp = mTevAlphaOp & ~0x03 | 3;
}
mTevAlphaOp = mTevAlphaOp & ~(0x01 << 3) | param_4 << 3;
mTevAlphaOp = mTevAlphaOp & ~(0x03 << 6) | param_5 << 6;
}
void setTevStageInfo(const J3DTevStageInfo& info) {
setTevColorOp(info.mTevAlphaOp, info.mTevAlphaAB, info.mTevSwapModeInfo, info.field_0x8, info.field_0x9);
setTevColorAB(info.mTevColorOp, info.mTevColorAB);
setTevColorCD(info.mTevColorCD, info.field_0x4);
setAlphaABCD(info.field_0xa, info.field_0xb, info.field_0xc, info.field_0xd);
setTevAlphaOp(info.field_0xe, info.field_0xf, info.field_0x10, info.field_0x11, info.field_0x12);
}
J3DTevStage(J3DTevStageInfo const& param_0) {
setTevStageInfo(param_0);
setTevSwapModeInfo(j3dDefaultTevSwapMode);
}
void setTevSwapModeInfo(J3DTevSwapModeInfo const& param_0) {
setTexSel(param_0.mTexSel);
setRasSel(param_0.mRasSel);
}
void setStageNo(u32 param_0) {
field_0x0 = 0xC0 + param_0 * 2;
field_0x4 = 0xC1 + param_0 * 2;
}
void setRasSel(u8 ras_sel) { mTevSwapModeInfo = (mTevSwapModeInfo & ~3) | ras_sel; }
void setTexSel(u8 tex_sel) { mTevSwapModeInfo = (mTevSwapModeInfo & ~0xc) | (tex_sel << 2); }
void load(u32 param_1) const {
J3DGDWriteBPCmd(*(BE(u32)*)&field_0x0);
J3DGDWriteBPCmd(*(BE(u32)*)&field_0x4);
}
J3DTevStage& operator=(const J3DTevStage& other) {
mTevColorOp = other.mTevColorOp;
mTevColorAB = other.mTevColorAB;
mTevColorCD = other.mTevColorCD;
mTevAlphaOp = other.mTevAlphaOp;
mTevAlphaAB = other.mTevAlphaAB;
mTevSwapModeInfo = other.mTevSwapModeInfo;
return *this;
}
J3DTevStage& operator=(J3DTevStage& other) {
mTevColorOp = other.mTevColorOp;
mTevColorAB = other.mTevColorAB;
mTevColorCD = other.mTevColorCD;
mTevAlphaOp = other.mTevAlphaOp;
mTevAlphaAB = other.mTevAlphaAB;
mTevSwapModeInfo = other.mTevSwapModeInfo;
return *this;
}
/* 0x0 */ u8 field_0x0;
/* 0x1 */ u8 mTevColorOp;
/* 0x2 */ u8 mTevColorAB;
/* 0x3 */ u8 mTevColorCD;
/* 0x4 */ u8 field_0x4;
/* 0x5 */ u8 mTevAlphaOp;
/* 0x6 */ u8 mTevAlphaAB;
/* 0x7 */ u8 mTevSwapModeInfo;
};
/**
* @ingroup jsystem-j3d
*
*/
struct J3DIndTevStage {
J3DIndTevStage() : mInfo(0) { setIndTevStageInfo(j3dDefaultIndTevStageInfo); }
J3DIndTevStage(J3DIndTevStageInfo const& info) : mInfo(0) { setIndTevStageInfo(info); }
void setIndTevStageInfo(J3DIndTevStageInfo const& info) {
setIndStage(info.mIndStage);
setIndFormat(info.mIndFormat);
setBiasSel(info.mBiasSel);
setMtxSel(info.mMtxSel);
setWrapS(info.mWrapS);
setWrapT(info.mWrapT);
setPrev(info.mPrev);
setLod(info.mLod);
setAlphaSel(info.mAlphaSel);
}
void setIndStage(u8 indStage) { mInfo = (mInfo & ~3) | indStage; }
void setIndFormat(u8 indFormat) { mInfo = (mInfo & ~0xc) | (indFormat << 2); }
void setBiasSel(u8 biasSel) { mInfo = (mInfo & ~0x70) | (biasSel << 4); }
void setMtxSel(u8 mtxSel) { mInfo = (mInfo & ~0x1e00) | (mtxSel << 9); }
void setWrapS(u8 wrapS) { mInfo = (mInfo & ~0xe000) | (wrapS << 13); }
void setWrapT(u8 wrapT) { mInfo = (mInfo & ~0x70000) | (wrapT << 16); }
void setPrev(u8 prev) { mInfo = (mInfo & ~0x100000) | (prev << 20); }
void setLod(u8 lod) { mInfo = (mInfo & ~0x80000) | (lod << 19); }
void setAlphaSel(u8 alphaSel) { mInfo = (mInfo & ~0x180) | (alphaSel << 7); }
void load(u32 param_1) const {
J3DGDWriteBPCmd(mInfo | (param_1 + 0x10) * 0x1000000);
}
J3DIndTevStage& operator=(const J3DIndTevStage& other) {
mInfo = other.mInfo;
return *this;
}
J3DIndTevStage& operator=(J3DIndTevStage& other) {
mInfo = other.mInfo;
return *this;
}
/* 0x0 */ u32 mInfo;
};
extern const J3DTevOrderInfo j3dDefaultTevOrderInfoNull;
/**
* @ingroup jsystem-j3d
*
*/
struct J3DTevOrder : public J3DTevOrderInfo {
J3DTevOrder() {
J3DTevOrderInfo::operator=(j3dDefaultTevOrderInfoNull);
}
J3DTevOrder(const J3DTevOrderInfo& info) {
J3DTevOrderInfo::operator=(info);
}
J3DTevOrderInfo& getTevOrderInfo() { return *this; }
u8 getTexMap() const { return mTexMap; }
};
extern u8 j3dTevSwapTableTable[1024];
extern u8 const j3dDefaultTevSwapTableID;
inline u8 calcTevSwapTableID(u8 param_0, u8 param_1, u8 param_2, u8 param_3) {
return 0x40 * (u8)param_0 + 0x10 * (u8)param_1 + 4 * (u8)param_2 + param_3;
}
/**
* @ingroup jsystem-j3d
*
*/
struct J3DTevSwapModeTable {
J3DTevSwapModeTable() { mIdx = j3dDefaultTevSwapTableID; }
J3DTevSwapModeTable(J3DTevSwapModeTableInfo const& info) {
mIdx = calcTevSwapTableID(info.field_0x0, info.field_0x1, info.field_0x2, info.field_0x3);
}
J3DTevSwapModeTable& operator=(const J3DTevSwapModeTable& rhs) {
mIdx = rhs.mIdx;
return *this;
}
J3DTevSwapModeTable& operator=(J3DTevSwapModeTable& other) {
mIdx = other.mIdx;
return *this;
}
u8 getR() const { return *(&j3dTevSwapTableTable[mIdx * 4] + 0); }
u8 getG() const { return *(&j3dTevSwapTableTable[mIdx * 4] + 1); }
u8 getB() const { return *(&j3dTevSwapTableTable[mIdx * 4] + 2); }
u8 getA() const { return *(&j3dTevSwapTableTable[mIdx * 4] + 3); }
/* 0x0 */ u8 mIdx;
}; // Size: 0x1
/**
* @ingroup jsystem-j3d
*
*/
class J3DLightObj {
public:
J3DLightObj() { mInfo = j3dDefaultLightInfo; }
void load(u32) const;
J3DLightInfo* getLightInfo() { return &mInfo; }
J3DLightObj& operator=(J3DLightObj const& other) {
mInfo = other.mInfo;
return *this;
}
/* 0x00 */ J3DLightInfo mInfo;
/* 0x34 */ GXLightObj mLightObj;
}; // Size = 0x74
extern const J3DNBTScaleInfo j3dDefaultNBTScaleInfo;
/**
* @ingroup jsystem-j3d
*
*/
struct J3DNBTScale : public J3DNBTScaleInfo {
J3DNBTScale() {
mbHasScale = j3dDefaultNBTScaleInfo.mbHasScale;
mScale.x = j3dDefaultNBTScaleInfo.mScale.x;
mScale.y = j3dDefaultNBTScaleInfo.mScale.y;
mScale.z = j3dDefaultNBTScaleInfo.mScale.z;
}
J3DNBTScale(J3DNBTScaleInfo const& info) {
mbHasScale = info.mbHasScale;
mScale.x = info.mScale.x;
mScale.y = info.mScale.y;
mScale.z = info.mScale.z;
}
BE(Vec)* getScale() { return &mScale; }
};
extern const GXColor j3dDefaultColInfo;
extern const GXColor j3dDefaultAmbInfo;
extern const GXColorS10 j3dDefaultTevColor;
extern const GXColor j3dDefaultTevKColor;
extern u8 j3dAlphaCmpTable[768];
extern const u8 j3dDefaultNumChans;
struct J3DNBTScale;
struct J3DTexCoord;
void loadNBTScale(J3DNBTScale& param_0);
void loadTexCoordGens(u32 param_0, J3DTexCoord* param_1);
void loadTexNo(u32 param_0, u16 const& param_1);
void patchTexNo_PtrToIdx(u32 texID, u16 const& idx);
bool isTexNoReg(void* param_0);
u16 getTexNoReg(void* param_0);
void makeTexCoordTable();
void makeAlphaCmpTable();
void makeZModeTable();
void makeTevSwapTable();
#endif /* J3DTEVS_H */