2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _CGX
|
|
|
|
#define _CGX
|
2022-08-30 04:05:16 +00:00
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
2022-08-30 22:48:44 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
|
2022-09-05 04:00:04 +00:00
|
|
|
#include <dolphin/gx.h>
|
|
|
|
#include <dolphin/mtx.h>
|
2022-08-30 04:05:16 +00:00
|
|
|
|
|
|
|
class CGX {
|
|
|
|
public:
|
|
|
|
struct STevState {
|
2022-09-05 04:01:13 +00:00
|
|
|
uint x0_colorInArgs;
|
|
|
|
uint x4_alphaInArgs;
|
|
|
|
uint x8_colorOps;
|
|
|
|
uint xc_alphaOps;
|
|
|
|
uint x10_indFlags;
|
|
|
|
uint x14_tevOrderFlags;
|
2022-10-09 05:37:23 +00:00
|
|
|
uchar x18_kColorSel;
|
|
|
|
uchar x19_kAlphaSel;
|
2022-08-30 04:05:16 +00:00
|
|
|
|
|
|
|
STevState();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct STexState {
|
2022-09-05 04:01:13 +00:00
|
|
|
uint x0_coordGen;
|
2022-08-30 04:05:16 +00:00
|
|
|
|
|
|
|
STexState();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SFogParams {
|
2022-10-09 05:37:23 +00:00
|
|
|
float x0_fogStartZ;
|
|
|
|
float x4_fogEndZ;
|
|
|
|
float x8_fogNearZ;
|
|
|
|
float xc_fogFarZ;
|
2022-08-30 04:05:16 +00:00
|
|
|
GXColor x10_fogColor;
|
|
|
|
|
2022-08-30 22:48:44 +00:00
|
|
|
SFogParams() : x0_fogStartZ(0.f), x4_fogEndZ(1.f), x8_fogNearZ(0.1f), xc_fogFarZ(1.f) {
|
|
|
|
x10_fogColor.a = 0;
|
|
|
|
x10_fogColor.b = 0;
|
|
|
|
x10_fogColor.g = 0;
|
|
|
|
x10_fogColor.r = 0;
|
|
|
|
}
|
2022-08-30 04:05:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct SGXState {
|
2022-08-30 22:48:44 +00:00
|
|
|
const void* x0_arrayPtrs[12];
|
2022-10-09 05:37:23 +00:00
|
|
|
ushort x30_prevChanCtrls[2];
|
|
|
|
ushort x34_chanCtrls[2];
|
2022-08-30 04:05:16 +00:00
|
|
|
GXColor x38_chanAmbColors[2];
|
|
|
|
GXColor x40_chanMatColors[2];
|
2022-09-05 04:01:13 +00:00
|
|
|
uint x48_descList;
|
2022-08-30 22:48:44 +00:00
|
|
|
union {
|
2022-10-09 05:37:23 +00:00
|
|
|
uchar x4c_chanFlags;
|
2022-08-30 22:48:44 +00:00
|
|
|
struct {
|
2022-10-09 05:37:23 +00:00
|
|
|
uchar unused : 5;
|
|
|
|
uchar chansDirty : 2;
|
|
|
|
uchar numDirty : 1;
|
2022-08-31 16:06:56 +00:00
|
|
|
} x4c_flags;
|
2022-08-30 22:48:44 +00:00
|
|
|
};
|
2022-10-09 05:37:23 +00:00
|
|
|
uchar x4d_prevNumChans;
|
|
|
|
uchar x4e_numChans;
|
|
|
|
uchar x4f_numTexGens;
|
|
|
|
uchar x50_numTevStages;
|
|
|
|
uchar x51_numIndStages;
|
|
|
|
uchar x52_zmode;
|
|
|
|
uchar x53_fogType;
|
|
|
|
ushort x54_lineWidthAndOffset;
|
|
|
|
ushort x56_blendMode;
|
2022-08-30 04:05:16 +00:00
|
|
|
GXColor x58_kColors[4];
|
|
|
|
STevState x68_tevStates[16];
|
|
|
|
STexState x228_texStates[8];
|
2022-09-05 04:01:13 +00:00
|
|
|
uint x248_alphaCompare;
|
2022-08-30 04:05:16 +00:00
|
|
|
SFogParams x24c_fogParams;
|
|
|
|
|
|
|
|
SGXState();
|
|
|
|
};
|
|
|
|
|
|
|
|
enum EChannelId {
|
|
|
|
Channel0, // GX_COLOR0
|
|
|
|
Channel1, // GX_COLOR1
|
|
|
|
};
|
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
static void SetNumChans(uchar num);
|
|
|
|
static void SetNumTexGens(uchar num);
|
|
|
|
static void SetNumTevStages(uchar num);
|
|
|
|
static void SetNumIndStages(uchar num);
|
2022-08-30 04:05:16 +00:00
|
|
|
static void SetChanAmbColor(EChannelId channel, const GXColor& color);
|
|
|
|
static void SetChanMatColor(EChannelId channel, const GXColor& color);
|
2022-09-18 06:05:46 +00:00
|
|
|
static void SetChanCtrl(EChannelId channel, GXBool enable, GXColorSrc ambSrc, GXColorSrc matSrc,
|
|
|
|
GXLightID lights, GXDiffuseFn diffFn, GXAttnFn attnFn);
|
2022-08-30 04:05:16 +00:00
|
|
|
static void SetTevKColor(GXTevKColorID id, const GXColor& color);
|
2022-09-18 06:05:46 +00:00
|
|
|
static void SetTevColorIn(GXTevStageID stageId, GXTevColorArg a, GXTevColorArg b, GXTevColorArg c,
|
|
|
|
GXTevColorArg d);
|
|
|
|
static void SetTevAlphaIn(GXTevStageID stageId, GXTevAlphaArg a, GXTevAlphaArg b, GXTevAlphaArg c,
|
|
|
|
GXTevAlphaArg d);
|
|
|
|
static void SetTevColorOp(GXTevStageID stageId, GXTevOp op, GXTevBias bias, GXTevScale scale,
|
|
|
|
GXBool clamp, GXTevRegID outReg);
|
2022-09-05 04:01:13 +00:00
|
|
|
static void SetTevColorOp_Compressed(GXTevStageID stageId, uint flags);
|
2022-09-18 06:05:46 +00:00
|
|
|
static void SetTevAlphaOp(GXTevStageID stageId, GXTevOp op, GXTevBias bias, GXTevScale scale,
|
|
|
|
GXBool clamp, GXTevRegID outReg);
|
2022-09-05 04:01:13 +00:00
|
|
|
static void SetTevAlphaOp_Compressed(GXTevStageID stageId, uint flags);
|
2022-08-30 22:48:44 +00:00
|
|
|
static void SetTevKColorSel(GXTevStageID stageId, GXTevKColorSel sel);
|
|
|
|
static void SetTevKAlphaSel(GXTevStageID stageId, GXTevKAlphaSel sel);
|
2022-09-18 06:05:46 +00:00
|
|
|
static void SetTevOrder(GXTevStageID stageId, GXTexCoordID texCoord, GXTexMapID texMap,
|
|
|
|
GXChannelID color);
|
|
|
|
static void SetBlendMode(GXBlendMode mode, GXBlendFactor srcFac, GXBlendFactor dstFac,
|
|
|
|
GXLogicOp op);
|
2023-02-06 16:22:14 +00:00
|
|
|
static void SetZMode(GXBool compareEnable, GXCompare func, GXBool updateEnable);
|
2022-10-09 05:37:23 +00:00
|
|
|
static void SetAlphaCompare(GXCompare comp0, uchar ref0, GXAlphaOp op, GXCompare comp1,
|
|
|
|
uchar ref1);
|
2022-09-18 06:05:46 +00:00
|
|
|
static void SetTevIndirect(GXTevStageID stageId, GXIndTexStageID indStage, GXIndTexFormat fmt,
|
|
|
|
GXIndTexBiasSel biasSel, GXIndTexMtxID mtxSel, GXIndTexWrap wrapS,
|
|
|
|
GXIndTexWrap wrapT, GXBool addPrev, GXBool indLod,
|
2022-08-30 22:48:44 +00:00
|
|
|
GXIndTexAlphaSel alphaSel);
|
|
|
|
static void SetTevDirect(GXTevStageID stageId);
|
2022-09-18 06:05:46 +00:00
|
|
|
static void SetTexCoordGen(GXTexCoordID dstCoord, GXTexGenType fn, GXTexGenSrc src, GXTexMtx mtx,
|
|
|
|
GXBool normalize, GXPTTexMtx postMtx);
|
2022-10-09 05:37:23 +00:00
|
|
|
static void SetArray(GXAttr attr, const void* data, uchar stride);
|
|
|
|
static void SetFog(GXFogType type, float startZ, float endZ, float nearZ, float farZ,
|
2022-09-18 06:05:46 +00:00
|
|
|
const GXColor& color);
|
2022-10-09 05:37:23 +00:00
|
|
|
static void SetLineWidth(uchar width, GXTexOffset offset);
|
2022-08-30 22:48:44 +00:00
|
|
|
static void SetIndTexMtxSTPointFive(GXIndTexMtxID id, s8 scaleExp);
|
2022-09-05 04:01:13 +00:00
|
|
|
static void SetVtxDescv_Compressed(uint flags);
|
2022-08-31 04:54:17 +00:00
|
|
|
static void SetVtxDesc(GXAttr attr, GXAttrType type); // name?
|
|
|
|
static void ResetVtxDescv(); // name?
|
|
|
|
static void SetVtxDescv(const GXVtxDescList* list);
|
2022-09-18 06:05:46 +00:00
|
|
|
static void SetStandardDirectTev_Compressed(GXTevStageID stageId, uint colorArgs, uint alphaArgs,
|
|
|
|
uint colorOps, uint alphaOps);
|
2022-08-31 04:54:17 +00:00
|
|
|
static void SetStandardTevColorAlphaOp(GXTevStageID stageId);
|
2022-08-30 22:48:44 +00:00
|
|
|
|
|
|
|
static void CallDisplayList(const void* ptr, size_t size);
|
2022-10-09 05:37:23 +00:00
|
|
|
static void Begin(GXPrimitive prim, GXVtxFmt fmt, ushort numVtx);
|
2022-08-30 22:48:44 +00:00
|
|
|
static void End();
|
|
|
|
static void ResetGXStates();
|
|
|
|
static void ResetGXStatesFull(); // name?
|
2022-08-30 04:05:16 +00:00
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
static inline void LoadTexMtxImm(const float mtx[][4], unsigned long id, GXTexMtxType type) {
|
2022-09-18 06:05:46 +00:00
|
|
|
GXLoadTexMtxImm(const_cast< MtxPtr >(mtx), id, type);
|
2022-09-05 04:00:04 +00:00
|
|
|
}
|
|
|
|
|
2022-08-30 04:05:16 +00:00
|
|
|
static GXColor GetChanAmbColor(EChannelId channel);
|
2022-10-09 05:37:23 +00:00
|
|
|
static void GetFog(GXFogType* fogType, float* fogStartZ, float* fogEndZ, float* fogNearZ,
|
|
|
|
float* fogFarZ, GXColor* fogColor);
|
2022-08-30 04:05:16 +00:00
|
|
|
|
|
|
|
static inline bool CompareGXColors(const GXColor& lhs, const GXColor& rhs) {
|
2022-09-05 04:01:13 +00:00
|
|
|
return *reinterpret_cast< const uint* >(&lhs) == *reinterpret_cast< const uint* >(&rhs);
|
2022-08-30 04:05:16 +00:00
|
|
|
}
|
|
|
|
static inline void CopyGXColor(GXColor& dst, const GXColor& src) {
|
2022-09-05 04:01:13 +00:00
|
|
|
*reinterpret_cast< uint* >(&dst) = *reinterpret_cast< const uint* >(&src);
|
2022-08-30 04:05:16 +00:00
|
|
|
}
|
2022-09-05 04:01:13 +00:00
|
|
|
static inline uint MaskAndShiftLeft(uint v, uint m, uint s) { return (v & m) << s; }
|
|
|
|
static inline uint ShiftRightAndMask(uint v, uint m, uint s) { return (v >> s) & m; }
|
2022-08-30 04:05:16 +00:00
|
|
|
|
|
|
|
private:
|
2022-08-30 22:48:44 +00:00
|
|
|
static void FlushState();
|
2022-09-05 04:01:13 +00:00
|
|
|
static void update_fog(uint flags);
|
2022-08-31 16:06:56 +00:00
|
|
|
static void apply_fog() {
|
|
|
|
static const GXColor black = {0, 0, 0, 0};
|
2022-09-18 06:05:46 +00:00
|
|
|
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 & (7 << 5)) == (GX_BL_ONE << 5)
|
|
|
|
? black
|
|
|
|
: sGXState.x24c_fogParams.x10_fogColor);
|
2022-08-31 16:06:56 +00:00
|
|
|
}
|
2022-08-30 22:48:44 +00:00
|
|
|
|
2022-08-30 04:05:16 +00:00
|
|
|
static SGXState sGXState;
|
|
|
|
};
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _CGX
|