CStaticModel: Invert condition in BufferGL

This commit is contained in:
Lioncash 2020-06-22 02:24:40 -04:00
parent 6120e60b05
commit 12cd221c48
1 changed files with 45 additions and 45 deletions

View File

@ -28,62 +28,62 @@ void CStaticModel::AddSurface(SSurface *pSurface)
void CStaticModel::BufferGL() void CStaticModel::BufferGL()
{ {
if (!mBuffered) if (mBuffered)
return;
mVBO.Clear();
mIBOs.clear();
for (size_t iSurf = 0; iSurf < mSurfaces.size(); iSurf++)
{ {
mVBO.Clear(); SSurface *pSurf = mSurfaces[iSurf];
mIBOs.clear();
for (size_t iSurf = 0; iSurf < mSurfaces.size(); iSurf++) const auto VBOStartOffset = static_cast<uint16>(mVBO.Size());
mVBO.Reserve(static_cast<uint16>(pSurf->VertexCount));
for (const auto& pPrim : pSurf->Primitives)
{ {
SSurface *pSurf = mSurfaces[iSurf]; CIndexBuffer *pIBO = InternalGetIBO(pPrim.Type);
pIBO->Reserve(pPrim.Vertices.size() + 1); // Allocate enough space for this primitive, plus the restart index
const auto VBOStartOffset = static_cast<uint16>(mVBO.Size()); // Next step: add new vertices to the VBO and create a small index buffer for the current primitive
mVBO.Reserve(static_cast<uint16>(pSurf->VertexCount)); std::vector<uint16> Indices(pPrim.Vertices.size());
for (size_t iVert = 0; iVert < pPrim.Vertices.size(); iVert++)
Indices[iVert] = mVBO.AddIfUnique(pPrim.Vertices[iVert], VBOStartOffset);
for (const auto& pPrim : pSurf->Primitives) // then add the indices to the IBO. We convert some primitives to strips to minimize draw calls.
switch (pPrim.Type)
{ {
CIndexBuffer *pIBO = InternalGetIBO(pPrim.Type); case EPrimitiveType::Triangles:
pIBO->Reserve(pPrim.Vertices.size() + 1); // Allocate enough space for this primitive, plus the restart index pIBO->TrianglesToStrips(Indices.data(), Indices.size());
break;
// Next step: add new vertices to the VBO and create a small index buffer for the current primitive case EPrimitiveType::TriangleFan:
std::vector<uint16> Indices(pPrim.Vertices.size()); pIBO->FansToStrips(Indices.data(), Indices.size());
for (size_t iVert = 0; iVert < pPrim.Vertices.size(); iVert++) break;
Indices[iVert] = mVBO.AddIfUnique(pPrim.Vertices[iVert], VBOStartOffset); case EPrimitiveType::Quads:
pIBO->QuadsToStrips(Indices.data(), Indices.size());
// then add the indices to the IBO. We convert some primitives to strips to minimize draw calls. break;
switch (pPrim.Type) default:
{ pIBO->AddIndices(Indices.data(), Indices.size());
case EPrimitiveType::Triangles: pIBO->AddIndex(0xFFFF); // primitive restart
pIBO->TrianglesToStrips(Indices.data(), Indices.size()); break;
break;
case EPrimitiveType::TriangleFan:
pIBO->FansToStrips(Indices.data(), Indices.size());
break;
case EPrimitiveType::Quads:
pIBO->QuadsToStrips(Indices.data(), Indices.size());
break;
default:
pIBO->AddIndices(Indices.data(), Indices.size());
pIBO->AddIndex(0xFFFF); // primitive restart
break;
}
} }
// Make sure the number of submesh offset vectors matches the number of IBOs, then add the offsets
while (mIBOs.size() > mSurfaceEndOffsets.size())
mSurfaceEndOffsets.emplace_back(std::vector<uint32>(mSurfaces.size()));
for (size_t iIBO = 0; iIBO < mIBOs.size(); iIBO++)
mSurfaceEndOffsets[iIBO][iSurf] = mIBOs[iIBO].GetSize();
} }
mVBO.Buffer(); // Make sure the number of submesh offset vectors matches the number of IBOs, then add the offsets
while (mIBOs.size() > mSurfaceEndOffsets.size())
mSurfaceEndOffsets.emplace_back(std::vector<uint32>(mSurfaces.size()));
for (auto& ibo : mIBOs) for (size_t iIBO = 0; iIBO < mIBOs.size(); iIBO++)
ibo.Buffer(); mSurfaceEndOffsets[iIBO][iSurf] = mIBOs[iIBO].GetSize();
mBuffered = true;
} }
mVBO.Buffer();
for (auto& ibo : mIBOs)
ibo.Buffer();
mBuffered = true;
} }
void CStaticModel::GenerateMaterialShaders() void CStaticModel::GenerateMaterialShaders()