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

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

View File

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

View File

@ -33,6 +33,8 @@ void CStaticModel::AddSurface(SSurface *pSurface)
}
void CStaticModel::BufferGL()
{
if (!mBuffered)
{
mVBO.Clear();
mIBOs.clear();
@ -88,6 +90,7 @@ void CStaticModel::BufferGL()
mBuffered = true;
}
}
void CStaticModel::GenerateMaterialShaders()
{

View File

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