Cleanup & refactoring

This commit is contained in:
Aruki
2018-12-16 14:00:40 -07:00
parent 2287b05bc3
commit c4829f5fda
197 changed files with 2461 additions and 2345 deletions

View File

@@ -8,7 +8,7 @@
class CBasicModel : public CResource
{
DECLARE_RESOURCE_TYPE(eModel)
DECLARE_RESOURCE_TYPE(Model)
protected:
CAABox mAABox;
uint32 mVertexCount;

View File

@@ -76,13 +76,13 @@ void CModel::BufferGL()
// then add the indices to the IBO. We convert some primitives to strips to minimize draw calls.
switch (pPrim->Type)
{
case eGX_Triangles:
case EPrimitiveType::Triangles:
pIBO->TrianglesToStrips(Indices.data(), Indices.size());
break;
case eGX_TriangleFan:
case EPrimitiveType::TriangleFan:
pIBO->FansToStrips(Indices.data(), Indices.size());
break;
case eGX_Quads:
case EPrimitiveType::Quads:
pIBO->QuadsToStrips(Indices.data(), Indices.size());
break;
default:
@@ -137,12 +137,12 @@ void CModel::DrawSurface(FRenderOptions Options, uint32 Surface, uint32 MatSet)
MatSet = mMaterialSets.size() - 1;
// Bind material
if ((Options & eNoMaterialSetup) == 0)
if ((Options & ERenderOption::NoMaterialSetup) == 0)
{
SSurface *pSurf = mSurfaces[Surface];
CMaterial *pMat = mMaterialSets[MatSet]->MaterialByIndex(pSurf->MaterialID);
if (!Options.HasFlag(eEnableOccluders) && pMat->Options().HasFlag(CMaterial::eOccluder))
if (!Options.HasFlag(ERenderOption::EnableOccluders) && pMat->Options().HasFlag(EMaterialOption::Occluder))
return;
pMat->SetCurrent(Options);
@@ -168,7 +168,7 @@ void CModel::DrawWireframe(FRenderOptions Options, CColor WireColor /*= CColor::
// Set up wireframe
WireColor.A = 0;
CDrawUtil::UseColorShader(WireColor);
Options |= eNoMaterialSetup;
Options |= ERenderOption::NoMaterialSetup;
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glBlendFunc(GL_ONE, GL_ZERO);
@@ -185,9 +185,11 @@ void CModel::SetSkin(CSkin *pSkin)
// Assert commented out because it actually failed somewhere! Needs to be addressed.
//ASSERT(!mpSkin || !pSkin || mpSkin == pSkin); // This is to verify no model has more than one unique skin applied
//@todo this is actually really dumb and could be handled much better (and much more inline with how the game does it)
// by simply storing skinning data in a different vertex buffer that isn't tied to the model's vertex buffer
if (mpSkin != pSkin)
{
const FVertexDescription kBoneFlags = (eBoneIndices | eBoneWeights);
const FVertexDescription kBoneFlags = (EVertexAttribute::BoneIndices | EVertexAttribute::BoneWeights);
mpSkin = pSkin;
mVBO.SetSkin(pSkin);
@@ -261,7 +263,7 @@ bool CModel::HasTransparency(uint32 MatSet)
MatSet = mMaterialSets.size() - 1;
for (uint32 iMat = 0; iMat < mMaterialSets[MatSet]->NumMaterials(); iMat++)
if (mMaterialSets[MatSet]->MaterialByIndex(iMat)->Options() & CMaterial::eTransparent ) return true;
if (mMaterialSets[MatSet]->MaterialByIndex(iMat)->Options() & EMaterialOption::Transparent ) return true;
return false;
}
@@ -272,7 +274,7 @@ bool CModel::IsSurfaceTransparent(uint32 Surface, uint32 MatSet)
MatSet = mMaterialSets.size() - 1;
uint32 matID = mSurfaces[Surface]->MaterialID;
return (mMaterialSets[MatSet]->MaterialByIndex(matID)->Options() & CMaterial::eTransparent) != 0;
return (mMaterialSets[MatSet]->MaterialByIndex(matID)->Options() & EMaterialOption::Transparent) != 0;
}
bool CModel::IsLightmapped() const
@@ -284,14 +286,14 @@ bool CModel::IsLightmapped() const
for (uint32 iMat = 0; iMat < pSet->NumMaterials(); iMat++)
{
CMaterial *pMat = pSet->MaterialByIndex(iMat);
if (pMat->Options().HasFlag(CMaterial::eLightmap))
if (pMat->Options().HasFlag(EMaterialOption::Lightmap))
return true;
}
}
return false;
}
CIndexBuffer* CModel::InternalGetIBO(uint32 Surface, EGXPrimitiveType Primitive)
CIndexBuffer* CModel::InternalGetIBO(uint32 Surface, EPrimitiveType Primitive)
{
std::vector<CIndexBuffer> *pIBOs = &mSurfaceIndexBuffers[Surface];
GLenum Type = GXPrimToGLPrim(Primitive);

View File

@@ -46,7 +46,7 @@ public:
inline bool IsSkinned() const { return (mpSkin != nullptr); }
private:
CIndexBuffer* InternalGetIBO(uint32 Surface, EGXPrimitiveType Primitive);
CIndexBuffer* InternalGetIBO(uint32 Surface, EPrimitiveType Primitive);
};
#endif // MODEL_H

View File

@@ -13,7 +13,7 @@ CStaticModel::CStaticModel()
CStaticModel::CStaticModel(CMaterial *pMat)
: CBasicModel()
, mpMaterial(pMat)
, mTransparent((pMat->Options() & CMaterial::eTransparent) != 0)
, mTransparent((pMat->Options() & EMaterialOption::Transparent) != 0)
{
}
@@ -58,13 +58,13 @@ void CStaticModel::BufferGL()
// then add the indices to the IBO. We convert some primitives to strips to minimize draw calls.
switch (pPrim->Type)
{
case eGX_Triangles:
case EPrimitiveType::Triangles:
pIBO->TrianglesToStrips(Indices.data(), Indices.size());
break;
case eGX_TriangleFan:
case EPrimitiveType::TriangleFan:
pIBO->FansToStrips(Indices.data(), Indices.size());
break;
case eGX_Quads:
case EPrimitiveType::Quads:
pIBO->QuadsToStrips(Indices.data(), Indices.size());
break;
default:
@@ -109,7 +109,7 @@ void CStaticModel::Draw(FRenderOptions Options)
{
if (!mBuffered) BufferGL();
if ((Options & eNoMaterialSetup) == 0) mpMaterial->SetCurrent(Options);
if ((Options & ERenderOption::NoMaterialSetup) == 0) mpMaterial->SetCurrent(Options);
// Draw IBOs
mVBO.Bind();
@@ -133,7 +133,7 @@ void CStaticModel::DrawSurface(FRenderOptions Options, uint32 Surface)
mVBO.Bind();
glLineWidth(1.f);
if ((Options & eNoMaterialSetup) == 0) mpMaterial->SetCurrent(Options);
if ((Options & ERenderOption::NoMaterialSetup) == 0) mpMaterial->SetCurrent(Options);
for (uint32 iIBO = 0; iIBO < mIBOs.size(); iIBO++)
{
@@ -159,7 +159,7 @@ void CStaticModel::DrawWireframe(FRenderOptions Options, CColor WireColor /*= CC
// Set up wireframe
WireColor.A = 0;
CDrawUtil::UseColorShader(WireColor);
Options |= eNoMaterialSetup;
Options |= ERenderOption::NoMaterialSetup;
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glBlendFunc(GL_ONE, GL_ZERO);
@@ -179,7 +179,7 @@ CMaterial* CStaticModel::GetMaterial()
void CStaticModel::SetMaterial(CMaterial *pMat)
{
mpMaterial = pMat;
mTransparent = pMat->Options().HasFlag(CMaterial::eTransparent);
mTransparent = pMat->Options().HasFlag(EMaterialOption::Transparent);
}
bool CStaticModel::IsTransparent()
@@ -189,10 +189,10 @@ bool CStaticModel::IsTransparent()
bool CStaticModel::IsOccluder()
{
return mpMaterial->Options().HasFlag(CMaterial::eOccluder);
return mpMaterial->Options().HasFlag(EMaterialOption::Occluder);
}
CIndexBuffer* CStaticModel::InternalGetIBO(EGXPrimitiveType Primitive)
CIndexBuffer* CStaticModel::InternalGetIBO(EPrimitiveType Primitive)
{
GLenum type = GXPrimToGLPrim(Primitive);

View File

@@ -34,7 +34,7 @@ public:
bool IsOccluder();
private:
CIndexBuffer* InternalGetIBO(EGXPrimitiveType Primitive);
CIndexBuffer* InternalGetIBO(EPrimitiveType Primitive);
};
#endif // CSTATICMODEL_H

View File

@@ -7,23 +7,23 @@ uint32 VertexAttributeSize(EVertexAttribute Attrib)
{
switch (Attrib)
{
case ePosition:
case eNormal:
case EVertexAttribute::Position:
case EVertexAttribute::Normal:
return 0x0C;
case eColor0:
case eColor1:
case eBoneWeights:
case EVertexAttribute::Color0:
case EVertexAttribute::Color1:
case EVertexAttribute::BoneWeights:
return 0x10;
case eTex0:
case eTex1:
case eTex2:
case eTex3:
case eTex4:
case eTex5:
case eTex6:
case eTex7:
case EVertexAttribute::Tex0:
case EVertexAttribute::Tex1:
case EVertexAttribute::Tex2:
case EVertexAttribute::Tex3:
case EVertexAttribute::Tex4:
case EVertexAttribute::Tex5:
case EVertexAttribute::Tex6:
case EVertexAttribute::Tex7:
return 0x08;
case eBoneIndices:
case EVertexAttribute::BoneIndices:
return 0x04;
default:
errorf("AttributeSize(): Unknown vertex attribute: %d", Attrib);

View File

@@ -3,33 +3,33 @@
#include <Common/Flags.h>
enum EVertexAttribute
enum class EVertexAttribute
{
eNoAttributes = 0x0,
ePosition = 0x1,
eNormal = 0x2,
eColor0 = 0x4,
eColor1 = 0x8,
eTex0 = 0x10,
eTex1 = 0x20,
eTex2 = 0x40,
eTex3 = 0x80,
eTex4 = 0x100,
eTex5 = 0x200,
eTex6 = 0x400,
eTex7 = 0x800,
eBoneIndices = 0x1000,
eBoneWeights = 0x2000,
ePosMtx = 0x4000,
eTex0Mtx = 0x8000,
eTex1Mtx = 0x10000,
eTex2Mtx = 0x20000,
eTex3Mtx = 0x40000,
eTex4Mtx = 0x80000,
eTex5Mtx = 0x100000,
eTex6Mtx = 0x200000
None = 0x0,
Position = 0x1,
Normal = 0x2,
Color0 = 0x4,
Color1 = 0x8,
Tex0 = 0x10,
Tex1 = 0x20,
Tex2 = 0x40,
Tex3 = 0x80,
Tex4 = 0x100,
Tex5 = 0x200,
Tex6 = 0x400,
Tex7 = 0x800,
BoneIndices = 0x1000,
BoneWeights = 0x2000,
PosMtx = 0x4000,
Tex0Mtx = 0x8000,
Tex1Mtx = 0x10000,
Tex2Mtx = 0x20000,
Tex3Mtx = 0x40000,
Tex4Mtx = 0x80000,
Tex5Mtx = 0x100000,
Tex6Mtx = 0x200000
};
DECLARE_FLAGS(EVertexAttribute, FVertexDescription)
DECLARE_FLAGS_ENUMCLASS(EVertexAttribute, FVertexDescription)
extern const uint32 gkNumVertexAttribs;
uint32 VertexAttributeSize(EVertexAttribute Attrib);

View File

@@ -14,11 +14,11 @@ std::pair<bool,float> SSurface::IntersectsRay(const CRay& rkRay, bool AllowBackf
uint32 NumVerts = pPrim->Vertices.size();
// Triangles
if ((pPrim->Type == eGX_Triangles) || (pPrim->Type == eGX_TriangleFan) || (pPrim->Type == eGX_TriangleStrip))
if ((pPrim->Type == EPrimitiveType::Triangles) || (pPrim->Type == EPrimitiveType::TriangleFan) || (pPrim->Type == EPrimitiveType::TriangleStrip))
{
uint32 NumTris;
if (pPrim->Type == eGX_Triangles)
if (pPrim->Type == EPrimitiveType::Triangles)
NumTris = NumVerts / 3;
else
NumTris = NumVerts - 2;
@@ -28,7 +28,7 @@ std::pair<bool,float> SSurface::IntersectsRay(const CRay& rkRay, bool AllowBackf
CVector3f VtxA, VtxB, VtxC;
// Get the three vertices that make up the current tri
if (pPrim->Type == eGX_Triangles)
if (pPrim->Type == EPrimitiveType::Triangles)
{
uint32 VertIndex = iTri * 3;
VtxA = pPrim->Vertices[VertIndex].Position;
@@ -36,14 +36,14 @@ std::pair<bool,float> SSurface::IntersectsRay(const CRay& rkRay, bool AllowBackf
VtxC = pPrim->Vertices[VertIndex+2].Position;
}
else if (pPrim->Type == eGX_TriangleFan)
else if (pPrim->Type == EPrimitiveType::TriangleFan)
{
VtxA = pPrim->Vertices[0].Position;
VtxB = pPrim->Vertices[iTri+1].Position;
VtxC = pPrim->Vertices[iTri+2].Position;
}
else if (pPrim->Type = eGX_TriangleStrip)
else if (pPrim->Type == EPrimitiveType::TriangleStrip)
{
if (iTri & 0x1)
{
@@ -75,11 +75,11 @@ std::pair<bool,float> SSurface::IntersectsRay(const CRay& rkRay, bool AllowBackf
}
// Lines
if ((pPrim->Type == eGX_Lines) || (pPrim->Type == eGX_LineStrip))
if ((pPrim->Type == EPrimitiveType::Lines) || (pPrim->Type == EPrimitiveType::LineStrip))
{
uint32 NumLines;
if (pPrim->Type == eGX_Lines)
if (pPrim->Type == EPrimitiveType::Lines)
NumLines = NumVerts / 2;
else
NumLines = NumVerts - 1;
@@ -89,7 +89,7 @@ std::pair<bool,float> SSurface::IntersectsRay(const CRay& rkRay, bool AllowBackf
CVector3f VtxA, VtxB;
// Get the two vertices that make up the current line
uint32 Index = (pPrim->Type == eGX_Lines ? iLine * 2 : iLine);
uint32 Index = (pPrim->Type == EPrimitiveType::Lines ? iLine * 2 : iLine);
VtxA = pPrim->Vertices[Index].Position;
VtxB = pPrim->Vertices[Index+1].Position;

View File

@@ -25,7 +25,7 @@ struct SSurface
struct SPrimitive
{
EGXPrimitiveType Type;
EPrimitiveType Type;
std::vector<CVertex> Vertices;
};
std::vector<SPrimitive> Primitives;