2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-12-14 15:26:10 +00:00

CGuiFrame & Model fixes; CModel::Draw impl; Document CModelFlags bits

This commit is contained in:
2022-03-05 19:26:52 -05:00
parent b3daf4a527
commit 6c3e74b93e
25 changed files with 135 additions and 192 deletions

View File

@@ -48,7 +48,7 @@ void CCubeMaterial::SetCurrent(const CModelFlags& flags, const CCubeSurface& sur
}
u32 texCount = SBig(*reinterpret_cast<const u32*>(materialDataCur + 4));
if ((flags.x2_flags & 4) != 0) { // render without texture lock
if (flags.x2_flags & CModelFlagBits::NoTextureLock) {
materialDataCur += (2 + texCount) * 4;
} else {
materialDataCur += 8;
@@ -259,16 +259,16 @@ void CCubeMaterial::SetupBlendMode(u32 blendFactors, const CModelFlags& flags, b
aurora::gfx::set_blend_mode(ERglBlendMode::Blend, newSrcFactor, newDstFactor, ERglLogicOp::Clear);
}
void CCubeMaterial::HandleDepth(u16 modelFlags, CCubeMaterialFlags matFlags) {
void CCubeMaterial::HandleDepth(CModelFlagsFlags modelFlags, CCubeMaterialFlags matFlags) {
ERglEnum func = ERglEnum::Never;
if ((modelFlags & 0x1) == 0) {
if (!(modelFlags & CModelFlagBits::DepthTest)) {
func = ERglEnum::Always;
} else if ((modelFlags & 0x8) != 0) {
func = (modelFlags & 0x10) != 0 ? ERglEnum::Greater : ERglEnum::GEqual;
} else if (modelFlags & CModelFlagBits::DepthGreater) {
func = modelFlags & CModelFlagBits::DepthNonInclusive ? ERglEnum::Greater : ERglEnum::GEqual;
} else {
func = (modelFlags & 0x10) != 0 ? ERglEnum::Less : ERglEnum::LEqual;
func = modelFlags & CModelFlagBits::DepthNonInclusive ? ERglEnum::Less : ERglEnum::LEqual;
}
bool depthWrite = (modelFlags & 0x2) != 0 && matFlags & CCubeMaterialFlagBits::fDepthWrite;
bool depthWrite = modelFlags & CModelFlagBits::DepthUpdate && matFlags & CCubeMaterialFlagBits::fDepthWrite;
aurora::gfx::set_depth_mode(true, func, depthWrite);
}

View File

@@ -7,12 +7,12 @@
#include "CToken.hpp"
#include "GCNTypes.hpp"
#include "Graphics/CTexture.hpp"
#include "Graphics/CModel.hpp"
#include "IObjectStore.hpp"
namespace metaforce {
class CCubeModel;
class CCubeSurface;
struct CModelFlags;
enum class CCubeMaterialFlagBits : u32 {
fKonstValues = 0x8,
@@ -93,7 +93,7 @@ private:
void SetCurrentBlack();
static void SetupBlendMode(u32 blendFactors, const CModelFlags& flags, bool alphaTest);
static void HandleDepth(u16 modelFlags, CCubeMaterialFlags matFlags);
static void HandleDepth(CModelFlagsFlags modelFlags, CCubeMaterialFlags matFlags);
static u32 HandleColorChannels(u32 chanCount, u32 firstChan);
static void HandleTev(u32 tevCur, const u8* materialDataCur, const u32* texMapTexCoordFlags, bool shadowMapsEnabled);
static u32 HandleAnimatedUV(const u32* uvAnim, u32 texMtx, u32 pttTexMtx);

View File

@@ -377,7 +377,7 @@ u32 CCubeRenderer::GetFPS() { return CGraphics::GetFPS(); }
void CCubeRenderer::CacheReflection(IRenderer::TReflectionCallback cb, void* ctx, bool clearAfter) {}
void CCubeRenderer::DrawSpaceWarp(const zeus::CVector3f& pt, float strength) {}
void CCubeRenderer::DrawThermalModel(const CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol,
TVectorRef positions, TVectorRef normals, CModelFlags flags) {}
TVectorRef positions, TVectorRef normals, const CModelFlags& flags) {}
void CCubeRenderer::DrawModelDisintegrate(const CModel& model, const CTexture& tex, const zeus::CColor& color,
TVectorRef positions, TVectorRef normals) {}
void CCubeRenderer::DrawModelFlat(const CModel& model, const CModelFlags& flags, bool unsortedOnly) {}

View File

@@ -179,7 +179,7 @@ public:
void CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) override;
void DrawSpaceWarp(const zeus::CVector3f& pt, float strength) override;
void DrawThermalModel(const CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol,
TVectorRef positions, TVectorRef normals, CModelFlags flags) override;
TVectorRef positions, TVectorRef normals, const CModelFlags& flags) override;
void DrawModelDisintegrate(const CModel& model, const CTexture& tex, const zeus::CColor& color, TVectorRef positions,
TVectorRef normals) override;
void DrawModelFlat(const CModel& model, const CModelFlags& flags, bool unsortedOnly) override;

View File

@@ -249,12 +249,28 @@ void CModel::Touch(u32 matIdx) {
}
}
void CModel::Draw(CModelFlags flags) const {}
void CModel::Draw(CModelFlags flags) {
if (flags.x2_flags & CModelFlagBits::DrawNormal) {
x28_modelInst->DrawNormal(nullptr, nullptr, ESurfaceSelection::All);
}
CCubeMaterial::ResetCachedMaterials();
MoveToThisFrameList();
VerifyCurrentShader(flags.x1_matSetIdx);
x28_modelInst->Draw(flags);
}
void CModel::Draw(TVectorRef positions, TVectorRef normals, CModelFlags flags) {}
void CModel::Draw(TVectorRef positions, TVectorRef normals, const CModelFlags& flags) {
if (flags.x2_flags & CModelFlagBits::DrawNormal) {
x28_modelInst->DrawNormal(positions, normals, ESurfaceSelection::All);
}
CCubeMaterial::ResetCachedMaterials();
MoveToThisFrameList();
VerifyCurrentShader(flags.x1_matSetIdx);
x28_modelInst->Draw(positions, normals, flags);
}
void CModel::DrawSortedParts(CModelFlags flags) {
if ((flags.x2_flags & 0x20) != 0) {
if (flags.x2_flags & CModelFlagBits::DrawNormal) {
x28_modelInst->DrawNormal(nullptr, nullptr, ESurfaceSelection::Sorted);
}
CCubeMaterial::ResetCachedMaterials();
@@ -264,7 +280,7 @@ void CModel::DrawSortedParts(CModelFlags flags) {
}
void CModel::DrawUnsortedParts(CModelFlags flags) {
if ((flags.x2_flags & 0x20) != 0) {
if (flags.x2_flags & CModelFlagBits::DrawNormal) {
x28_modelInst->DrawNormal(nullptr, nullptr, ESurfaceSelection::Unsorted);
}
CCubeMaterial::ResetCachedMaterials();

View File

@@ -13,6 +13,17 @@ namespace metaforce {
class CCubeSurface;
class CCubeMaterial;
enum class CModelFlagBits : u16 {
DepthTest = 0x1,
DepthUpdate = 0x2,
NoTextureLock = 0x4,
DepthGreater = 0x8,
DepthNonInclusive = 0x10,
DrawNormal = 0x20,
Unknown1 = 0x40,
};
using CModelFlagsFlags = Flags<CModelFlagBits>;
struct CModelFlags {
/**
* 2: add color
@@ -22,14 +33,7 @@ struct CModelFlags {
*/
u8 x0_blendMode = 0;
u8 x1_matSetIdx = 0;
/**
* 0x1: depth equal
* 0x2: depth update
* 0x4: render without texture lock
* 0x8: depth greater
* 0x10: depth non-inclusive
*/
u16 x2_flags = 0;
CModelFlagsFlags x2_flags{};
/**
* Set into kcolor slot specified by material
*/
@@ -38,6 +42,8 @@ struct CModelFlags {
constexpr CModelFlags() = default;
constexpr CModelFlags(u8 blendMode, u8 shadIdx, u16 flags, const zeus::CColor& col)
: x0_blendMode(blendMode), x1_matSetIdx(shadIdx), x2_flags(flags), x4_color(col) {}
constexpr CModelFlags(u8 blendMode, u8 shadIdx, CModelFlagsFlags flags, const zeus::CColor& col)
: x0_blendMode(blendMode), x1_matSetIdx(shadIdx), x2_flags(flags), x4_color(col) {}
bool operator==(const CModelFlags& other) const {
return x0_blendMode == other.x0_blendMode && x1_matSetIdx == other.x1_matSetIdx && x2_flags == other.x2_flags &&
@@ -92,8 +98,8 @@ public:
void RemoveFromList();
void VerifyCurrentShader(u32 matIdx);
void Touch(u32 matIdx);
void Draw(CModelFlags flags) const;
void Draw(TVectorRef positions, TVectorRef normals, CModelFlags flags);
void Draw(CModelFlags flags);
void Draw(TVectorRef positions, TVectorRef normals, const CModelFlags& flags);
void DrawSortedParts(CModelFlags flags);
void DrawUnsortedParts(CModelFlags flags);
bool IsLoaded(u32 matIdx);

View File

@@ -87,7 +87,7 @@ public:
virtual void CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) = 0;
virtual void DrawSpaceWarp(const zeus::CVector3f& pt, float strength) = 0;
virtual void DrawThermalModel(const CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol,
TVectorRef positions, TVectorRef normals, CModelFlags flags) = 0;
TVectorRef positions, TVectorRef normals, const CModelFlags& flags) = 0;
virtual void DrawModelDisintegrate(const CModel& model, const CTexture& tex, const zeus::CColor& color,
TVectorRef positions, TVectorRef normals) = 0;
virtual void DrawModelFlat(const CModel& model, const CModelFlags& flags, bool unsortedOnly) = 0;