Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Bolsee <benoit.bolsee@online.be>2008-03-24 02:12:40 +0300
committerBenoit Bolsee <benoit.bolsee@online.be>2008-03-24 02:12:40 +0300
commitb20f6e27ff24f60bfa39b2311be3cc2f4130ac09 (patch)
treecb528d7c2d3cfe9d983a17cea3866a695f1c1e43 /source/gameengine/Converter/BL_BlenderDataConversion.cpp
parentf162428bd244687116c5a51edc64b1b49c634154 (diff)
Commit patch #8724:
This patch modifies the BL_ConvertMesh method from the data conversion module in order to reduce the number of polygon material objects that are created. Normally, there should be only one material object for each material bucket(the group of meshes that are rendered together with a single material). However, the number of materials that are created right now in the converter is much higher and eats a lot of memory in scenes with large polygon counts. This patch deletes those material objects(KX_BlenderMaterial) that are used only temporarily in the converter(and are now deleted only when the converter is destroyed, at the end of the game). For a cube that's subdivided 7 times(90+ k polygons) I get 200 MB usage in the game engine in 2.45 and 44 MB with a svn build with this patch applied if the "Use Blender Materials" option is activated in the Game menu.
Diffstat (limited to 'source/gameengine/Converter/BL_BlenderDataConversion.cpp')
-rw-r--r--source/gameengine/Converter/BL_BlenderDataConversion.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
index 743aabcd821..8ae287a494c 100644
--- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp
+++ b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
@@ -883,6 +883,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
Material* ma = 0;
bool polyvisible = true;
RAS_IPolyMaterial* polymat = NULL;
+ BL_Material *bl_mat;
if(converter->GetMaterials())
{
@@ -891,7 +892,7 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
else
ma = give_current_material(blenderobj, 1);
- BL_Material *bl_mat = ConvertMaterial(mesh, ma, tface, mface, mmcol, lightlayer, blenderobj, layers);
+ bl_mat = ConvertMaterial(mesh, ma, tface, mface, mmcol, lightlayer, blenderobj, layers);
// set the index were dealing with
bl_mat->material_index = (int)mface->mat_nr;
@@ -899,7 +900,6 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
collider = ((bl_mat->ras_mode & COLLIDER)!=0);
polymat = new KX_BlenderMaterial(scene, bl_mat, skinMesh, lightlayer, blenderobj );
- converter->RegisterBlenderMaterial(bl_mat);
unsigned int rgb[4];
bl_mat->GetConversionRGB(rgb);
@@ -921,8 +921,6 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
if (mface->v4)
tan3 = tangent[mface->v4];
}
- // this is needed to free up memory afterwards
- converter->RegisterPolyMaterial(polymat);
}
else
{
@@ -1029,12 +1027,27 @@ RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, RAS_IRenderTools*
polymat->m_specular = MT_Vector3(0.0f,0.0f,0.0f);
polymat->m_shininess = 35.0;
}
+ }
+
+ // see if a bucket was reused or a new one was created
+ // this way only one KX_BlenderMaterial object has to exist per bucket
+ bool bucketCreated;
+ RAS_MaterialBucket* bucket = scene->FindBucket(polymat, bucketCreated);
+ if (bucketCreated) {
// this is needed to free up memory afterwards
converter->RegisterPolyMaterial(polymat);
-
+ if(converter->GetMaterials()) {
+ converter->RegisterBlenderMaterial(bl_mat);
+ }
+ } else {
+ // delete the material objects since they are no longer needed
+ // from now on, use the polygon material from the material bucket
+ delete polymat;
+ if(converter->GetMaterials()) {
+ delete bl_mat;
+ }
+ polymat = bucket->GetPolyMaterial();
}
-
- RAS_MaterialBucket* bucket = scene->FindBucket(polymat);
int nverts = mface->v4?4:3;
int vtxarray = meshobj->FindVertexArray(nverts,polymat);