Skip to content
Permalink
Browse files
Load materials once, not once per model.
Load time 9.29s -> 4.54s
  • Loading branch information
rygorous committed Mar 4, 2013
1 parent 5d4f838 commit b4e29b2
Showing 1 changed file with 8 additions and 7 deletions.
@@ -306,6 +306,7 @@ CPUTMaterial *CPUTAssetLibrary::GetMaterial(const cString &name, bool nameIsFull
// Resolve name to absolute path before searching
CPUTOSServices *pServices = CPUTOSServices::GetOSServices();
cString absolutePathAndFilename;
bool created = false;
pServices->ResolveAbsolutePathAndFilename( nameIsFullPathAndFilename? name : (mMaterialDirectoryName + name + _L(".mtl")), &absolutePathAndFilename);

CPUTMaterial *pMaterial;
@@ -318,25 +319,25 @@ CPUTMaterial *CPUTAssetLibrary::GetMaterial(const cString &name, bool nameIsFull
return pMaterial;
}
}
else
{
// Loading a non-instanced material (or, the master)
pMaterial = FindMaterial(absolutePathAndFilename, true);
}

// Loading a non-instanced material (or, the master)
pMaterial = FindMaterial(absolutePathAndFilename, true);

// If the material has per-model properties, then we need a material clone
if( !pMaterial )
{
pMaterial = CPUTMaterial::CreateMaterial( absolutePathAndFilename, pModel, meshIndex );
pMaterial = CPUTMaterial::CreateMaterial( absolutePathAndFilename );
ASSERT( pMaterial, _L("Failed creating material.") );
created = true;
}
if( !pModel )
{
// Not looking for an instance, so return what we found
return pMaterial;
}
CPUTMaterial *pClone = pMaterial->CloneMaterial( absolutePathAndFilename, pModel, meshIndex);
pMaterial->Release(); // We don't want to hold a reference to the master.
if ( created )
pMaterial->Release(); // We don't want to hold a reference to the master.
return pClone;
}

0 comments on commit b4e29b2

Please sign in to comment.