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;
CColor CGraphics::sAreaAmbientColor = CColor::skTransparentBlack;
float CGraphics::sWorldLightMultiplier;
CLight CGraphics::sDefaultDirectionalLights[3] = {
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))
};
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.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 ************
void CGraphics::Initialize()

View File

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

View File

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

View File

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

View File

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