Fixes to avoid needless re-buffering in PostLoad + fix for a crash/memory leak when changing areas

This commit is contained in:
parax0 2016-02-10 18:49:56 -07:00
parent 7bd97f0fce
commit 3296948bea
4 changed files with 94 additions and 87 deletions

View File

@ -31,10 +31,12 @@ CModel::~CModel()
void CModel::BufferGL() void CModel::BufferGL()
{ {
if (!mBuffered)
{
mVBO.Clear(); mVBO.Clear();
mSubmeshIndexBuffers.clear(); mSurfaceIndexBuffers.clear();
mSubmeshIndexBuffers.resize(mSurfaces.size()); mSurfaceIndexBuffers.resize(mSurfaces.size());
for (u32 iSurf = 0; iSurf < mSurfaces.size(); iSurf++) for (u32 iSurf = 0; iSurf < mSurfaces.size(); iSurf++)
{ {
@ -70,9 +72,13 @@ void CModel::BufferGL()
break; break;
} }
} }
for (u32 iIBO = 0; iIBO < mSurfaceIndexBuffers[iSurf].size(); iIBO++)
mSurfaceIndexBuffers[iSurf][iIBO].Buffer();
} }
mBuffered = true; mBuffered = true;
}
} }
void CModel::GenerateMaterialShaders() void CModel::GenerateMaterialShaders()
@ -92,7 +98,7 @@ void CModel::GenerateMaterialShaders()
void CModel::ClearGLBuffer() void CModel::ClearGLBuffer()
{ {
mVBO.Clear(); mVBO.Clear();
mSubmeshIndexBuffers.clear(); mSurfaceIndexBuffers.clear();
mBuffered = false; mBuffered = false;
} }
@ -127,9 +133,9 @@ void CModel::DrawSurface(FRenderOptions Options, u32 Surface, u32 MatSet)
mVBO.Bind(); mVBO.Bind();
glLineWidth(1.f); glLineWidth(1.f);
for (u32 iIBO = 0; iIBO < mSubmeshIndexBuffers[Surface].size(); iIBO++) for (u32 iIBO = 0; iIBO < mSurfaceIndexBuffers[Surface].size(); iIBO++)
{ {
CIndexBuffer *pIBO = &mSubmeshIndexBuffers[Surface][iIBO]; CIndexBuffer *pIBO = &mSurfaceIndexBuffers[Surface][iIBO];
pIBO->DrawElements(); pIBO->DrawElements();
} }
@ -209,7 +215,7 @@ bool CModel::IsSurfaceTransparent(u32 Surface, u32 MatSet)
CIndexBuffer* CModel::InternalGetIBO(u32 Surface, EGXPrimitiveType Primitive) CIndexBuffer* CModel::InternalGetIBO(u32 Surface, EGXPrimitiveType Primitive)
{ {
std::vector<CIndexBuffer> *pIBOs = &mSubmeshIndexBuffers[Surface]; std::vector<CIndexBuffer> *pIBOs = &mSurfaceIndexBuffers[Surface];
GLenum Type = GXPrimToGLPrim(Primitive); GLenum Type = GXPrimToGLPrim(Primitive);
for (u32 iIBO = 0; iIBO < pIBOs->size(); iIBO++) for (u32 iIBO = 0; iIBO < pIBOs->size(); iIBO++)

View File

@ -14,7 +14,7 @@ class CModel : public CBasicModel
friend class CModelCooker; friend class CModelCooker;
std::vector<CMaterialSet*> mMaterialSets; std::vector<CMaterialSet*> mMaterialSets;
std::vector<std::vector<CIndexBuffer>> mSubmeshIndexBuffers; std::vector<std::vector<CIndexBuffer>> mSurfaceIndexBuffers;
bool mHasOwnMaterials; bool mHasOwnMaterials;
public: public:

View File

@ -34,6 +34,8 @@ void CStaticModel::AddSurface(SSurface *pSurface)
void CStaticModel::BufferGL() void CStaticModel::BufferGL()
{ {
if (!mBuffered)
{
mVBO.Clear(); mVBO.Clear();
mIBOs.clear(); mIBOs.clear();
@ -87,6 +89,7 @@ void CStaticModel::BufferGL()
mIBOs[iIBO].Buffer(); mIBOs[iIBO].Buffer();
mBuffered = true; mBuffered = true;
}
} }
void CStaticModel::GenerateMaterialShaders() void CStaticModel::GenerateMaterialShaders()

View File

@ -33,7 +33,7 @@ CModelNode* CScene::CreateModelNode(CModel *pModel)
{ {
if (pModel == nullptr) return nullptr; if (pModel == nullptr) return nullptr;
CModelNode *pNode = new CModelNode(this, mpSceneRootNode, pModel); CModelNode *pNode = new CModelNode(this, mpAreaRootNode, pModel);
mNodes[eModelNode].push_back(pNode); mNodes[eModelNode].push_back(pNode);
mNumNodes++; mNumNodes++;
return pNode; return pNode;
@ -82,10 +82,7 @@ CLightNode* CScene::CreateLightNode(CLight *pLight)
void CScene::SetActiveArea(CGameArea *pArea) void CScene::SetActiveArea(CGameArea *pArea)
{ {
// Clear existing area // Clear existing area
delete mpAreaRootNode; ClearScene();
mNodes.clear();
mAreaAttributesObjects.clear();
mScriptNodeMap.clear();
// Create nodes for new area // Create nodes for new area
mpArea = pArea; mpArea = pArea;
@ -203,10 +200,11 @@ void CScene::ClearScene()
} }
mNodes.clear(); mNodes.clear();
mAreaAttributesObjects.clear();
mScriptNodeMap.clear();
mNumNodes = 0; mNumNodes = 0;
mpArea = nullptr; mpArea = nullptr;
mpWorld = nullptr;
} }
void CScene::AddSceneToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo) void CScene::AddSceneToRenderer(CRenderer *pRenderer, const SViewInfo& ViewInfo)