CMaterialSet/CModel: Make use of size_t where applicable

Prevents type truncation warnings internally and also provides slightly
better code-gen, given the upper half of 64-bit registers don't need to
be constantly cleared.
This commit is contained in:
Lioncash 2020-06-15 14:24:39 -04:00
parent 6edea6a225
commit 79f7b62960
10 changed files with 158 additions and 136 deletions

View File

@ -166,17 +166,17 @@ void GenerateAssetNames(CGameProject *pProj)
ApplyGeneratedName(pSkyEntry, WorldDir + "sky/cooked/", WorldName + "_sky"); ApplyGeneratedName(pSkyEntry, WorldDir + "sky/cooked/", WorldName + "_sky");
// Move sky textures // Move sky textures
for (uint32 iSet = 0; iSet < pSkyModel->GetMatSetCount(); iSet++) for (size_t iSet = 0; iSet < pSkyModel->GetMatSetCount(); iSet++)
{ {
CMaterialSet *pSet = pSkyModel->GetMatSet(iSet); CMaterialSet *pSet = pSkyModel->GetMatSet(iSet);
for (uint32 iMat = 0; iMat < pSet->NumMaterials(); iMat++) for (size_t mat = 0; mat < pSet->NumMaterials(); mat++)
{ {
CMaterial *pMat = pSet->MaterialByIndex(iMat, true); CMaterial *pMat = pSet->MaterialByIndex(mat, true);
for (uint32 iPass = 0; iPass < pMat->PassCount(); iPass++) for (size_t pass = 0; pass < pMat->PassCount(); pass++)
{ {
CMaterialPass *pPass = pMat->Pass(iPass); CMaterialPass *pPass = pMat->Pass(pass);
if (pPass->Texture()) if (pPass->Texture())
ApplyGeneratedName(pPass->Texture()->Entry(), WorldDir + "sky/sourceimages/", pPass->Texture()->Entry()->Name()); ApplyGeneratedName(pPass->Texture()->Entry(), WorldDir + "sky/sourceimages/", pPass->Texture()->Entry()->Name());
@ -237,12 +237,12 @@ void GenerateAssetNames(CGameProject *pProj)
uint32 LightmapNum = 0; uint32 LightmapNum = 0;
CMaterialSet *pMaterials = pArea->Materials(); CMaterialSet *pMaterials = pArea->Materials();
for (uint32 iMat = 0; iMat < pMaterials->NumMaterials(); iMat++) for (size_t iMat = 0; iMat < pMaterials->NumMaterials(); iMat++)
{ {
CMaterial *pMat = pMaterials->MaterialByIndex(iMat, true); CMaterial *pMat = pMaterials->MaterialByIndex(iMat, true);
bool FoundLightmap = false; bool FoundLightmap = false;
for (uint32 iPass = 0; iPass < pMat->PassCount(); iPass++) for (size_t iPass = 0; iPass < pMat->PassCount(); iPass++)
{ {
CMaterialPass *pPass = pMat->Pass(iPass); CMaterialPass *pPass = pMat->Pass(iPass);
@ -407,30 +407,31 @@ void GenerateAssetNames(CGameProject *pProj)
for (TResourceIterator<EResourceType::Model> It(pStore); It; ++It) for (TResourceIterator<EResourceType::Model> It(pStore); It; ++It)
{ {
CModel *pModel = (CModel*) It->Load(); CModel *pModel = (CModel*) It->Load();
uint32 LightmapNum = 0; size_t LightmapNum = 0;
for (uint32 iSet = 0; iSet < pModel->GetMatSetCount(); iSet++) for (size_t iSet = 0; iSet < pModel->GetMatSetCount(); iSet++)
{ {
CMaterialSet *pSet = pModel->GetMatSet(iSet); CMaterialSet *pSet = pModel->GetMatSet(iSet);
for (uint32 iMat = 0; iMat < pSet->NumMaterials(); iMat++) for (size_t iMat = 0; iMat < pSet->NumMaterials(); iMat++)
{ {
CMaterial *pMat = pSet->MaterialByIndex(iMat, true); CMaterial *pMat = pSet->MaterialByIndex(iMat, true);
for (uint32 iPass = 0; iPass < pMat->PassCount(); iPass++) for (size_t iPass = 0; iPass < pMat->PassCount(); iPass++)
{ {
CMaterialPass *pPass = pMat->Pass(iPass); CMaterialPass *pPass = pMat->Pass(iPass);
bool IsLightmap = ( (pMat->Version() <= EGame::Echoes && pMat->Options().HasFlag(EMaterialOption::Lightmap) && iPass == 0) || const bool IsLightmap = (pMat->Version() <= EGame::Echoes && pMat->Options().HasFlag(EMaterialOption::Lightmap) && iPass == 0) ||
(pMat->Version() >= EGame::CorruptionProto && pPass->Type() == "DIFF") ); (pMat->Version() >= EGame::CorruptionProto && pPass->Type() == "DIFF");
if (IsLightmap) if (IsLightmap)
{ {
CTexture *pLightmapTex = pPass->Texture(); CTexture *pLightmapTex = pPass->Texture();
CResourceEntry *pTexEntry = pLightmapTex->Entry(); CResourceEntry *pTexEntry = pLightmapTex->Entry();
if (pTexEntry->IsNamed() || pTexEntry->IsCategorized()) continue; if (pTexEntry->IsNamed() || pTexEntry->IsCategorized())
continue;
TString TexName = TString::Format("%s_lightmap%d", *It->Name(), LightmapNum); TString TexName = TString::Format("%s_lightmap%zu", *It->Name(), LightmapNum);
ApplyGeneratedName(pTexEntry, pModel->Entry()->DirectoryPath(), TexName); ApplyGeneratedName(pTexEntry, pModel->Entry()->DirectoryPath(), TexName);
pTexEntry->SetHidden(true); pTexEntry->SetHidden(true);
LightmapNum++; LightmapNum++;

View File

@ -22,53 +22,63 @@ public:
auto pOut = std::make_unique<CMaterialSet>(); auto pOut = std::make_unique<CMaterialSet>();
pOut->mMaterials.resize(mMaterials.size()); pOut->mMaterials.resize(mMaterials.size());
for (uint32 iMat = 0; iMat < mMaterials.size(); iMat++) for (size_t i = 0; i < mMaterials.size(); i++)
pOut->mMaterials[iMat] = mMaterials[iMat]->Clone(); pOut->mMaterials[i] = mMaterials[i]->Clone();
return pOut; return pOut;
} }
uint32 NumMaterials() const size_t NumMaterials() const
{ {
return mMaterials.size(); return mMaterials.size();
} }
CMaterial* MaterialByIndex(uint32 Index, bool TryBloom) CMaterial* MaterialByIndex(size_t Index, bool TryBloom)
{ {
if (Index >= NumMaterials()) return nullptr; if (Index >= NumMaterials())
return nullptr;
CMaterial* Ret = mMaterials[Index].get(); CMaterial* Ret = mMaterials[Index].get();
if (TryBloom && Ret->GetBloomVersion()) if (TryBloom && Ret->GetBloomVersion())
return Ret->GetBloomVersion(); return Ret->GetBloomVersion();
return Ret; return Ret;
} }
CMaterial* MaterialByName(const TString& rkName) CMaterial* MaterialByName(const TString& rkName)
{ {
for (auto it = mMaterials.begin(); it != mMaterials.end(); it++) for (auto it = mMaterials.begin(); it != mMaterials.end(); it++)
if ((*it)->Name() == rkName) return it->get(); {
if ((*it)->Name() == rkName)
return it->get();
}
return nullptr; return nullptr;
} }
uint32 MaterialIndexByName(const TString& rkName) uint32 MaterialIndexByName(const TString& rkName)
{ {
for (uint32 iMat = 0; iMat < mMaterials.size(); iMat++) for (uint32 i = 0; i < mMaterials.size(); i++)
if (mMaterials[iMat]->Name() == rkName) return iMat; {
if (mMaterials[i]->Name() == rkName)
return i;
}
return -1; return UINT32_MAX;
} }
void GetUsedTextureIDs(std::set<CAssetID>& rOut) void GetUsedTextureIDs(std::set<CAssetID>& rOut)
{ {
for (uint32 iMat = 0; iMat < mMaterials.size(); iMat++) for (const auto& material : mMaterials)
{ {
CMaterial *pMat = mMaterials[iMat].get(); if (material->IndTexture())
if (pMat->IndTexture()) rOut.insert(pMat->IndTexture()->ID()); rOut.insert(material->IndTexture()->ID());
for (uint32 iPass = 0; iPass < pMat->PassCount(); iPass++) for (size_t i = 0; i < material->PassCount(); i++)
{ {
CTexture *pTex = pMat->Pass(iPass)->Texture(); const CTexture *pTex = material->Pass(i)->Texture();
if (pTex) rOut.insert(pTex->ID()); if (pTex)
rOut.insert(pTex->ID());
} }
} }
} }

View File

@ -20,30 +20,31 @@ void CModelCooker::GenerateSurfaceData()
// Get vertex attributes // Get vertex attributes
mVtxAttribs = EVertexAttribute::None; mVtxAttribs = EVertexAttribute::None;
for (uint32 iMat = 0; iMat < mpModel->GetMatCount(); iMat++) for (size_t iMat = 0; iMat < mpModel->GetMatCount(); iMat++)
{ {
CMaterial *pMat = mpModel->GetMaterialByIndex(0, iMat); CMaterial *pMat = mpModel->GetMaterialByIndex(0, iMat);
mVtxAttribs |= pMat->VtxDesc(); mVtxAttribs |= pMat->VtxDesc();
} }
// Get vertices // Get vertices
uint32 MaxIndex = 0; size_t MaxIndex = 0;
for (uint32 iSurf = 0; iSurf < mNumSurfaces; iSurf++) for (size_t iSurf = 0; iSurf < mNumSurfaces; iSurf++)
{ {
uint32 NumPrimitives = mpModel->mSurfaces[iSurf]->Primitives.size(); const size_t NumPrimitives = mpModel->mSurfaces[iSurf]->Primitives.size();
for (uint32 iPrim = 0; iPrim < NumPrimitives; iPrim++) for (size_t iPrim = 0; iPrim < NumPrimitives; iPrim++)
{ {
SSurface::SPrimitive *pPrim = &mpModel->mSurfaces[iSurf]->Primitives[iPrim]; const SSurface::SPrimitive *pPrim = &mpModel->mSurfaces[iSurf]->Primitives[iPrim];
uint32 NumVerts = pPrim->Vertices.size(); const size_t NumVerts = pPrim->Vertices.size();
for (uint32 iVtx = 0; iVtx < NumVerts; iVtx++) for (size_t iVtx = 0; iVtx < NumVerts; iVtx++)
{ {
uint32 VertIndex = pPrim->Vertices[iVtx].ArrayPosition; const uint32 VertIndex = pPrim->Vertices[iVtx].ArrayPosition;
mVertices[VertIndex] = pPrim->Vertices[iVtx]; mVertices[VertIndex] = pPrim->Vertices[iVtx];
if (VertIndex > MaxIndex) MaxIndex = VertIndex; if (VertIndex > MaxIndex)
MaxIndex = VertIndex;
} }
} }
} }
@ -142,7 +143,7 @@ void CModelCooker::WriteModelPrime(IOutputStream& rOut)
uint32 SurfacesStart = rOut.Tell(); uint32 SurfacesStart = rOut.Tell();
std::vector<uint32> SurfaceEndOffsets(mNumSurfaces); std::vector<uint32> SurfaceEndOffsets(mNumSurfaces);
for (uint32 iSurf = 0; iSurf < mNumSurfaces; iSurf++) for (size_t iSurf = 0; iSurf < mNumSurfaces; iSurf++)
{ {
SSurface *pSurface = mpModel->GetSurface(iSurf); SSurface *pSurface = mpModel->GetSurface(iSurf);

View File

@ -24,8 +24,10 @@ CModel::CModel(CMaterialSet *pSet, bool OwnsMatSet)
CModel::~CModel() CModel::~CModel()
{ {
if (mHasOwnMaterials) if (!mHasOwnMaterials)
for (uint32 iMat = 0; iMat < mMaterialSets.size(); iMat++) return;
for (size_t iMat = 0; iMat < mMaterialSets.size(); iMat++)
delete mMaterialSets[iMat]; delete mMaterialSets[iMat];
} }
@ -55,25 +57,24 @@ void CModel::BufferGL()
mSurfaceIndexBuffers.resize(mSurfaces.size()); mSurfaceIndexBuffers.resize(mSurfaces.size());
for (uint32 iSurf = 0; iSurf < mSurfaces.size(); iSurf++) for (size_t iSurf = 0; iSurf < mSurfaces.size(); iSurf++)
{ {
SSurface *pSurf = mSurfaces[iSurf]; SSurface *pSurf = mSurfaces[iSurf];
uint16 VBOStartOffset = (uint16) mVBO.Size(); uint16 VBOStartOffset = (uint16) mVBO.Size();
mVBO.Reserve((uint16) pSurf->VertexCount); mVBO.Reserve((uint16) pSurf->VertexCount);
for (uint32 iPrim = 0; iPrim < pSurf->Primitives.size(); iPrim++) for (SSurface::SPrimitive& pPrim : pSurf->Primitives)
{ {
SSurface::SPrimitive *pPrim = &pSurf->Primitives[iPrim]; CIndexBuffer *pIBO = InternalGetIBO(iSurf, pPrim.Type);
CIndexBuffer *pIBO = InternalGetIBO(iSurf, pPrim->Type); pIBO->Reserve(pPrim.Vertices.size() + 1); // Allocate enough space for this primitive, plus the restart index
pIBO->Reserve(pPrim->Vertices.size() + 1); // Allocate enough space for this primitive, plus the restart index
std::vector<uint16> Indices(pPrim->Vertices.size()); std::vector<uint16> Indices(pPrim.Vertices.size());
for (uint32 iVert = 0; iVert < pPrim->Vertices.size(); iVert++) for (size_t iVert = 0; iVert < pPrim.Vertices.size(); iVert++)
Indices[iVert] = mVBO.AddIfUnique(pPrim->Vertices[iVert], VBOStartOffset); Indices[iVert] = mVBO.AddIfUnique(pPrim.Vertices[iVert], VBOStartOffset);
// then add the indices to the IBO. We convert some primitives to strips to minimize draw calls. // then add the indices to the IBO. We convert some primitives to strips to minimize draw calls.
switch (pPrim->Type) switch (pPrim.Type)
{ {
case EPrimitiveType::Triangles: case EPrimitiveType::Triangles:
pIBO->TrianglesToStrips(Indices.data(), Indices.size()); pIBO->TrianglesToStrips(Indices.data(), Indices.size());
@ -91,7 +92,7 @@ void CModel::BufferGL()
} }
} }
for (uint32 iIBO = 0; iIBO < mSurfaceIndexBuffers[iSurf].size(); iIBO++) for (size_t iIBO = 0; iIBO < mSurfaceIndexBuffers[iSurf].size(); iIBO++)
mSurfaceIndexBuffers[iSurf][iIBO].Buffer(); mSurfaceIndexBuffers[iSurf][iIBO].Buffer();
} }
@ -101,14 +102,12 @@ void CModel::BufferGL()
void CModel::GenerateMaterialShaders() void CModel::GenerateMaterialShaders()
{ {
for (uint32 iSet = 0; iSet < mMaterialSets.size(); iSet++) for (CMaterialSet* set : mMaterialSets)
{ {
CMaterialSet *pSet = mMaterialSets[iSet]; for (size_t i = 0; i < set->NumMaterials(); i++)
for (uint32 iMat = 0; iMat < pSet->NumMaterials(); iMat++)
{ {
pSet->MaterialByIndex(iMat, false)->GenerateShader(false); set->MaterialByIndex(i, false)->GenerateShader(false);
pSet->MaterialByIndex(iMat, true)->GenerateShader(false); set->MaterialByIndex(i, true)->GenerateShader(false);
} }
} }
} }
@ -120,16 +119,19 @@ void CModel::ClearGLBuffer()
mBuffered = false; mBuffered = false;
} }
void CModel::Draw(FRenderOptions Options, uint32 MatSet) void CModel::Draw(FRenderOptions Options, size_t MatSet)
{ {
if (!mBuffered) BufferGL(); if (!mBuffered)
for (uint32 iSurf = 0; iSurf < mSurfaces.size(); iSurf++) BufferGL();
for (size_t iSurf = 0; iSurf < mSurfaces.size(); iSurf++)
DrawSurface(Options, iSurf, MatSet); DrawSurface(Options, iSurf, MatSet);
} }
void CModel::DrawSurface(FRenderOptions Options, uint32 Surface, uint32 MatSet) void CModel::DrawSurface(FRenderOptions Options, size_t Surface, size_t MatSet)
{ {
if (!mBuffered) BufferGL(); if (!mBuffered)
BufferGL();
// Check that mat set index is valid // Check that mat set index is valid
if (MatSet >= mMaterialSets.size()) if (MatSet >= mMaterialSets.size())
@ -141,7 +143,7 @@ void CModel::DrawSurface(FRenderOptions Options, uint32 Surface, uint32 MatSet)
mVBO.Bind(); mVBO.Bind();
glLineWidth(1.f); glLineWidth(1.f);
for (uint32 iIBO = 0; iIBO < mSurfaceIndexBuffers[Surface].size(); iIBO++) for (size_t iIBO = 0; iIBO < mSurfaceIndexBuffers[Surface].size(); iIBO++)
{ {
CIndexBuffer *pIBO = &mSurfaceIndexBuffers[Surface][iIBO]; CIndexBuffer *pIBO = &mSurfaceIndexBuffers[Surface][iIBO];
pIBO->DrawElements(); pIBO->DrawElements();
@ -153,7 +155,7 @@ void CModel::DrawSurface(FRenderOptions Options, uint32 Surface, uint32 MatSet)
// Bind material // Bind material
if ((Options & ERenderOption::NoMaterialSetup) == 0) if ((Options & ERenderOption::NoMaterialSetup) == 0)
{ {
SSurface *pSurf = mSurfaces[Surface]; const SSurface *pSurf = mSurfaces[Surface];
CMaterial *pMat = mMaterialSets[MatSet]->MaterialByIndex(pSurf->MaterialID, Options.HasFlag(ERenderOption::EnableBloom)); CMaterial *pMat = mMaterialSets[MatSet]->MaterialByIndex(pSurf->MaterialID, Options.HasFlag(ERenderOption::EnableBloom));
if (!Options.HasFlag(ERenderOption::EnableOccluders) && pMat->Options().HasFlag(EMaterialOption::Occluder)) if (!Options.HasFlag(ERenderOption::EnableOccluders) && pMat->Options().HasFlag(EMaterialOption::Occluder))
@ -171,9 +173,10 @@ void CModel::DrawSurface(FRenderOptions Options, uint32 Surface, uint32 MatSet)
} }
} }
void CModel::DrawWireframe(FRenderOptions Options, CColor WireColor /*= CColor::skWhite*/) void CModel::DrawWireframe(FRenderOptions Options, CColor WireColor)
{ {
if (!mBuffered) BufferGL(); if (!mBuffered)
BufferGL();
// Set up wireframe // Set up wireframe
WireColor.A = 0; WireColor.A = 0;
@ -183,7 +186,7 @@ void CModel::DrawWireframe(FRenderOptions Options, CColor WireColor /*= CColor::
glBlendFunc(GL_ONE, GL_ZERO); glBlendFunc(GL_ONE, GL_ZERO);
// Draw surfaces // Draw surfaces
for (uint32 iSurf = 0; iSurf < mSurfaces.size(); iSurf++) for (size_t iSurf = 0; iSurf < mSurfaces.size(); iSurf++)
DrawSurface(Options, iSurf, 0); DrawSurface(Options, iSurf, 0);
// Cleanup // Cleanup
@ -210,15 +213,13 @@ void CModel::SetSkin(CSkin *pSkin)
else if (!pSkin && mVBO.VertexDesc().HasAnyFlags(kBoneFlags)) else if (!pSkin && mVBO.VertexDesc().HasAnyFlags(kBoneFlags))
mVBO.SetVertexDesc(mVBO.VertexDesc() & ~kBoneFlags); mVBO.SetVertexDesc(mVBO.VertexDesc() & ~kBoneFlags);
for (uint32 iSet = 0; iSet < mMaterialSets.size(); iSet++) for (CMaterialSet* set : mMaterialSets)
{ {
CMaterialSet *pSet = mMaterialSets[iSet]; for (size_t iMat = 0; iMat < set->NumMaterials(); iMat++)
for (uint32 iMat = 0; iMat < pSet->NumMaterials(); iMat++)
{ {
for (bool iBloom = false; !iBloom; iBloom = true) for (bool iBloom = false; !iBloom; iBloom = true)
{ {
CMaterial *pMat = pSet->MaterialByIndex(iMat, iBloom); CMaterial *pMat = set->MaterialByIndex(iMat, iBloom);
FVertexDescription VtxDesc = pMat->VtxDesc(); FVertexDescription VtxDesc = pMat->VtxDesc();
if (pSkin && !VtxDesc.HasAllFlags(kBoneFlags)) if (pSkin && !VtxDesc.HasAllFlags(kBoneFlags))
@ -238,23 +239,25 @@ void CModel::SetSkin(CSkin *pSkin)
} }
} }
uint32 CModel::GetMatSetCount() size_t CModel::GetMatSetCount() const
{ {
return mMaterialSets.size(); return mMaterialSets.size();
} }
uint32 CModel::GetMatCount() size_t CModel::GetMatCount() const
{ {
if (mMaterialSets.empty()) return 0; if (mMaterialSets.empty())
else return mMaterialSets[0]->NumMaterials(); return 0;
return mMaterialSets[0]->NumMaterials();
} }
CMaterialSet* CModel::GetMatSet(uint32 MatSet) CMaterialSet* CModel::GetMatSet(size_t MatSet)
{ {
return mMaterialSets[MatSet]; return mMaterialSets[MatSet];
} }
CMaterial* CModel::GetMaterialByIndex(uint32 MatSet, uint32 Index) CMaterial* CModel::GetMaterialByIndex(size_t MatSet, size_t Index)
{ {
if (MatSet >= mMaterialSets.size()) if (MatSet >= mMaterialSets.size())
MatSet = mMaterialSets.size() - 1; MatSet = mMaterialSets.size() - 1;
@ -265,40 +268,41 @@ CMaterial* CModel::GetMaterialByIndex(uint32 MatSet, uint32 Index)
return mMaterialSets[MatSet]->MaterialByIndex(Index, false); return mMaterialSets[MatSet]->MaterialByIndex(Index, false);
} }
CMaterial* CModel::GetMaterialBySurface(uint32 MatSet, uint32 Surface) CMaterial* CModel::GetMaterialBySurface(size_t MatSet, size_t Surface)
{ {
return GetMaterialByIndex(MatSet, mSurfaces[Surface]->MaterialID); return GetMaterialByIndex(MatSet, mSurfaces[Surface]->MaterialID);
} }
bool CModel::HasTransparency(uint32 MatSet) bool CModel::HasTransparency(size_t MatSet)
{ {
if (MatSet >= mMaterialSets.size()) if (MatSet >= mMaterialSets.size())
MatSet = mMaterialSets.size() - 1; MatSet = mMaterialSets.size() - 1;
for (uint32 iMat = 0; iMat < mMaterialSets[MatSet]->NumMaterials(); iMat++) for (size_t iMat = 0; iMat < mMaterialSets[MatSet]->NumMaterials(); iMat++)
if (mMaterialSets[MatSet]->MaterialByIndex(iMat, true)->Options() & EMaterialOption::Transparent ) return true; {
if (mMaterialSets[MatSet]->MaterialByIndex(iMat, true)->Options() & EMaterialOption::Transparent)
return true;
}
return false; return false;
} }
bool CModel::IsSurfaceTransparent(uint32 Surface, uint32 MatSet) bool CModel::IsSurfaceTransparent(size_t Surface, size_t MatSet)
{ {
if (MatSet >= mMaterialSets.size()) if (MatSet >= mMaterialSets.size())
MatSet = mMaterialSets.size() - 1; MatSet = mMaterialSets.size() - 1;
uint32 matID = mSurfaces[Surface]->MaterialID; const uint32 matID = mSurfaces[Surface]->MaterialID;
return (mMaterialSets[MatSet]->MaterialByIndex(matID, true)->Options() & EMaterialOption::Transparent) != 0; return (mMaterialSets[MatSet]->MaterialByIndex(matID, true)->Options() & EMaterialOption::Transparent) != 0;
} }
bool CModel::IsLightmapped() const bool CModel::IsLightmapped() const
{ {
for (uint32 iSet = 0; iSet < mMaterialSets.size(); iSet++) for (CMaterialSet* set : mMaterialSets)
{ {
CMaterialSet *pSet = mMaterialSets[iSet]; for (size_t iMat = 0; iMat < set->NumMaterials(); iMat++)
for (uint32 iMat = 0; iMat < pSet->NumMaterials(); iMat++)
{ {
CMaterial *pMat = pSet->MaterialByIndex(iMat, true); const CMaterial *pMat = set->MaterialByIndex(iMat, true);
if (pMat->Options().HasFlag(EMaterialOption::Lightmap)) if (pMat->Options().HasFlag(EMaterialOption::Lightmap))
return true; return true;
} }
@ -306,17 +310,17 @@ bool CModel::IsLightmapped() const
return false; return false;
} }
CIndexBuffer* CModel::InternalGetIBO(uint32 Surface, EPrimitiveType Primitive) CIndexBuffer* CModel::InternalGetIBO(size_t Surface, EPrimitiveType Primitive)
{ {
std::vector<CIndexBuffer> *pIBOs = &mSurfaceIndexBuffers[Surface]; std::vector<CIndexBuffer>& pIBOs = mSurfaceIndexBuffers[Surface];
GLenum Type = GXPrimToGLPrim(Primitive); const GLenum Type = GXPrimToGLPrim(Primitive);
for (uint32 iIBO = 0; iIBO < pIBOs->size(); iIBO++) for (size_t iIBO = 0; iIBO < pIBOs.size(); iIBO++)
{ {
if ((*pIBOs)[iIBO].GetPrimitiveType() == Type) if (pIBOs[iIBO].GetPrimitiveType() == Type)
return &(*pIBOs)[iIBO]; return &pIBOs[iIBO];
} }
pIBOs->emplace_back(CIndexBuffer(Type)); pIBOs.emplace_back(CIndexBuffer(Type));
return &pIBOs->back(); return &pIBOs.back();
} }

View File

@ -29,24 +29,24 @@ public:
void BufferGL(); void BufferGL();
void GenerateMaterialShaders(); void GenerateMaterialShaders();
void ClearGLBuffer() override; void ClearGLBuffer() override;
void Draw(FRenderOptions Options, uint32 MatSet); void Draw(FRenderOptions Options, size_t MatSet);
void DrawSurface(FRenderOptions Options, uint32 Surface, uint32 MatSet); void DrawSurface(FRenderOptions Options, size_t Surface, size_t MatSet);
void DrawWireframe(FRenderOptions Options, CColor WireColor = CColor::skWhite); void DrawWireframe(FRenderOptions Options, CColor WireColor = CColor::skWhite);
void SetSkin(CSkin *pSkin); void SetSkin(CSkin *pSkin);
uint32 GetMatSetCount(); size_t GetMatSetCount() const;
uint32 GetMatCount(); size_t GetMatCount() const;
CMaterialSet* GetMatSet(uint32 MatSet); CMaterialSet* GetMatSet(size_t MatSet);
CMaterial* GetMaterialByIndex(uint32 MatSet, uint32 Index); CMaterial* GetMaterialByIndex(size_t MatSet, size_t Index);
CMaterial* GetMaterialBySurface(uint32 MatSet, uint32 Surface); CMaterial* GetMaterialBySurface(size_t MatSet, size_t Surface);
bool HasTransparency(uint32 MatSet); bool HasTransparency(size_t MatSet);
bool IsSurfaceTransparent(uint32 Surface, uint32 MatSet); bool IsSurfaceTransparent(size_t Surface, size_t MatSet);
bool IsLightmapped() const; bool IsLightmapped() const;
bool IsSkinned() const { return (mpSkin != nullptr); } bool IsSkinned() const { return mpSkin != nullptr; }
private: private:
CIndexBuffer* InternalGetIBO(uint32 Surface, EPrimitiveType Primitive); CIndexBuffer* InternalGetIBO(size_t Surface, EPrimitiveType Primitive);
}; };
#endif // MODEL_H #endif // MODEL_H

View File

@ -57,8 +57,11 @@ void CModelNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo
void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, ERenderCommand Command, const SViewInfo& rkViewInfo) void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, ERenderCommand Command, const SViewInfo& rkViewInfo)
{ {
if (!mpModel) return; if (!mpModel)
if (mForceAlphaOn) Options = (FRenderOptions) (Options & ~ERenderOption::NoAlpha); return;
if (mForceAlphaOn)
Options = static_cast<FRenderOptions>(Options & ~ERenderOption::NoAlpha);
if (!mWorldModel) if (!mWorldModel)
{ {
@ -71,7 +74,7 @@ void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, ERenderCommand
} }
else else
{ {
bool IsLightingEnabled = CGraphics::sLightMode == CGraphics::ELightingMode::World || rkViewInfo.GameMode; const bool IsLightingEnabled = CGraphics::sLightMode == CGraphics::ELightingMode::World || rkViewInfo.GameMode;
if (IsLightingEnabled) if (IsLightingEnabled)
{ {
@ -80,7 +83,6 @@ void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, ERenderCommand
CGraphics::sPixelBlock.LightmapMultiplier = 1.f; CGraphics::sPixelBlock.LightmapMultiplier = 1.f;
CGraphics::UpdateLightBlock(); CGraphics::UpdateLightBlock();
} }
else else
{ {
LoadLights(rkViewInfo); LoadLights(rkViewInfo);
@ -90,7 +92,7 @@ void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, ERenderCommand
CGraphics::sVertexBlock.COLOR0_Mat = CColor::skTransparentWhite; CGraphics::sVertexBlock.COLOR0_Mat = CColor::skTransparentWhite;
float Mul = CGraphics::sWorldLightMultiplier; const float Mul = CGraphics::sWorldLightMultiplier;
CGraphics::sPixelBlock.SetAllTevColors(CColor(Mul,Mul,Mul)); CGraphics::sPixelBlock.SetAllTevColors(CColor(Mul,Mul,Mul));
} }

View File

@ -203,13 +203,14 @@ void CSceneNode::LoadLights(const SViewInfo& rkViewInfo)
CGraphics::UpdateLightBlock(); CGraphics::UpdateLightBlock();
} }
void CSceneNode::AddModelToRenderer(CRenderer *pRenderer, CModel *pModel, uint32 MatSet) void CSceneNode::AddModelToRenderer(CRenderer *pRenderer, CModel *pModel, size_t MatSet)
{ {
ASSERT(pModel); ASSERT(pModel);
if (!pModel->HasTransparency(MatSet)) if (!pModel->HasTransparency(MatSet))
{
pRenderer->AddMesh(this, -1, AABox(), false, ERenderCommand::DrawMesh); pRenderer->AddMesh(this, -1, AABox(), false, ERenderCommand::DrawMesh);
}
else else
{ {
pRenderer->AddMesh(this, -1, AABox(), false, ERenderCommand::DrawOpaqueParts); pRenderer->AddMesh(this, -1, AABox(), false, ERenderCommand::DrawOpaqueParts);
@ -217,22 +218,23 @@ void CSceneNode::AddModelToRenderer(CRenderer *pRenderer, CModel *pModel, uint32
} }
} }
void CSceneNode::DrawModelParts(CModel *pModel, FRenderOptions Options, uint32 MatSet, ERenderCommand RenderCommand) void CSceneNode::DrawModelParts(CModel *pModel, FRenderOptions Options, size_t MatSet, ERenderCommand RenderCommand)
{ {
// Common rendering functionality // Common rendering functionality
if (RenderCommand == ERenderCommand::DrawMesh) if (RenderCommand == ERenderCommand::DrawMesh)
{
pModel->Draw(Options, MatSet); pModel->Draw(Options, MatSet);
}
else else
{ {
bool DrawOpaque = (RenderCommand == ERenderCommand::DrawMesh || RenderCommand == ERenderCommand::DrawOpaqueParts); const bool DrawOpaque = (RenderCommand == ERenderCommand::DrawMesh || RenderCommand == ERenderCommand::DrawOpaqueParts);
bool DrawTransparent = (RenderCommand == ERenderCommand::DrawMesh || RenderCommand == ERenderCommand::DrawTransparentParts); const bool DrawTransparent = (RenderCommand == ERenderCommand::DrawMesh || RenderCommand == ERenderCommand::DrawTransparentParts);
for (uint32 iSurf = 0; iSurf < pModel->GetSurfaceCount(); iSurf++) for (size_t iSurf = 0; iSurf < pModel->GetSurfaceCount(); iSurf++)
{ {
bool ShouldRender = ( (DrawOpaque && DrawTransparent) || const bool ShouldRender = (DrawOpaque && DrawTransparent) ||
(DrawOpaque && !pModel->IsSurfaceTransparent(iSurf, MatSet)) || (DrawOpaque && !pModel->IsSurfaceTransparent(iSurf, MatSet)) ||
(DrawTransparent && pModel->IsSurfaceTransparent(iSurf, MatSet)) ); (DrawTransparent && pModel->IsSurfaceTransparent(iSurf, MatSet));
if (ShouldRender) if (ShouldRender)
pModel->DrawSurface(Options, iSurf, MatSet); pModel->DrawSurface(Options, iSurf, MatSet);

View File

@ -128,8 +128,8 @@ public:
void LoadModelMatrix(); void LoadModelMatrix();
void BuildLightList(CGameArea *pArea); void BuildLightList(CGameArea *pArea);
void LoadLights(const SViewInfo& rkViewInfo); void LoadLights(const SViewInfo& rkViewInfo);
void AddModelToRenderer(CRenderer *pRenderer, CModel *pModel, uint32 MatSet); void AddModelToRenderer(CRenderer *pRenderer, CModel *pModel, size_t MatSet);
void DrawModelParts(CModel *pModel, FRenderOptions Options, uint32 MatSet, ERenderCommand RenderCommand); void DrawModelParts(CModel *pModel, FRenderOptions Options, size_t MatSet, ERenderCommand RenderCommand);
void DrawBoundingBox() const; void DrawBoundingBox() const;
void DrawRotationArrow() const; void DrawRotationArrow() const;

View File

@ -53,9 +53,9 @@ void CGizmo::AddToRenderer(CRenderer *pRenderer, const SViewInfo&)
CModel *pModel = pPart->pModel; CModel *pModel = pPart->pModel;
// Determine whether to use the mat set for regular (0) or highlight (1) // Determine whether to use the mat set for regular (0) or highlight (1)
FAxes PartAxes = pPart->ModelAxes; const FAxes PartAxes = pPart->ModelAxes;
bool IsHighlighted = (PartAxes != EAxis::None) && ((mSelectedAxes & PartAxes) == pPart->ModelAxes); const bool IsHighlighted = (PartAxes != EAxis::None) && ((mSelectedAxes & PartAxes) == pPart->ModelAxes);
uint32 SetID = (IsHighlighted ? 1 : 0); const size_t SetID = (IsHighlighted ? 1 : 0);
// Add to renderer... // Add to renderer...
pRenderer->AddMesh(this, iPart, pModel->AABox().Transformed(mTransform), pModel->HasTransparency(SetID), ERenderCommand::DrawMesh, EDepthGroup::Foreground); pRenderer->AddMesh(this, iPart, pModel->AABox().Transformed(mTransform), pModel->HasTransparency(SetID), ERenderCommand::DrawMesh, EDepthGroup::Foreground);

View File

@ -195,9 +195,9 @@ void CModelEditorWindow::SetActiveModel(CModel *pModel)
ui->MatSelectionComboBox->blockSignals(true); ui->MatSelectionComboBox->blockSignals(true);
ui->MatSelectionComboBox->clear(); ui->MatSelectionComboBox->clear();
for (uint32 iMat = 0; iMat < NumMats; iMat++) for (size_t iMat = 0; iMat < NumMats; iMat++)
{ {
TString MatName = pModel->GetMaterialByIndex(0, iMat)->Name(); const TString MatName = pModel->GetMaterialByIndex(0, iMat)->Name();
ui->MatSelectionComboBox->addItem(TO_QSTRING(MatName)); ui->MatSelectionComboBox->addItem(TO_QSTRING(MatName));
} }
@ -215,12 +215,14 @@ void CModelEditorWindow::SetActiveModel(CModel *pModel)
void CModelEditorWindow::SetActiveMaterial(int MatIndex) void CModelEditorWindow::SetActiveMaterial(int MatIndex)
{ {
if (!mpCurrentModel) return; if (!mpCurrentModel)
return;
uint32 SetIndex = ui->SetSelectionComboBox->currentIndex(); const auto SetIndex = static_cast<uint32>(ui->SetSelectionComboBox->currentIndex());
mpCurrentMat = mpCurrentModel->GetMaterialByIndex(SetIndex, MatIndex); mpCurrentMat = mpCurrentModel->GetMaterialByIndex(SetIndex, MatIndex);
ui->Viewport->SetActiveMaterial(mpCurrentMat); ui->Viewport->SetActiveMaterial(mpCurrentMat);
if (!mpCurrentMat) return; if (!mpCurrentMat)
return;
// Set up UI // Set up UI
FMaterialOptions Settings = mpCurrentMat->Options(); FMaterialOptions Settings = mpCurrentMat->Options();