summaryrefslogtreecommitdiff
path: root/include/JSystem/J3DGraphBase
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2023-09-30 14:09:53 -0700
committerJasper St. Pierre <jstpierre@mecheye.net>2023-09-30 14:09:53 -0700
commita85fb7c63ba10f6374eac3df3e42ff687cbb86ef (patch)
tree396f2d3fdd609a60b17ea420aec69ae38c1fcd51 /include/JSystem/J3DGraphBase
parent836bf25fc747cb71d2d519814d6a89379326b4bd (diff)
J3DTevs, J3DMatBlock progress
Diffstat (limited to 'include/JSystem/J3DGraphBase')
-rw-r--r--include/JSystem/J3DGraphBase/J3DGD.h40
-rw-r--r--include/JSystem/J3DGraphBase/J3DMatBlock.h140
-rw-r--r--include/JSystem/J3DGraphBase/J3DStruct.h31
-rw-r--r--include/JSystem/J3DGraphBase/J3DTexture.h4
4 files changed, 112 insertions, 103 deletions
diff --git a/include/JSystem/J3DGraphBase/J3DGD.h b/include/JSystem/J3DGraphBase/J3DGD.h
index 50524595..b4a0bb60 100644
--- a/include/JSystem/J3DGraphBase/J3DGD.h
+++ b/include/JSystem/J3DGraphBase/J3DGD.h
@@ -82,26 +82,42 @@ inline void J3DGDSetNumTexGens(u8 numTexGens) {
J3DGDWriteXFCmd(0x103f, numTexGens);
}
-inline void J3DGDSetAlphaCompare(GXCompare param_0, u8 param_1, GXAlphaOp param_2, GXCompare param_3, u8 param_4) {
- J3DGDWriteBPCmd(param_2 << 22 | param_3 << 19 | param_0 << 16 | param_4 << 8 | param_1 | 0xF3000000);
+inline void J3DGDSetAlphaCompare(GXCompare cmp0, u8 ref0, GXAlphaOp op, GXCompare cmp1, u8 ref1) {
+ J3DGDWriteBPCmd(ref0 | ref1 << 8 | cmp0 << 16 | cmp1 << 19 | op << 22 | 0xF3 << 24);
}
-inline void J3DGDSetBlendMode(GXBlendMode param_0, GXBlendFactor param_1, GXBlendFactor param_2, GXLogicOp param_3) {
+inline void J3DGDSetBlendMode(GXBlendMode mode, GXBlendFactor srcFactor, GXBlendFactor dstFactor, GXLogicOp logicOp) {
J3DGDWriteBPCmd(0xFE001FE3);
- bool r30 = true;
- if (param_0 != GX_BM_BLEND && param_0 != GX_BM_SUBTRACT) {
- r30 = false;
- }
- J3DGDWriteBPCmd(param_3 << 12 | (param_0 == GX_BM_LOGIC) << 11 | param_1 << 8 | param_2 << 5 | (param_0 == GX_BM_BLEND) << 1 | r30 | 0x41000000);
+ J3DGDWriteBPCmd(
+ (mode == GX_BM_BLEND || mode == GX_BM_SUBTRACT) << 0 |
+ (mode == GX_BM_LOGIC) << 1 |
+ dstFactor << 5 |
+ srcFactor << 8 |
+ (mode == GX_BM_SUBTRACT) << 11 |
+ logicOp << 12 |
+ 0x41 << 24);
}
-inline void J3DGDSetZMode(u8 param_0, GXCompare param_1, u8 param_2) {
- J3DGDWriteBPCmd(param_2 << 4 | param_0 | param_1 << 1 | 0x40000000);
+inline void J3DGDSetBlendMode(GXBlendMode mode, GXBlendFactor srcFactor, GXBlendFactor dstFactor, GXLogicOp logicOp, u8 ditherEnable) {
+ J3DGDWriteBPCmd(0xFE001FE7);
+ J3DGDWriteBPCmd(
+ (mode == GX_BM_BLEND || mode == GX_BM_SUBTRACT) << 0 |
+ (mode == GX_BM_LOGIC) << 1 |
+ ditherEnable << 2 |
+ dstFactor << 5 |
+ srcFactor << 8 |
+ (mode == GX_BM_SUBTRACT) << 11 |
+ logicOp << 12 |
+ 0x41 << 24);
}
-inline void J3DGDSetZCompLoc(u32 param_0) {
+inline void J3DGDSetZMode(u8 compareEnable, GXCompare func, u8 writeEnable) {
+ J3DGDWriteBPCmd(compareEnable | func << 1 | writeEnable << 4 | 0x40 << 24);
+}
+
+inline void J3DGDSetZCompLoc(u32 compLocEnable) {
J3DGDWriteBPCmd(0xFE000040);
- J3DGDWriteBPCmd(param_0 << 6 | 0x43000000);
+ J3DGDWriteBPCmd(compLocEnable << 6 | 0x43 << 24);
}
inline void J3DGDSetTevKonstantSel_SwapModeTable(GXTevStageID stage, GXTevKColorSel colorSel1, GXTevKAlphaSel alphaSel1, GXTevKColorSel colorSel2, GXTevKAlphaSel alphaSel2, GXTevColorChan chan1, GXTevColorChan chan2) {
diff --git a/include/JSystem/J3DGraphBase/J3DMatBlock.h b/include/JSystem/J3DGraphBase/J3DMatBlock.h
index 47cbc21e..fb0b960f 100644
--- a/include/JSystem/J3DGraphBase/J3DMatBlock.h
+++ b/include/JSystem/J3DGraphBase/J3DMatBlock.h
@@ -5,6 +5,7 @@
#include "JSystem/J3DGraphBase/J3DStruct.h"
#include "JSystem/J3DGraphBase/J3DTevs.h"
#include "JSystem/J3DGraphBase/J3DTexture.h"
+#include "dolphin/gx/GXEnum.h"
struct J3DGXColorS10 : public GXColorS10 {
J3DGXColorS10() {}
@@ -71,9 +72,9 @@ public:
protected:
/* 0x04 */ u32 mTexGenNum;
/* 0x08 */ J3DTexCoord mTexCoord[8];
- /* 0x38 */ J3DTexMtx* mTexMtx[8];
- /* 0x58 */ u32 mTexMtxOffset;
-}; // Size: 0x5C
+ /* 0x28 */ J3DTexMtx* mTexMtx[8];
+ /* 0x48 */ u32 mTexMtxOffset;
+}; // Size: 0x4C
class J3DTexGenBlockBasic : public J3DTexGenBlockPatched {
public:
@@ -91,8 +92,8 @@ public:
virtual ~J3DTexGenBlockBasic() {}
private:
- /* 0x5C */ J3DNBTScale mNBTScale;
-}; // Size: 0x6C
+ /* 0x4C */ J3DNBTScale mNBTScale;
+}; // Size: 0x5C
class J3DTexGenBlock4 : public J3DTexGenBlockPatched {
public:
@@ -110,8 +111,8 @@ public:
virtual ~J3DTexGenBlock4() {}
private:
- /* 0x5C */ J3DNBTScale mNBTScale;
-}; // Size: 0x6C
+ /* 0x4C */ J3DNBTScale mNBTScale;
+}; // Size: 0x5C
class J3DTevBlock {
public:
@@ -529,28 +530,22 @@ inline u16 calcZModeID(u8 param_0, u8 param_1, u8 param_2) {
return ((param_1 * 2) & 0x1FE) + (param_0 * 0x10) + param_2;
}
-struct J3DZModeInfo {
- /* 0x0 */ u8 field_0x0;
- /* 0x1 */ u8 field_0x1;
- /* 0x2 */ u8 field_0x2;
-};
+extern u8 j3dZModeTable[96];
struct J3DZMode {
J3DZMode() { mZModeID = j3dDefaultZModeID; }
- //u8 getCompareEnaable() const { return j3dZModeTable[mZModeID * 3]; }
- //u8 getFunc() const { return j3dZModeTable[mZModeID * 3 + 1]; }
- //u8 getUpdateEnable() const { return j3dZModeTable[mZModeID * 3 + 2]; }
+ u8 getCompareEnaable() const { return j3dZModeTable[mZModeID * 3]; }
+ u8 getFunc() const { return j3dZModeTable[mZModeID * 3 + 1]; }
+ u8 getUpdateEnable() const { return j3dZModeTable[mZModeID * 3 + 2]; }
void setZModeInfo(const J3DZModeInfo& info) {
- mZModeID = calcZModeID(info.field_0x0, info.field_0x1, info.field_0x2);
+ mZModeID = calcZModeID(info.mCompareEnable, info.mFunc, info.mUpdateEnable);
}
- /*
void load() {
J3DGDSetZMode(getCompareEnaable(), GXCompare(getFunc()), getUpdateEnable());
}
- */
/* 0x0 */ u16 mZModeID;
};
@@ -558,13 +553,13 @@ struct J3DZMode {
struct J3DBlend : public J3DBlendInfo {
J3DBlend() { *(J3DBlendInfo*)this = j3dDefaultBlendInfo; }
- void load() {
- J3DGDSetBlendMode(
- GXBlendMode(mType),
- GXBlendFactor(mSrcFactor),
- GXBlendFactor(mDstFactor),
- GXLogicOp(mOp)
- );
+ GXBlendMode getBlendMode() const { return (GXBlendMode)mBlendMode; }
+ GXBlendFactor getSrcFactor() const { return (GXBlendFactor)mSrcFactor; }
+ GXBlendFactor getDstFactor() const { return (GXBlendFactor)mDstFactor; }
+ GXLogicOp getLogicOp() const { return (GXLogicOp)mLogicOp; }
+
+ void load(u8 ditherEnable) {
+ J3DGDSetBlendMode(getBlendMode(), getSrcFactor(), getDstFactor(), getLogicOp(), ditherEnable);
}
};
@@ -595,41 +590,30 @@ inline u32 calcAlphaCmpID(u32 param_1, u32 param_2, u32 param_3) {
return ((param_1 & 0xff) << 5) + ((param_2 & 0xff) << 3) + (param_3 & 0xff);
}
+extern u8 j3dAlphaCmpTable[768];
+
struct J3DAlphaComp {
J3DAlphaComp() {
- field_0x0 = j3dDefaultAlphaCmpID;
+ mAlphaCmpID = j3dDefaultAlphaCmpID;
mRef0 = 0;
mRef1 = 0;
}
- //u8 getComp0() { return j3dAlphaCmpTable[field_0x0 * 3]; }
- //u8 getOp() { return j3dAlphaCmpTable[field_0x0 * 3 + 1]; }
- //u8 getComp1() { return j3dAlphaCmpTable[field_0x0 * 3 + 2]; }
-
- void setAlphaCompInfo(const J3DAlphaCompInfo& param_1) {
- mRef0 = param_1.field_0x1;
- mRef1 = param_1.field_0x4;
- u32 p1_mref1 = param_1.mRef1;
- field_0x0 = calcAlphaCmpID(param_1.field_0x0, param_1.mRef0, p1_mref1);
+ GXCompare getComp0() const { return GXCompare(j3dAlphaCmpTable[mAlphaCmpID * 3]); }
+ GXAlphaOp getOp() const { return GXAlphaOp(j3dAlphaCmpTable[mAlphaCmpID * 3 + 1]); }
+ GXCompare getComp1() const { return GXCompare(j3dAlphaCmpTable[mAlphaCmpID * 3 + 2]); }
+ u8 getRef0() const { return mRef0; }
+ u8 getRef1() const { return mRef1; }
- // this matches for `dKy_bg_MAxx_proc` but causes `addWarpMaterial` to fail,
- // while the above matches for `addWarpMaterial` but causes `dKy_bg_MAxx_proc` to fail?
- // field_0x0 = calcAlphaCmpID(param_1.field_0x0, param_1.mRef0, param_1.mRef1);
+ void setAlphaCompInfo(const J3DAlphaCompInfo& info) {
+ // mAlphaCmpID = calcAlphaCmpID(param_1, param_1.mRef0, param_1.mRef1);
}
- /*
void load() {
- J3DGDSetAlphaCompare(
- GXCompare(getComp0()),
- mRef0,
- GXAlphaOp(getOp()),
- GXCompare(getComp1()),
- mRef1
- );
+ J3DGDSetAlphaCompare(getComp0(), getRef0(), getOp(), getComp1(), getRef1());
}
- */
- /* 0x00 */ u16 field_0x0;
+ /* 0x00 */ u16 mAlphaCmpID;
/* 0x02 */ u8 mRef0;
/* 0x03 */ u8 mRef1;
}; // Size: 0x4
@@ -868,54 +852,40 @@ public:
virtual ~J3DIndBlockNull();
};
-/*
-inline u32 setChanCtrlMacro(u8 param_0, GXColorSrc param_1, GXColorSrc param_2, u32 param_3, GXDiffuseFn param_4, GXAttnFn param_5) {
- GXDiffuseFn r31;
- if (param_5 == GX_AF_SPEC) {
- r31 = GX_DF_NONE;
- } else {
- r31 = param_4;
- }
+inline u32 setChanCtrlMacro(u8 enable, GXColorSrc ambSrc, GXColorSrc matSrc, u32 lightMask, GXDiffuseFn diffuseFn, GXAttnFn attnFn) {
return
- param_2 |
- param_0 << 1 |
- (param_3 & 0xf) << 2 |
- param_1 << 6 |
- r31 << 7 |
- (param_5 != 2) << 9 |
- (param_5 != 0) << 10 |
- (param_3 >> 4 & 0x0f) << 11;
+ matSrc |
+ enable << 1 |
+ (lightMask & 0x0f) << 2 |
+ ambSrc << 6 |
+ ((attnFn == GX_AF_SPEC) ? GX_DF_NONE : diffuseFn) << 7 |
+ (attnFn != GX_AF_NONE) << 9 |
+ (attnFn != GX_AF_SPEC) << 10 |
+ (lightMask >> 4 & 0x0f) << 11;
}
-*/
struct J3DColorChan {
J3DColorChan();
- /*
- u8 getAttnFn() {
- u8 local_8[4] = {0x20, 0x00, 0x02, 0x01};
- return local_8[(mColorChanID & 0x600) >> 9];
+ GXAttnFn getAttnFn() {
+ // Need a way to put this in sdata2 without affecting every single TU ever...
+
+ // static const u8 attnFnTbl[] = { GX_AF_NONE, GX_AF_SPEC, GX_AF_NONE, GX_AF_SPOT, };
+ // return GXAttnFn(attnFnTbl[mColorChanID >> 9 & 0x03]);
+ return GXAttnFn(mColorChanID >> 9 & 0x03);
}
- */
- u8 getDiffuseFn() { return (mColorChanID & 0x180) >> 7; }
- u8 getLightMask() { return (((mColorChanID & 0x7800) >> 7) | (mColorChanID & 0x3c) >> 2); }
+ GXDiffuseFn getDiffuseFn() { return GXDiffuseFn(mColorChanID >> 7 & 3); }
+ u8 getLightMask() { return ((mColorChanID >> 2 & 0x0f) | (mColorChanID >> 11 & 0x0f) << 4); }
void setLightMask(u8 param_1) {
- mColorChanID = (mColorChanID & ~0x3c) | ((param_1 & 0xf) << 2);
+ mColorChanID = (mColorChanID & ~0x3c) | ((param_1 & 0x0f) << 2);
mColorChanID = (mColorChanID & ~0x7800) | ((param_1 & 0xf0) << 7);
}
- u8 getMatSrc() { return mColorChanID & 0x01; }
- u8 getAmbSrc() { return (mColorChanID & 0x40) >> 6; }
- u8 getEnable() { return (mColorChanID & 0x02) >> 1; }
- /*
+ // bug? both enable and getMatSrc seem to use bit 0? enable should use bit 1
+ GXColorSrc getMatSrc() { return GXColorSrc(mColorChanID >> 0 & 0x01); }
+ GXColorSrc getAmbSrc() { return GXColorSrc(mColorChanID >> 6 & 0x01); }
+ u8 getEnable() { return mColorChanID >> 0 & 0x01; }
void load() {
- u8 r26 = getAttnFn();
- u8 r27 = getDiffuseFn();
- u8 r28 = getLightMask();
- u8 r29 = getMatSrc();
- u8 r30 = getAmbSrc();
- u8 r31 = getEnable();
- J3DGDWrite_u32(setChanCtrlMacro(r31, GXColorSrc(r30), GXColorSrc(r29), r28, GXDiffuseFn(r27), GXAttnFn(r26)));
+ J3DGDWrite_u32(setChanCtrlMacro(getEnable(), getAmbSrc(), getMatSrc(), getLightMask(), getDiffuseFn(), getAttnFn()));
}
- */
/* 0x0 */ u16 mColorChanID;
};
diff --git a/include/JSystem/J3DGraphBase/J3DStruct.h b/include/JSystem/J3DGraphBase/J3DStruct.h
index d1a0c403..d579ba6d 100644
--- a/include/JSystem/J3DGraphBase/J3DStruct.h
+++ b/include/JSystem/J3DGraphBase/J3DStruct.h
@@ -8,7 +8,7 @@
class J3DLightInfo {
public:
- /* 803256C4 */ void operator=(J3DLightInfo const&);
+ void operator=(J3DLightInfo const&);
/* 0x00 */ Vec mLightPosition;
/* 0x0C */ Vec mLightDirection;
@@ -25,9 +25,24 @@ struct J3DTextureSRTInfo {
/* 0x10 */ f32 mTranslationY;
}; // Size: 0x14
+enum J3DTexMtxMode {
+ J3DTexMtxMode_None,
+ J3DTexMtxMode_EnvmapBasic,
+ J3DTexMtxMode_ProjmapBasic,
+ J3DTexMtxMode_ViewProjmapBasic,
+ J3DTexMtxMode_Unknown4,
+ J3DTexMtxMode_Unknown5,
+ J3DTexMtxMode_EnvmapOld,
+ J3DTexMtxMode_Envmap,
+ J3DTexMtxMode_Projmap,
+ J3DTexMtxMode_ViewProjmap,
+ J3DTexMtxMode_EnvmapOldEffectMtx,
+ J3DTexMtxMode_EnvmapEffectMtx,
+};
+
struct J3DTexMtxInfo {
- /* 80325718 */ void operator=(J3DTexMtxInfo const&);
- /* 80325794 */ void setEffectMtx(Mtx);
+ void operator=(J3DTexMtxInfo const&);
+ void setEffectMtx(Mtx);
/* 0x00 */ u8 mProjection;
/* 0x01 */ u8 mInfo;
@@ -129,10 +144,10 @@ struct J3DIndTexCoordScaleInfo {
};
struct J3DBlendInfo {
- /* 0x0 */ u8 mType;
+ /* 0x0 */ u8 mBlendMode;
/* 0x1 */ u8 mSrcFactor;
/* 0x2 */ u8 mDstFactor;
- /* 0x3 */ u8 mOp;
+ /* 0x3 */ u8 mLogicOp;
};
struct J3DTevOrderInfo {
@@ -152,6 +167,12 @@ struct J3DColorChanInfo {
/* 0x7 */ u8 field_0x7;
};
+struct J3DZModeInfo {
+ /* 0x0 */ u8 mCompareEnable;
+ /* 0x1 */ u8 mFunc;
+ /* 0x2 */ u8 mUpdateEnable;
+};
+
STATIC_ASSERT(sizeof(J3DTevStageInfo) == 0x14);
#endif /* J3DSTRUCT_H */
diff --git a/include/JSystem/J3DGraphBase/J3DTexture.h b/include/JSystem/J3DGraphBase/J3DTexture.h
index dba348b2..92bc64ed 100644
--- a/include/JSystem/J3DGraphBase/J3DTexture.h
+++ b/include/JSystem/J3DGraphBase/J3DTexture.h
@@ -67,11 +67,13 @@ public:
J3DTexMtxInfo& getTexMtxInfo() { return mTexMtxInfo; }
Mtx& getMtx() { return mMtx; }
void setEffectMtx(Mtx effectMtx) { mTexMtxInfo.setEffectMtx(effectMtx); }
+ Mtx& getViewMtx() { return mViewMtx; }
+ void setViewMtx(const Mtx viewMtx) { MTXCopy(viewMtx, mViewMtx); }
private:
/* 0x00 */ J3DTexMtxInfo mTexMtxInfo;
/* 0x64 */ Mtx mMtx;
- /* 0x94 */ Mtx field_0x94;
+ /* 0x94 */ Mtx mViewMtx;
}; // Size: 0xc4
struct J3DTexCoord : public J3DTexCoordInfo {