From 79f7b629606c7f1de9881d2b7ea0d5f7a752ec75 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 15 Jun 2020 14:24:39 -0400 Subject: [PATCH] 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. --- src/Core/GameProject/AssetNameGeneration.cpp | 31 ++--- src/Core/Resource/CMaterialSet.h | 40 +++--- src/Core/Resource/Cooker/CModelCooker.cpp | 23 ++-- src/Core/Resource/Model/CModel.cpp | 122 +++++++++--------- src/Core/Resource/Model/CModel.h | 22 ++-- src/Core/Scene/CModelNode.cpp | 12 +- src/Core/Scene/CSceneNode.cpp | 22 ++-- src/Core/Scene/CSceneNode.h | 4 +- src/Editor/CGizmo.cpp | 6 +- src/Editor/ModelEditor/CModelEditorWindow.cpp | 12 +- 10 files changed, 158 insertions(+), 136 deletions(-) diff --git a/src/Core/GameProject/AssetNameGeneration.cpp b/src/Core/GameProject/AssetNameGeneration.cpp index ee724035..efebbdbc 100644 --- a/src/Core/GameProject/AssetNameGeneration.cpp +++ b/src/Core/GameProject/AssetNameGeneration.cpp @@ -166,17 +166,17 @@ void GenerateAssetNames(CGameProject *pProj) ApplyGeneratedName(pSkyEntry, WorldDir + "sky/cooked/", WorldName + "_sky"); // 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); - 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()) ApplyGeneratedName(pPass->Texture()->Entry(), WorldDir + "sky/sourceimages/", pPass->Texture()->Entry()->Name()); @@ -237,12 +237,12 @@ void GenerateAssetNames(CGameProject *pProj) uint32 LightmapNum = 0; 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); 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); @@ -407,30 +407,31 @@ void GenerateAssetNames(CGameProject *pProj) for (TResourceIterator It(pStore); It; ++It) { 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); - for (uint32 iMat = 0; iMat < pSet->NumMaterials(); iMat++) + for (size_t iMat = 0; iMat < pSet->NumMaterials(); iMat++) { 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); - bool IsLightmap = ( (pMat->Version() <= EGame::Echoes && pMat->Options().HasFlag(EMaterialOption::Lightmap) && iPass == 0) || - (pMat->Version() >= EGame::CorruptionProto && pPass->Type() == "DIFF") ); + const bool IsLightmap = (pMat->Version() <= EGame::Echoes && pMat->Options().HasFlag(EMaterialOption::Lightmap) && iPass == 0) || + (pMat->Version() >= EGame::CorruptionProto && pPass->Type() == "DIFF"); if (IsLightmap) { CTexture *pLightmapTex = pPass->Texture(); 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); pTexEntry->SetHidden(true); LightmapNum++; diff --git a/src/Core/Resource/CMaterialSet.h b/src/Core/Resource/CMaterialSet.h index fdeac3fa..4b68676e 100644 --- a/src/Core/Resource/CMaterialSet.h +++ b/src/Core/Resource/CMaterialSet.h @@ -22,53 +22,63 @@ public: auto pOut = std::make_unique(); pOut->mMaterials.resize(mMaterials.size()); - for (uint32 iMat = 0; iMat < mMaterials.size(); iMat++) - pOut->mMaterials[iMat] = mMaterials[iMat]->Clone(); + for (size_t i = 0; i < mMaterials.size(); i++) + pOut->mMaterials[i] = mMaterials[i]->Clone(); return pOut; } - uint32 NumMaterials() const + size_t NumMaterials() const { 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(); if (TryBloom && Ret->GetBloomVersion()) return Ret->GetBloomVersion(); + return Ret; } CMaterial* MaterialByName(const TString& rkName) { 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; } uint32 MaterialIndexByName(const TString& rkName) { - for (uint32 iMat = 0; iMat < mMaterials.size(); iMat++) - if (mMaterials[iMat]->Name() == rkName) return iMat; + for (uint32 i = 0; i < mMaterials.size(); i++) + { + if (mMaterials[i]->Name() == rkName) + return i; + } - return -1; + return UINT32_MAX; } void GetUsedTextureIDs(std::set& rOut) { - for (uint32 iMat = 0; iMat < mMaterials.size(); iMat++) + for (const auto& material : mMaterials) { - CMaterial *pMat = mMaterials[iMat].get(); - if (pMat->IndTexture()) rOut.insert(pMat->IndTexture()->ID()); + if (material->IndTexture()) + 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(); - if (pTex) rOut.insert(pTex->ID()); + const CTexture *pTex = material->Pass(i)->Texture(); + if (pTex) + rOut.insert(pTex->ID()); } } } diff --git a/src/Core/Resource/Cooker/CModelCooker.cpp b/src/Core/Resource/Cooker/CModelCooker.cpp index 6ccbc557..eec583ca 100644 --- a/src/Core/Resource/Cooker/CModelCooker.cpp +++ b/src/Core/Resource/Cooker/CModelCooker.cpp @@ -20,30 +20,31 @@ void CModelCooker::GenerateSurfaceData() // Get vertex attributes 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); mVtxAttribs |= pMat->VtxDesc(); } // 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]; - uint32 NumVerts = pPrim->Vertices.size(); + const SSurface::SPrimitive *pPrim = &mpModel->mSurfaces[iSurf]->Primitives[iPrim]; + 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]; - if (VertIndex > MaxIndex) MaxIndex = VertIndex; + if (VertIndex > MaxIndex) + MaxIndex = VertIndex; } } } @@ -142,7 +143,7 @@ void CModelCooker::WriteModelPrime(IOutputStream& rOut) uint32 SurfacesStart = rOut.Tell(); std::vector SurfaceEndOffsets(mNumSurfaces); - for (uint32 iSurf = 0; iSurf < mNumSurfaces; iSurf++) + for (size_t iSurf = 0; iSurf < mNumSurfaces; iSurf++) { SSurface *pSurface = mpModel->GetSurface(iSurf); diff --git a/src/Core/Resource/Model/CModel.cpp b/src/Core/Resource/Model/CModel.cpp index 500a9187..e10e618a 100644 --- a/src/Core/Resource/Model/CModel.cpp +++ b/src/Core/Resource/Model/CModel.cpp @@ -24,9 +24,11 @@ CModel::CModel(CMaterialSet *pSet, bool OwnsMatSet) CModel::~CModel() { - if (mHasOwnMaterials) - for (uint32 iMat = 0; iMat < mMaterialSets.size(); iMat++) - delete mMaterialSets[iMat]; + if (!mHasOwnMaterials) + return; + + for (size_t iMat = 0; iMat < mMaterialSets.size(); iMat++) + delete mMaterialSets[iMat]; } @@ -55,25 +57,24 @@ void CModel::BufferGL() 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]; uint16 VBOStartOffset = (uint16) mVBO.Size(); 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); - pIBO->Reserve(pPrim->Vertices.size() + 1); // Allocate enough space for this primitive, plus the restart index + CIndexBuffer *pIBO = InternalGetIBO(iSurf, pPrim.Type); + pIBO->Reserve(pPrim.Vertices.size() + 1); // Allocate enough space for this primitive, plus the restart index - std::vector Indices(pPrim->Vertices.size()); - for (uint32 iVert = 0; iVert < pPrim->Vertices.size(); iVert++) - Indices[iVert] = mVBO.AddIfUnique(pPrim->Vertices[iVert], VBOStartOffset); + std::vector Indices(pPrim.Vertices.size()); + for (size_t iVert = 0; iVert < pPrim.Vertices.size(); iVert++) + 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. - switch (pPrim->Type) + switch (pPrim.Type) { case EPrimitiveType::Triangles: 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(); } @@ -101,14 +102,12 @@ void CModel::BufferGL() void CModel::GenerateMaterialShaders() { - for (uint32 iSet = 0; iSet < mMaterialSets.size(); iSet++) + for (CMaterialSet* set : mMaterialSets) { - CMaterialSet *pSet = mMaterialSets[iSet]; - - for (uint32 iMat = 0; iMat < pSet->NumMaterials(); iMat++) + for (size_t i = 0; i < set->NumMaterials(); i++) { - pSet->MaterialByIndex(iMat, false)->GenerateShader(false); - pSet->MaterialByIndex(iMat, true)->GenerateShader(false); + set->MaterialByIndex(i, false)->GenerateShader(false); + set->MaterialByIndex(i, true)->GenerateShader(false); } } } @@ -120,16 +119,19 @@ void CModel::ClearGLBuffer() mBuffered = false; } -void CModel::Draw(FRenderOptions Options, uint32 MatSet) +void CModel::Draw(FRenderOptions Options, size_t MatSet) { - if (!mBuffered) BufferGL(); - for (uint32 iSurf = 0; iSurf < mSurfaces.size(); iSurf++) + if (!mBuffered) + BufferGL(); + + for (size_t iSurf = 0; iSurf < mSurfaces.size(); iSurf++) 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 if (MatSet >= mMaterialSets.size()) @@ -141,7 +143,7 @@ void CModel::DrawSurface(FRenderOptions Options, uint32 Surface, uint32 MatSet) mVBO.Bind(); 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]; pIBO->DrawElements(); @@ -153,7 +155,7 @@ void CModel::DrawSurface(FRenderOptions Options, uint32 Surface, uint32 MatSet) // Bind material 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)); 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 WireColor.A = 0; @@ -183,7 +186,7 @@ void CModel::DrawWireframe(FRenderOptions Options, CColor WireColor /*= CColor:: glBlendFunc(GL_ONE, GL_ZERO); // Draw surfaces - for (uint32 iSurf = 0; iSurf < mSurfaces.size(); iSurf++) + for (size_t iSurf = 0; iSurf < mSurfaces.size(); iSurf++) DrawSurface(Options, iSurf, 0); // Cleanup @@ -210,15 +213,13 @@ void CModel::SetSkin(CSkin *pSkin) else if (!pSkin && mVBO.VertexDesc().HasAnyFlags(kBoneFlags)) mVBO.SetVertexDesc(mVBO.VertexDesc() & ~kBoneFlags); - for (uint32 iSet = 0; iSet < mMaterialSets.size(); iSet++) + for (CMaterialSet* set : mMaterialSets) { - CMaterialSet *pSet = mMaterialSets[iSet]; - - for (uint32 iMat = 0; iMat < pSet->NumMaterials(); iMat++) + for (size_t iMat = 0; iMat < set->NumMaterials(); iMat++) { for (bool iBloom = false; !iBloom; iBloom = true) { - CMaterial *pMat = pSet->MaterialByIndex(iMat, iBloom); + CMaterial *pMat = set->MaterialByIndex(iMat, iBloom); FVertexDescription VtxDesc = pMat->VtxDesc(); 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(); } -uint32 CModel::GetMatCount() +size_t CModel::GetMatCount() const { - if (mMaterialSets.empty()) return 0; - else return mMaterialSets[0]->NumMaterials(); + if (mMaterialSets.empty()) + return 0; + + return mMaterialSets[0]->NumMaterials(); } -CMaterialSet* CModel::GetMatSet(uint32 MatSet) +CMaterialSet* CModel::GetMatSet(size_t MatSet) { return mMaterialSets[MatSet]; } -CMaterial* CModel::GetMaterialByIndex(uint32 MatSet, uint32 Index) +CMaterial* CModel::GetMaterialByIndex(size_t MatSet, size_t Index) { if (MatSet >= mMaterialSets.size()) MatSet = mMaterialSets.size() - 1; @@ -265,40 +268,41 @@ CMaterial* CModel::GetMaterialByIndex(uint32 MatSet, uint32 Index) 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); } -bool CModel::HasTransparency(uint32 MatSet) +bool CModel::HasTransparency(size_t MatSet) { if (MatSet >= mMaterialSets.size()) MatSet = mMaterialSets.size() - 1; - for (uint32 iMat = 0; iMat < mMaterialSets[MatSet]->NumMaterials(); iMat++) - if (mMaterialSets[MatSet]->MaterialByIndex(iMat, true)->Options() & EMaterialOption::Transparent ) return true; + for (size_t iMat = 0; iMat < mMaterialSets[MatSet]->NumMaterials(); iMat++) + { + if (mMaterialSets[MatSet]->MaterialByIndex(iMat, true)->Options() & EMaterialOption::Transparent) + return true; + } return false; } -bool CModel::IsSurfaceTransparent(uint32 Surface, uint32 MatSet) +bool CModel::IsSurfaceTransparent(size_t Surface, size_t MatSet) { if (MatSet >= mMaterialSets.size()) 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; } bool CModel::IsLightmapped() const { - for (uint32 iSet = 0; iSet < mMaterialSets.size(); iSet++) + for (CMaterialSet* set : mMaterialSets) { - CMaterialSet *pSet = mMaterialSets[iSet]; - - for (uint32 iMat = 0; iMat < pSet->NumMaterials(); iMat++) + for (size_t iMat = 0; iMat < set->NumMaterials(); iMat++) { - CMaterial *pMat = pSet->MaterialByIndex(iMat, true); + const CMaterial *pMat = set->MaterialByIndex(iMat, true); if (pMat->Options().HasFlag(EMaterialOption::Lightmap)) return true; } @@ -306,17 +310,17 @@ bool CModel::IsLightmapped() const return false; } -CIndexBuffer* CModel::InternalGetIBO(uint32 Surface, EPrimitiveType Primitive) +CIndexBuffer* CModel::InternalGetIBO(size_t Surface, EPrimitiveType Primitive) { - std::vector *pIBOs = &mSurfaceIndexBuffers[Surface]; - GLenum Type = GXPrimToGLPrim(Primitive); + std::vector& pIBOs = mSurfaceIndexBuffers[Surface]; + 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) - return &(*pIBOs)[iIBO]; + if (pIBOs[iIBO].GetPrimitiveType() == Type) + return &pIBOs[iIBO]; } - pIBOs->emplace_back(CIndexBuffer(Type)); - return &pIBOs->back(); + pIBOs.emplace_back(CIndexBuffer(Type)); + return &pIBOs.back(); } diff --git a/src/Core/Resource/Model/CModel.h b/src/Core/Resource/Model/CModel.h index d6fdd0fa..8849c12e 100644 --- a/src/Core/Resource/Model/CModel.h +++ b/src/Core/Resource/Model/CModel.h @@ -29,24 +29,24 @@ public: void BufferGL(); void GenerateMaterialShaders(); void ClearGLBuffer() override; - void Draw(FRenderOptions Options, uint32 MatSet); - void DrawSurface(FRenderOptions Options, uint32 Surface, uint32 MatSet); + void Draw(FRenderOptions Options, size_t MatSet); + void DrawSurface(FRenderOptions Options, size_t Surface, size_t MatSet); void DrawWireframe(FRenderOptions Options, CColor WireColor = CColor::skWhite); void SetSkin(CSkin *pSkin); - uint32 GetMatSetCount(); - uint32 GetMatCount(); - CMaterialSet* GetMatSet(uint32 MatSet); - CMaterial* GetMaterialByIndex(uint32 MatSet, uint32 Index); - CMaterial* GetMaterialBySurface(uint32 MatSet, uint32 Surface); - bool HasTransparency(uint32 MatSet); - bool IsSurfaceTransparent(uint32 Surface, uint32 MatSet); + size_t GetMatSetCount() const; + size_t GetMatCount() const; + CMaterialSet* GetMatSet(size_t MatSet); + CMaterial* GetMaterialByIndex(size_t MatSet, size_t Index); + CMaterial* GetMaterialBySurface(size_t MatSet, size_t Surface); + bool HasTransparency(size_t MatSet); + bool IsSurfaceTransparent(size_t Surface, size_t MatSet); bool IsLightmapped() const; - bool IsSkinned() const { return (mpSkin != nullptr); } + bool IsSkinned() const { return mpSkin != nullptr; } private: - CIndexBuffer* InternalGetIBO(uint32 Surface, EPrimitiveType Primitive); + CIndexBuffer* InternalGetIBO(size_t Surface, EPrimitiveType Primitive); }; #endif // MODEL_H diff --git a/src/Core/Scene/CModelNode.cpp b/src/Core/Scene/CModelNode.cpp index e8748d28..066f6551 100644 --- a/src/Core/Scene/CModelNode.cpp +++ b/src/Core/Scene/CModelNode.cpp @@ -57,8 +57,11 @@ void CModelNode::AddToRenderer(CRenderer *pRenderer, const SViewInfo& rkViewInfo void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, ERenderCommand Command, const SViewInfo& rkViewInfo) { - if (!mpModel) return; - if (mForceAlphaOn) Options = (FRenderOptions) (Options & ~ERenderOption::NoAlpha); + if (!mpModel) + return; + + if (mForceAlphaOn) + Options = static_cast(Options & ~ERenderOption::NoAlpha); if (!mWorldModel) { @@ -71,7 +74,7 @@ void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, ERenderCommand } else { - bool IsLightingEnabled = CGraphics::sLightMode == CGraphics::ELightingMode::World || rkViewInfo.GameMode; + const bool IsLightingEnabled = CGraphics::sLightMode == CGraphics::ELightingMode::World || rkViewInfo.GameMode; if (IsLightingEnabled) { @@ -80,7 +83,6 @@ void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, ERenderCommand CGraphics::sPixelBlock.LightmapMultiplier = 1.f; CGraphics::UpdateLightBlock(); } - else { LoadLights(rkViewInfo); @@ -90,7 +92,7 @@ void CModelNode::Draw(FRenderOptions Options, int ComponentIndex, ERenderCommand CGraphics::sVertexBlock.COLOR0_Mat = CColor::skTransparentWhite; - float Mul = CGraphics::sWorldLightMultiplier; + const float Mul = CGraphics::sWorldLightMultiplier; CGraphics::sPixelBlock.SetAllTevColors(CColor(Mul,Mul,Mul)); } diff --git a/src/Core/Scene/CSceneNode.cpp b/src/Core/Scene/CSceneNode.cpp index 132c8f8c..b3eb73d5 100644 --- a/src/Core/Scene/CSceneNode.cpp +++ b/src/Core/Scene/CSceneNode.cpp @@ -203,13 +203,14 @@ void CSceneNode::LoadLights(const SViewInfo& rkViewInfo) CGraphics::UpdateLightBlock(); } -void CSceneNode::AddModelToRenderer(CRenderer *pRenderer, CModel *pModel, uint32 MatSet) +void CSceneNode::AddModelToRenderer(CRenderer *pRenderer, CModel *pModel, size_t MatSet) { ASSERT(pModel); if (!pModel->HasTransparency(MatSet)) + { pRenderer->AddMesh(this, -1, AABox(), false, ERenderCommand::DrawMesh); - + } else { 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 if (RenderCommand == ERenderCommand::DrawMesh) + { pModel->Draw(Options, MatSet); - + } else { - bool DrawOpaque = (RenderCommand == ERenderCommand::DrawMesh || RenderCommand == ERenderCommand::DrawOpaqueParts); - bool DrawTransparent = (RenderCommand == ERenderCommand::DrawMesh || RenderCommand == ERenderCommand::DrawTransparentParts); + const bool DrawOpaque = (RenderCommand == ERenderCommand::DrawMesh || RenderCommand == ERenderCommand::DrawOpaqueParts); + 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) || - (DrawOpaque && !pModel->IsSurfaceTransparent(iSurf, MatSet)) || - (DrawTransparent && pModel->IsSurfaceTransparent(iSurf, MatSet)) ); + const bool ShouldRender = (DrawOpaque && DrawTransparent) || + (DrawOpaque && !pModel->IsSurfaceTransparent(iSurf, MatSet)) || + (DrawTransparent && pModel->IsSurfaceTransparent(iSurf, MatSet)); if (ShouldRender) pModel->DrawSurface(Options, iSurf, MatSet); diff --git a/src/Core/Scene/CSceneNode.h b/src/Core/Scene/CSceneNode.h index 4c0a6db1..dee8d63b 100644 --- a/src/Core/Scene/CSceneNode.h +++ b/src/Core/Scene/CSceneNode.h @@ -128,8 +128,8 @@ public: void LoadModelMatrix(); void BuildLightList(CGameArea *pArea); void LoadLights(const SViewInfo& rkViewInfo); - void AddModelToRenderer(CRenderer *pRenderer, CModel *pModel, uint32 MatSet); - void DrawModelParts(CModel *pModel, FRenderOptions Options, uint32 MatSet, ERenderCommand RenderCommand); + void AddModelToRenderer(CRenderer *pRenderer, CModel *pModel, size_t MatSet); + void DrawModelParts(CModel *pModel, FRenderOptions Options, size_t MatSet, ERenderCommand RenderCommand); void DrawBoundingBox() const; void DrawRotationArrow() const; diff --git a/src/Editor/CGizmo.cpp b/src/Editor/CGizmo.cpp index df198920..a017a2ff 100644 --- a/src/Editor/CGizmo.cpp +++ b/src/Editor/CGizmo.cpp @@ -53,9 +53,9 @@ void CGizmo::AddToRenderer(CRenderer *pRenderer, const SViewInfo&) CModel *pModel = pPart->pModel; // Determine whether to use the mat set for regular (0) or highlight (1) - FAxes PartAxes = pPart->ModelAxes; - bool IsHighlighted = (PartAxes != EAxis::None) && ((mSelectedAxes & PartAxes) == pPart->ModelAxes); - uint32 SetID = (IsHighlighted ? 1 : 0); + const FAxes PartAxes = pPart->ModelAxes; + const bool IsHighlighted = (PartAxes != EAxis::None) && ((mSelectedAxes & PartAxes) == pPart->ModelAxes); + const size_t SetID = (IsHighlighted ? 1 : 0); // Add to renderer... pRenderer->AddMesh(this, iPart, pModel->AABox().Transformed(mTransform), pModel->HasTransparency(SetID), ERenderCommand::DrawMesh, EDepthGroup::Foreground); diff --git a/src/Editor/ModelEditor/CModelEditorWindow.cpp b/src/Editor/ModelEditor/CModelEditorWindow.cpp index 3c9b77a1..ccff6bf1 100644 --- a/src/Editor/ModelEditor/CModelEditorWindow.cpp +++ b/src/Editor/ModelEditor/CModelEditorWindow.cpp @@ -195,9 +195,9 @@ void CModelEditorWindow::SetActiveModel(CModel *pModel) ui->MatSelectionComboBox->blockSignals(true); 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)); } @@ -215,12 +215,14 @@ void CModelEditorWindow::SetActiveModel(CModel *pModel) void CModelEditorWindow::SetActiveMaterial(int MatIndex) { - if (!mpCurrentModel) return; + if (!mpCurrentModel) + return; - uint32 SetIndex = ui->SetSelectionComboBox->currentIndex(); + const auto SetIndex = static_cast(ui->SetSelectionComboBox->currentIndex()); mpCurrentMat = mpCurrentModel->GetMaterialByIndex(SetIndex, MatIndex); ui->Viewport->SetActiveMaterial(mpCurrentMat); - if (!mpCurrentMat) return; + if (!mpCurrentMat) + return; // Set up UI FMaterialOptions Settings = mpCurrentMat->Options();