This commit is contained in:
Luke Street 2022-08-31 12:06:56 -04:00
parent 89284f17b2
commit 3e43c0878f
5 changed files with 32 additions and 34 deletions

View File

@ -704,7 +704,7 @@ SetFog__3CGXF10_GXFogTypeffffRC8_GXColor:
/* 80308530 00305490 D0 85 02 58 */ stfs f4, 0x258(r5)
/* 80308534 00305494 90 85 02 5C */ stw r4, 0x25c(r5)
/* 80308538 00305498 40 82 00 10 */ bne lbl_80308548
/* 8030853C 0030549C 80 02 8C A8 */ lwz r0, lbl_805AA9C8@sda21(r2)
/* 8030853C 0030549C 80 02 8C A8 */ lwz r0, black$localstatic3$apply_fog__3CGXFv@sda21(r2)
/* 80308540 003054A0 90 01 00 0C */ stw r0, 0xc(r1)
/* 80308544 003054A4 48 00 00 08 */ b lbl_8030854C
lbl_80308548:

View File

@ -123,8 +123,8 @@ lbl_805A720C:
.section .sdata2, "a"
.balign 8
.global lbl_805AA9C8
lbl_805AA9C8:
.global black$localstatic3$apply_fog__3CGXFv
black$localstatic3$apply_fog__3CGXFv:
# ROM: 0x3F7268
.4byte 0

View File

@ -3,12 +3,9 @@
#include "types.h"
#include "dolphin/gx.h"
#include <stddef.h>
#ifdef __MWERKS__
#pragma cpp_extensions on
#endif
#include "dolphin/gx.h"
class CGX {
public:
@ -54,12 +51,12 @@ public:
GXColor x40_chanMatColors[2];
u32 x48_descList;
union {
u8 x4c_flags;
u8 x4c_chanFlags;
struct {
u8 x4c_unk : 5;
u8 x4c_dirtyChanCtrl : 2;
u8 x4c_numChansDirty : 1;
};
u8 unused : 5;
u8 chansDirty : 2;
u8 numDirty : 1;
} x4c_flags;
};
u8 x4d_prevNumChans;
u8 x4e_numChans;
@ -142,6 +139,12 @@ public:
private:
static void FlushState();
static void update_fog(u32 flags);
static void apply_fog() {
static const GXColor black = {0, 0, 0, 0};
GXSetFog(static_cast< GXFogType >(sGXState.x53_fogType), sGXState.x24c_fogParams.x0_fogStartZ, sGXState.x24c_fogParams.x4_fogEndZ,
sGXState.x24c_fogParams.x8_fogNearZ, sGXState.x24c_fogParams.xc_fogFarZ,
(sGXState.x56_blendMode & 0xE0) == 0x20 ? black : sGXState.x24c_fogParams.x10_fogColor);
}
static SGXState sGXState;
};

View File

@ -514,7 +514,7 @@ KYOTO_1 :=\
$(BUILD_DIR)/asm/Kyoto/Text/CFont.o\
$(BUILD_DIR)/asm/Kyoto/Graphics/CLight.o\
$(BUILD_DIR)/asm/Kyoto/Graphics/CCubeModel.o\
$(BUILD_DIR)/asm/Kyoto/Graphics/CGX.o\
$(BUILD_DIR)/src/Kyoto/Graphics/CGX.o\
$(BUILD_DIR)/asm/Kyoto/Graphics/CTevCombiners.o\
$(BUILD_DIR)/asm/Kyoto/Graphics/DolphinCGraphics.o\
$(BUILD_DIR)/asm/Kyoto/Graphics/DolphinCPalette.o\

View File

@ -6,11 +6,11 @@
CGX::SGXState CGX::sGXState;
static GXVtxDescList sVtxDescList[GX_MAX_VTXDESCLIST_SZ];
static GXVtxDescList sVtxDescList[30];
void CGX::SetNumChans(u8 num) {
sGXState.x4e_numChans = num;
sGXState.x4c_numChansDirty = sGXState.x4e_numChans != sGXState.x4d_prevNumChans;
sGXState.x4c_flags.numDirty = sGXState.x4e_numChans != sGXState.x4d_prevNumChans;
}
void CGX::SetNumTexGens(u8 num) {
@ -36,18 +36,17 @@ void CGX::SetChanMatColor(EChannelId channel, const GXColor& color) {
}
}
// TODO https://decomp.me/scratch/09nam
void CGX::SetChanCtrl(EChannelId channel, GXBool enable, GXColorSrc ambSrc, GXColorSrc matSrc, GXLightID lights, GXDiffuseFn diffFn,
GXAttnFn attnFn) {
u16& state = sGXState.x34_chanCtrls[channel];
u16 prevFlags = sGXState.x30_prevChanCtrls[channel];
u32 flags = enable;
if (lights == GX_LIGHT_NULL) {
flags = 0;
enable = GX_FALSE;
}
flags = MaskAndShiftLeft(flags, 1, 0) | MaskAndShiftLeft(ambSrc, 1, 1) | MaskAndShiftLeft(matSrc, 1, 2) |
MaskAndShiftLeft(lights, 0xFF, 3) | MaskAndShiftLeft(diffFn, 3, 11) | MaskAndShiftLeft(attnFn, 3, 13);
sGXState.x34_chanCtrls[channel] = flags;
sGXState.x4c_flags = ((flags != prevFlags) << (channel + 1)) | (sGXState.x4c_flags & ~(1 << (channel + 1)));
u32 flags = MaskAndShiftLeft(enable, 1, 0) | MaskAndShiftLeft(ambSrc, 1, 1) | MaskAndShiftLeft(matSrc, 1, 2) |
MaskAndShiftLeft(lights, 0xFF, 3) | MaskAndShiftLeft(diffFn, 3, 11) | MaskAndShiftLeft(attnFn, 3, 13);
state = flags;
sGXState.x4c_chanFlags = ((flags != prevFlags) << (channel + 1)) | (sGXState.x4c_chanFlags & ~(1 << (channel + 1)));
}
void CGX::SetNumTevStages(u8 num) {
@ -57,7 +56,6 @@ void CGX::SetNumTevStages(u8 num) {
}
}
// TODO https://decomp.me/scratch/V2iVD
void CGX::SetTevKColor(GXTevKColorID id, const GXColor& color) {
if (!CompareGXColors(sGXState.x58_kColors[id], color)) {
CopyGXColor(sGXState.x58_kColors[id], color);
@ -148,9 +146,8 @@ void CGX::SetTevOrder(GXTevStageID stageId, GXTexCoordID texCoord, GXTexMapID te
}
}
// TODO https://decomp.me/scratch/YWJTk
void CGX::SetBlendMode(GXBlendMode mode, GXBlendFactor srcFac, GXBlendFactor dstFac, GXLogicOp op) {
u16 flags = MaskAndShiftLeft(mode, 3, 0) | MaskAndShiftLeft(srcFac, 7, 2) | MaskAndShiftLeft(dstFac, 7, 5) | MaskAndShiftLeft(op, 0xF, 8);
u32 flags = MaskAndShiftLeft(mode, 3, 0) | MaskAndShiftLeft(srcFac, 7, 2) | MaskAndShiftLeft(dstFac, 7, 5) | MaskAndShiftLeft(op, 0xF, 8);
if (flags != sGXState.x56_blendMode) {
update_fog(flags);
sGXState.x56_blendMode = flags;
@ -230,14 +227,14 @@ void CGX::SetArray(GXAttr attr, const void* data, u8 stride) {
}
void CGX::CallDisplayList(const void* ptr, size_t size) {
if (sGXState.x4c_flags != 0) {
if (sGXState.x4c_chanFlags != 0) {
FlushState();
}
GXCallDisplayList(ptr, size);
}
void CGX::Begin(GXPrimitive prim, GXVtxFmt fmt, u16 numVtx) {
if (sGXState.x4c_flags != 0) {
if (sGXState.x4c_chanFlags != 0) {
FlushState();
}
GXBegin(prim, fmt, numVtx);
@ -252,9 +249,7 @@ void CGX::SetFog(GXFogType type, f32 startZ, f32 endZ, f32 nearZ, f32 farZ, cons
sGXState.x24c_fogParams.x8_fogNearZ = nearZ;
sGXState.x24c_fogParams.xc_fogFarZ = farZ;
CopyGXColor(sGXState.x24c_fogParams.x10_fogColor, color);
GXSetFog(static_cast< GXFogType >(sGXState.x53_fogType), sGXState.x24c_fogParams.x0_fogStartZ, sGXState.x24c_fogParams.x4_fogEndZ,
sGXState.x24c_fogParams.x8_fogNearZ, sGXState.x24c_fogParams.xc_fogFarZ,
(sGXState.x56_blendMode & 0xE0) == 0x20 ? GXColor() : sGXState.x24c_fogParams.x10_fogColor);
apply_fog();
}
void CGX::SetLineWidth(u8 width, GXTexOffset offset) {
@ -340,11 +335,11 @@ void CGX::ResetGXStatesFull() {
}
void CGX::FlushState() {
if (sGXState.x4c_numChansDirty) {
if (sGXState.x4c_chanFlags & 1) {
GXSetNumChans(sGXState.x4e_numChans);
sGXState.x4d_prevNumChans = sGXState.x4e_numChans;
}
if (sGXState.x4c_flags & 2) {
if (sGXState.x4c_chanFlags & 2) {
u16 flags = sGXState.x34_chanCtrls[0];
GXBool enable = ShiftRightAndMask(flags, 1, 0);
GXColorSrc ambSrc = static_cast< GXColorSrc >(ShiftRightAndMask(flags, 1, 1));
@ -355,7 +350,7 @@ void CGX::FlushState() {
GXSetChanCtrl(GX_COLOR0, enable, ambSrc, matSrc, lightMask, diffFn, attnFn);
sGXState.x30_prevChanCtrls[0] = sGXState.x34_chanCtrls[0];
}
if (sGXState.x4c_flags & 4) {
if (sGXState.x4c_chanFlags & 4) {
u16 flags = sGXState.x34_chanCtrls[1];
GXBool enable = ShiftRightAndMask(flags, 1, 0);
GXColorSrc ambSrc = static_cast< GXColorSrc >(ShiftRightAndMask(flags, 1, 1));
@ -366,7 +361,7 @@ void CGX::FlushState() {
GXSetChanCtrl(GX_COLOR1, enable, ambSrc, matSrc, lightMask, diffFn, attnFn);
sGXState.x30_prevChanCtrls[1] = sGXState.x34_chanCtrls[1];
}
sGXState.x4c_flags = 0;
sGXState.x4c_chanFlags = 0;
}
void CGX::SetIndTexMtxSTPointFive(GXIndTexMtxID id, s8 scaleExp) {