CGraphics: Make use of std::array

This commit is contained in:
Lioncash 2020-06-12 16:32:01 -04:00
parent bf9233779a
commit ece0aec27a
5 changed files with 29 additions and 27 deletions

View File

@ -24,11 +24,11 @@ CGraphics::ELightingMode CGraphics::sLightMode;
uint32 CGraphics::sNumLights; uint32 CGraphics::sNumLights;
CColor CGraphics::sAreaAmbientColor = CColor::skTransparentBlack; CColor CGraphics::sAreaAmbientColor = CColor::skTransparentBlack;
float CGraphics::sWorldLightMultiplier; float CGraphics::sWorldLightMultiplier;
CLight CGraphics::sDefaultDirectionalLights[3] = { std::array<CLight, 3> CGraphics::sDefaultDirectionalLights{{
CLight::BuildDirectional(CVector3f(0), CVector3f (0.f, -0.866025f, -0.5f), CColor(0.3f, 0.3f, 0.3f, 0.3f)), CLight::BuildDirectional(CVector3f(0), CVector3f(0.f, -0.866025f, -0.5f), CColor(0.3f, 0.3f, 0.3f, 0.3f)),
CLight::BuildDirectional(CVector3f(0), CVector3f(-0.75f, 0.433013f, -0.5f), CColor(0.3f, 0.3f, 0.3f, 0.3f)), CLight::BuildDirectional(CVector3f(0), CVector3f(-0.75f, 0.433013f, -0.5f), CColor(0.3f, 0.3f, 0.3f, 0.3f)),
CLight::BuildDirectional(CVector3f(0), CVector3f( 0.75f, 0.433013f, -0.5f), CColor(0.3f, 0.3f, 0.3f, 0.3f)) CLight::BuildDirectional(CVector3f(0), CVector3f(0.75f, 0.433013f, -0.5f), CColor(0.3f, 0.3f, 0.3f, 0.3f)),
}; }};
// ************ FUNCTIONS ************ // ************ FUNCTIONS ************
void CGraphics::Initialize() void CGraphics::Initialize()

View File

@ -9,6 +9,7 @@
#include <Common/Math/CMatrix4f.h> #include <Common/Math/CMatrix4f.h>
#include <Common/Math/CVector3f.h> #include <Common/Math/CVector3f.h>
#include <Common/Math/CVector4f.h> #include <Common/Math/CVector4f.h>
#include <array>
/** /**
* todo: this entire thing needs to be further abstracted, other classes shouldn't * todo: this entire thing needs to be further abstracted, other classes shouldn't
@ -43,8 +44,8 @@ public:
// SVertexBlock // SVertexBlock
struct SVertexBlock struct SVertexBlock
{ {
CMatrix4f TexMatrices[10]; std::array<CMatrix4f, 10> TexMatrices;
CMatrix4f PostMatrices[20]; std::array<CMatrix4f, 20> PostMatrices;
CColor COLOR0_Amb; CColor COLOR0_Amb;
CColor COLOR0_Mat; CColor COLOR0_Mat;
CColor COLOR1_Amb; CColor COLOR1_Amb;
@ -55,15 +56,15 @@ public:
// SPixelBlock // SPixelBlock
struct SPixelBlock struct SPixelBlock
{ {
CColor Konst[4]; std::array<CColor, 4> Konst;
CColor TevColor[4]; std::array<CColor, 4> TevColor;
CColor TintColor; CColor TintColor;
float LightmapMultiplier; float LightmapMultiplier;
float Padding[3]; std::array<float, 3> Padding;
void SetAllTevColors(const CColor& color) void SetAllTevColors(const CColor& color)
{ {
std::fill(std::begin(TevColor), std::end(TevColor), color); TevColor.fill(color);
} }
}; };
static SPixelBlock sPixelBlock; static SPixelBlock sPixelBlock;
@ -79,7 +80,7 @@ public:
CVector4f DistAtten; CVector4f DistAtten;
CVector4f AngleAtten; CVector4f AngleAtten;
}; };
SGXLight Lights[8]; std::array<SGXLight, 8> Lights;
}; };
static SLightBlock sLightBlock; static SLightBlock sLightBlock;
@ -90,7 +91,7 @@ public:
static constexpr CColor skDefaultAmbientColor{0.5f, 0.5f, 0.5f, 0.0f}; static constexpr CColor skDefaultAmbientColor{0.5f, 0.5f, 0.5f, 0.0f};
static CColor sAreaAmbientColor; static CColor sAreaAmbientColor;
static float sWorldLightMultiplier; static float sWorldLightMultiplier;
static CLight sDefaultDirectionalLights[3]; static std::array<CLight, 3> sDefaultDirectionalLights;
// Functions // Functions
static void Initialize(); static void Initialize();

View File

@ -198,8 +198,9 @@ CStructProperty* CLight::GetProperties() const
// ************ OTHER ************ // ************ OTHER ************
void CLight::Load() const void CLight::Load() const
{ {
uint8 Index = (uint8) CGraphics::sNumLights; const auto Index = static_cast<uint8>(CGraphics::sNumLights);
if (Index >= 8) return; if (Index >= CGraphics::sLightBlock.Lights.size())
return;
CGraphics::SLightBlock::SGXLight *pLight = &CGraphics::sLightBlock.Lights[Index]; CGraphics::SLightBlock::SGXLight *pLight = &CGraphics::sLightBlock.Lights[Index];

View File

@ -181,13 +181,13 @@ bool CMaterial::SetCurrent(FRenderOptions Options)
glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha); glBlendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
// Set konst inputs // Set konst inputs
for (uint32 iKonst = 0; iKonst < 4; iKonst++) CGraphics::sPixelBlock.Konst = mKonstColors;
CGraphics::sPixelBlock.Konst[iKonst] = mKonstColors[iKonst];
// Set TEV registers // Set TEV registers
if (mVersion >= EGame::Corruption) if (mVersion >= EGame::Corruption)
for (uint32 iTev = 0; iTev < 4; iTev++) {
CGraphics::sPixelBlock.TevColor[iTev] = mTevColors[iTev]; CGraphics::sPixelBlock.TevColor = mTevColors;
}
// Set color channels // Set color channels
// COLOR0_Amb,Mat is initialized by the node instead of by the material // COLOR0_Amb,Mat is initialized by the node instead of by the material
@ -242,21 +242,21 @@ uint64 CMaterial::HashParameters()
{ {
CFNV1A Hash(CFNV1A::EHashLength::k64Bit); CFNV1A Hash(CFNV1A::EHashLength::k64Bit);
Hash.HashLong((int) mVersion); Hash.HashLong(static_cast<int>(mVersion));
Hash.HashLong(mOptions); Hash.HashLong(mOptions);
Hash.HashLong(mVtxDesc); Hash.HashLong(mVtxDesc);
Hash.HashData(mKonstColors, sizeof(CColor) * 4); Hash.HashData(mKonstColors.data(), sizeof(mKonstColors));
Hash.HashData(mTevColors, sizeof(CColor) * 4); Hash.HashData(mTevColors.data(), sizeof(mTevColors));
Hash.HashLong(mBlendSrcFac); Hash.HashLong(mBlendSrcFac);
Hash.HashLong(mBlendDstFac); Hash.HashLong(mBlendDstFac);
Hash.HashByte(mLightingEnabled); Hash.HashByte(mLightingEnabled);
Hash.HashLong(mEchoesUnknownA); Hash.HashLong(mEchoesUnknownA);
Hash.HashLong(mEchoesUnknownB); Hash.HashLong(mEchoesUnknownB);
for (uint32 iPass = 0; iPass < mPasses.size(); iPass++) for (auto& pass : mPasses)
mPasses[iPass]->HashParameters(Hash); pass->HashParameters(Hash);
uint64 NewHash = Hash.GetHash64(); const uint64 NewHash = Hash.GetHash64();
if (mParametersHash != NewHash) if (mParametersHash != NewHash)
ClearShader(); ClearShader();

View File

@ -83,8 +83,8 @@ private:
EGame mVersion; EGame mVersion;
FMaterialOptions mOptions; // See the EMaterialOption enum above FMaterialOptions mOptions; // See the EMaterialOption enum above
FVertexDescription mVtxDesc; // Descriptor of vertex attributes used by this material FVertexDescription mVtxDesc; // Descriptor of vertex attributes used by this material
CColor mKonstColors[4]; // Konst color values for TEV std::array<CColor, 4> mKonstColors; // Konst color values for TEV
CColor mTevColors[4]; // Initial TEV color register values (for MP3 materials only) std::array<CColor, 4> mTevColors; // Initial TEV color register values (for MP3 materials only)
GLenum mBlendSrcFac; // Source blend factor GLenum mBlendSrcFac; // Source blend factor
GLenum mBlendDstFac; // Dest blend factor GLenum mBlendDstFac; // Dest blend factor
bool mLightingEnabled; // Color channel control flags; indicate whether lighting is enabled bool mLightingEnabled; // Color channel control flags; indicate whether lighting is enabled