2022-03-04 07:47:21 +00:00
|
|
|
#include "Graphics/CTevCombiners.hpp"
|
|
|
|
|
2022-03-12 15:47:20 +00:00
|
|
|
#include "Graphics/CGX.hpp"
|
|
|
|
|
2022-03-04 07:47:21 +00:00
|
|
|
namespace metaforce::CTevCombiners {
|
|
|
|
u32 CTevPass::sNextUniquePass = 0;
|
|
|
|
|
|
|
|
void CTevPass::Execute(ERglTevStage stage) const {
|
2022-07-29 20:16:55 +00:00
|
|
|
const auto stageId = GXTevStageID(stage);
|
2022-03-12 15:47:20 +00:00
|
|
|
CGX::SetTevColorIn(stageId, x4_colorPass.x0_a, x4_colorPass.x4_b, x4_colorPass.x8_c, x4_colorPass.xc_d);
|
|
|
|
CGX::SetTevAlphaIn(stageId, x14_alphaPass.x0_a, x14_alphaPass.x4_b, x14_alphaPass.x8_c, x14_alphaPass.xc_d);
|
|
|
|
CGX::SetTevColorOp(stageId, x24_colorOp.x4_op, x24_colorOp.x8_bias, x24_colorOp.xc_scale, x24_colorOp.x0_clamp,
|
|
|
|
x24_colorOp.x10_regId);
|
|
|
|
CGX::SetTevAlphaOp(stageId, x38_alphaOp.x4_op, x38_alphaOp.x8_bias, x38_alphaOp.xc_scale, x38_alphaOp.x0_clamp,
|
|
|
|
x38_alphaOp.x10_regId);
|
2022-07-29 20:16:55 +00:00
|
|
|
CGX::SetTevKColorSel(stageId, GX_TEV_KCSEL_8_8);
|
|
|
|
CGX::SetTevKAlphaSel(stageId, GX_TEV_KASEL_8_8);
|
2022-03-04 07:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
constexpr u32 maxTevPasses = 2;
|
|
|
|
static u32 sNumEnabledPasses;
|
|
|
|
static std::array<bool, maxTevPasses> sValidPasses;
|
|
|
|
|
2022-08-15 22:50:20 +00:00
|
|
|
const CTevPass kEnvPassthru{
|
2022-07-29 20:16:55 +00:00
|
|
|
{GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_RASC},
|
|
|
|
{GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_RASA},
|
2022-03-04 07:47:21 +00:00
|
|
|
};
|
2022-08-15 22:50:20 +00:00
|
|
|
const CTevPass kEnvBlendCTandCConCF{
|
2022-07-29 20:16:55 +00:00
|
|
|
{GX_CC_C0, GX_CC_TEXC, GX_CC_RASC, GX_CC_ZERO},
|
|
|
|
{GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_RASA},
|
2022-03-20 20:24:02 +00:00
|
|
|
};
|
2022-08-15 22:50:20 +00:00
|
|
|
const CTevPass kEnvModulateConstColor{
|
2022-07-29 20:16:55 +00:00
|
|
|
{GX_CC_ZERO, GX_CC_RASC, GX_CC_C0, GX_CC_ZERO},
|
|
|
|
{GX_CA_ZERO, GX_CA_RASA, GX_CA_A0, GX_CA_ZERO},
|
2022-03-04 07:47:21 +00:00
|
|
|
};
|
2022-08-15 22:50:20 +00:00
|
|
|
const CTevPass kEnvConstColor{
|
2022-07-29 20:16:55 +00:00
|
|
|
{GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_C0},
|
|
|
|
{GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_A0},
|
2022-03-04 07:47:21 +00:00
|
|
|
};
|
2022-08-15 22:50:20 +00:00
|
|
|
const CTevPass kEnvModulate{
|
2022-07-29 20:16:55 +00:00
|
|
|
{GX_CC_ZERO, GX_CC_RASC, GX_CC_TEXC, GX_CC_ZERO},
|
|
|
|
{GX_CA_ZERO, GX_CA_RASA, GX_CA_TEXA, GX_CA_ZERO},
|
2022-03-04 07:47:21 +00:00
|
|
|
};
|
2022-08-15 22:50:20 +00:00
|
|
|
const CTevPass kEnvDecal{
|
2022-07-29 20:16:55 +00:00
|
|
|
{GX_CC_RASC, GX_CC_TEXC, GX_CC_TEXA, GX_CC_ZERO},
|
|
|
|
{GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_RASA},
|
2022-03-04 07:47:21 +00:00
|
|
|
};
|
2022-08-15 22:50:20 +00:00
|
|
|
const CTevPass kEnvBlend{
|
2022-07-29 20:16:55 +00:00
|
|
|
{GX_CC_RASC, GX_CC_ONE, GX_CC_TEXC, GX_CC_ZERO},
|
|
|
|
{GX_CA_ZERO, GX_CA_TEXA, GX_CA_RASA, GX_CA_ZERO},
|
2022-03-04 07:47:21 +00:00
|
|
|
};
|
2022-08-15 22:50:20 +00:00
|
|
|
const CTevPass kEnvReplace{
|
2022-07-29 20:16:55 +00:00
|
|
|
{GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_TEXC},
|
|
|
|
{GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_TEXA},
|
2022-03-04 07:47:21 +00:00
|
|
|
};
|
2022-08-15 22:50:20 +00:00
|
|
|
const CTevPass kEnvModulateAlpha{
|
2022-07-29 20:16:55 +00:00
|
|
|
{GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_RASC},
|
|
|
|
{GX_CA_ZERO, GX_CA_TEXA, GX_CA_RASA, GX_CA_ZERO},
|
2022-03-04 07:47:21 +00:00
|
|
|
};
|
2022-08-15 22:50:20 +00:00
|
|
|
const CTevPass kEnvModulateColor{
|
2022-07-29 20:16:55 +00:00
|
|
|
{GX_CC_ZERO, GX_CC_TEXC, GX_CC_RASC, GX_CC_ZERO},
|
|
|
|
{GX_CA_ZERO, GX_CA_KONST, GX_CA_RASA, GX_CA_ZERO},
|
2022-03-04 07:47:21 +00:00
|
|
|
};
|
2022-08-15 22:50:20 +00:00
|
|
|
const CTevPass kEnvModulateColorByAlpha{
|
2022-07-29 20:16:55 +00:00
|
|
|
{GX_CC_ZERO, GX_CC_CPREV, GX_CC_APREV, GX_CC_ZERO},
|
|
|
|
{GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO, GX_CA_APREV},
|
2022-03-04 07:47:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void Init() {
|
|
|
|
sNumEnabledPasses = maxTevPasses;
|
|
|
|
sValidPasses.fill(true);
|
|
|
|
for (int i = 0; i < maxTevPasses; ++i) {
|
|
|
|
DeletePass(static_cast<ERglTevStage>(i));
|
|
|
|
}
|
|
|
|
sValidPasses.fill(false);
|
|
|
|
RecomputePasses();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupPass(ERglTevStage stage, const CTevPass& pass) {
|
2022-08-15 22:50:20 +00:00
|
|
|
if (pass == kEnvPassthru) {
|
2022-03-04 07:47:21 +00:00
|
|
|
DeletePass(stage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (SetPassCombiners(stage, pass)) {
|
|
|
|
sValidPasses[static_cast<size_t>(stage)] = true;
|
|
|
|
RecomputePasses();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeletePass(ERglTevStage stage) {
|
2022-08-15 22:50:20 +00:00
|
|
|
SetPassCombiners(stage, kEnvPassthru);
|
2022-03-04 07:47:21 +00:00
|
|
|
sValidPasses[static_cast<size_t>(stage)] = false;
|
|
|
|
RecomputePasses();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SetPassCombiners(ERglTevStage stage, const CTevPass& pass) {
|
|
|
|
pass.Execute(stage);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecomputePasses() {
|
2022-12-08 02:02:33 +00:00
|
|
|
u8 tmp = static_cast<u8>((sValidPasses[maxTevPasses - 1] != 0));
|
|
|
|
tmp++;
|
|
|
|
sNumEnabledPasses = tmp;
|
|
|
|
CGX::SetNumTevStages(tmp);
|
2022-03-04 07:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ResetStates() {
|
|
|
|
sValidPasses.fill(false);
|
2022-08-15 22:50:20 +00:00
|
|
|
kEnvPassthru.Execute(ERglTevStage::Stage0);
|
2022-03-04 07:47:21 +00:00
|
|
|
sNumEnabledPasses = 1;
|
2022-03-12 15:47:20 +00:00
|
|
|
CGX::SetNumTevStages(1);
|
2022-03-04 07:47:21 +00:00
|
|
|
}
|
|
|
|
} // namespace metaforce::CTevCombiners
|