Added PostLoad methods to ensure all models have created vertex buffers and all materials have generated shaders before the user gains control of the camera, to fix hitching issues

This commit is contained in:
parax0
2016-02-10 17:38:32 -07:00
parent 6d55444cc2
commit 739e3c51bf
17 changed files with 91 additions and 13 deletions

View File

@@ -78,13 +78,16 @@ CMaterial* CMaterial::Clone()
return pOut;
}
void CMaterial::GenerateShader()
void CMaterial::GenerateShader(bool AllowRegen /*= true*/)
{
delete mpShader;
mpShader = CShaderGenerator::GenerateShader(*this);
if (mShaderStatus != eShaderExists || AllowRegen)
{
delete mpShader;
mpShader = CShaderGenerator::GenerateShader(*this);
if (!mpShader->IsValidProgram()) mShaderStatus = eShaderFailed;
else mShaderStatus = eShaderExists;
if (!mpShader->IsValidProgram()) mShaderStatus = eShaderFailed;
else mShaderStatus = eShaderExists;
}
}
bool CMaterial::SetCurrent(FRenderOptions Options)

View File

@@ -76,7 +76,7 @@ public:
CMaterial(EGame version, FVertexDescription vtxDesc);
~CMaterial();
CMaterial* Clone();
void GenerateShader();
void GenerateShader(bool AllowRegen = true);
bool SetCurrent(FRenderOptions Options);
u64 HashParameters();
void Update();

View File

@@ -75,6 +75,20 @@ void CModel::BufferGL()
mBuffered = true;
}
void CModel::GenerateMaterialShaders()
{
for (u32 iSet = 0; iSet < mMaterialSets.size(); iSet++)
{
CMaterialSet *pSet = mMaterialSets[iSet];
for (u32 iMat = 0; iMat < pSet->NumMaterials(); iMat++)
{
CMaterial *pMat = pSet->MaterialByIndex(iMat);
pMat->GenerateShader(false);
}
}
}
void CModel::ClearGLBuffer()
{
mVBO.Clear();

View File

@@ -23,6 +23,7 @@ public:
~CModel();
void BufferGL();
void GenerateMaterialShaders();
void ClearGLBuffer();
void Draw(FRenderOptions Options, u32 MatSet);
void DrawSurface(FRenderOptions Options, u32 Surface, u32 MatSet);

View File

@@ -89,6 +89,12 @@ void CStaticModel::BufferGL()
mBuffered = true;
}
void CStaticModel::GenerateMaterialShaders()
{
if (mpMaterial)
mpMaterial->GenerateShader(false);
}
void CStaticModel::ClearGLBuffer()
{
mVBO.Clear();

View File

@@ -22,6 +22,7 @@ public:
void AddSurface(SSurface *pSurface);
void BufferGL();
void GenerateMaterialShaders();
void ClearGLBuffer();
void Draw(FRenderOptions Options);
void DrawSurface(FRenderOptions Options, u32 Surface);