BGE: "Fix" for issue [#33663] "Objects Share Materials / Textures When Grouped In...
authorMitchell Stokes <mogurijin@gmail.com>
Mon, 24 Dec 2012 03:13:53 +0000 (03:13 +0000)
committerMitchell Stokes <mogurijin@gmail.com>
Mon, 24 Dec 2012 03:13:53 +0000 (03:13 +0000)
This commit adds a UI option in the Render properties to enable the new material caching in the converter. This caching can cause problems with Singletexture and Multitexture materials when texface is being used to handle materials. By default this option is enabled and users with broken games have two options:

  1) Fix up their materials so they are properly using textures
  2) Disable the material caching and take a speed hit during conversion time

Regardless of the setting, caching is always enabled for GLSL materials.

release/scripts/startup/bl_ui/properties_game.py
source/blender/makesdna/DNA_scene_types.h
source/blender/makesrna/intern/rna_scene.c
source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
source/gameengine/Converter/BL_BlenderDataConversion.cpp
source/gameengine/Converter/KX_BlenderSceneConverter.cpp
source/gameengine/Converter/KX_BlenderSceneConverter.h
source/gameengine/GamePlayer/ghost/GPG_Application.cpp
source/gameengine/Ketsji/KX_ISceneConverter.h

index 42f651de6dfe20e2fc45022cedfa37289f668eaf..58b6aa6916c4070a2a5645185e6cb72b22b7c36f 100644 (file)
@@ -407,6 +407,7 @@ class RENDER_PT_game_system(RenderButtonsPanel, Panel):
         col = row.column()
         col.prop(gs, "use_frame_rate")
         col.prop(gs, "restrict_animation_updates")
+        col.prop(gs, "use_material_caching")
         col = row.column()
         col.prop(gs, "use_display_lists")
         col.active = gs.raster_storage != 'VERTEX_BUFFER_OBJECT'
index 5e06a3084acbddc84ce511e817fcd5534daf3c7b..5af116df77210f7bba3c03622577738000b24db9 100644 (file)
@@ -693,6 +693,7 @@ typedef struct GameData {
 #define GAME_SHOW_MOUSE                                                (1 << 14)
 #define GAME_GLSL_NO_COLOR_MANAGEMENT          (1 << 15)
 #define GAME_SHOW_OBSTACLE_SIMULATION          (1 << 16)
+#define GAME_NO_MATERIAL_CACHING                       (1 << 17)
 /* Note: GameData.flag is now an int (max 32 flags). A short could only take 16 flags */
 
 /* GameData.playerflag */
index 1ead8e6e975440ea42bf168615b8127f6cb4b5a9..8a295e883e1c4b57c458cb533e48206aee5f595d 100644 (file)
@@ -2776,6 +2776,11 @@ static void rna_def_scene_game_data(BlenderRNA *brna)
                                 "Use extra textures like normal or specular maps for GLSL rendering");
        RNA_def_property_update(prop, NC_SCENE | NA_EDITED, "rna_Scene_glsl_update");
 
+       prop = RNA_def_property(srna, "use_material_caching", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_NO_MATERIAL_CACHING);
+       RNA_def_property_ui_text(prop, "Use Material Caching",
+                                                        "Cache materials in the converter. This is faster, but can cause propblems with older Singletexture and Multitexture games");
+
        /* obstacle simulation */
        prop = RNA_def_property(srna, "obstacle_simulation", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "obstacleSimulation");
index 482700d59581b772369007fe6879e2df494f4469..176dc33d05739f9cea0c993b1c258ca7af6b71b4 100644 (file)
@@ -468,6 +468,8 @@ extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *c
                                sceneconverter->SetMaterials(true);
                        if (useglslmat && (gs.matmode == GAME_MAT_GLSL))
                                sceneconverter->SetGLSLMaterials(true);
+                       if (scene->gm.flag & GAME_NO_MATERIAL_CACHING)
+                               sceneconverter->SetCacheMaterials(false);
                                        
                        KX_Scene* startscene = new KX_Scene(keyboarddevice,
                                mousedevice,
index 874bf6144132085a7eaeb766d1b07d087810e5ab..d0d6f9cb81c1fba4c80a2d782db686e62080a821 100644 (file)
@@ -922,6 +922,9 @@ static RAS_MaterialBucket *material_from_mesh(Material *ma, MFace *mface, MTFace
                /* do Texture Face materials */
                Image* bima = (tface)? (Image*)tface->tpage: NULL;
                STR_String imastr =  (tface)? (bima? (bima)->id.name : "" ) : "";
+
+               if (!converter->GetCacheMaterials())
+                       polymat = NULL;
                
                char alpha_blend=0;
                short tile=0;
@@ -1044,7 +1047,8 @@ static RAS_MaterialBucket *material_from_mesh(Material *ma, MFace *mface, MTFace
                                polymat->m_shininess = 35.0;
                        }
                        
-                       converter->CachePolyMaterial(ma, polymat);
+                       if (converter->GetCacheMaterials())
+                               converter->CachePolyMaterial(ma, polymat);
                }
        }
        
index ceaa0a5f5a8890f911c9c9d421894e1a9fe13bdf..5524612f7070240f580c180db1efde00004685c6 100644 (file)
@@ -131,7 +131,8 @@ KX_BlenderSceneConverter::KX_BlenderSceneConverter(
                                                        m_ketsjiEngine(engine),
                                                        m_alwaysUseExpandFraming(false),
                                                        m_usemat(false),
-                                                       m_useglslmat(false)
+                                                       m_useglslmat(false),
+                                                       m_use_mat_cache(true)
 {
        tag_main(maggie, 0); /* avoid re-tagging later on */
        m_newfilename = "";
@@ -488,6 +489,11 @@ void KX_BlenderSceneConverter::SetGLSLMaterials(bool val)
        m_useglslmat = val;
 }
 
+void KX_BlenderSceneConverter::SetCacheMaterials(bool val)
+{
+       m_use_mat_cache = val;
+}
+
 bool KX_BlenderSceneConverter::GetMaterials()
 {
        return m_usemat;
@@ -498,6 +504,11 @@ bool KX_BlenderSceneConverter::GetGLSLMaterials()
        return m_useglslmat;
 }
 
+bool KX_BlenderSceneConverter::GetCacheMaterials()
+{
+       return m_use_mat_cache;
+}
+
 void KX_BlenderSceneConverter::RegisterBlenderMaterial(BL_Material *mat)
 {
        // First make sure we don't register the material twice
index f7723350eee7d7ee5bc45adc69e8d2349aa9f01c..06dac1707c5a22b72f9a879a369d7a0ece78a924 100644 (file)
@@ -91,6 +91,7 @@ class KX_BlenderSceneConverter : public KX_ISceneConverter
        bool                                    m_alwaysUseExpandFraming;
        bool                                    m_usemat;
        bool                                    m_useglslmat;
+       bool                                    m_use_mat_cache;
 
 public:
        KX_BlenderSceneConverter(
@@ -160,6 +161,10 @@ public:
        virtual void SetGLSLMaterials(bool val);
        virtual bool GetGLSLMaterials();
 
+       // cache materials during conversion
+       virtual void SetCacheMaterials(bool val);
+       virtual bool GetCacheMaterials();
+
        struct Scene* GetBlenderSceneForName(const STR_String& name);
 
 //     struct Main* GetMain() { return m_maggie; }
index 1dcc68c8e75685ee44a4c68e8bacb2fdbb7aefa2..89d11515bb33d36525d88f69e85adb6fe3be6e31 100644 (file)
@@ -703,6 +703,8 @@ bool GPG_Application::startEngine(void)
                        m_sceneconverter->SetMaterials(true);
                if (m_blenderglslmat && (m_globalSettings->matmode == GAME_MAT_GLSL))
                        m_sceneconverter->SetGLSLMaterials(true);
+               if (m_startScene->gm.flag & GAME_NO_MATERIAL_CACHING)
+                       m_sceneconverter->SetCacheMaterials(false);
 
                KX_Scene* startscene = new KX_Scene(m_keyboard,
                        m_mouse,
index 7c1d593a81e4990a29da1fa8aea0109c4fed1ddb..616895a82692cd668a187a3ff9e2f6635f79955f 100644 (file)
@@ -89,6 +89,10 @@ public:
        virtual void SetGLSLMaterials(bool val) =0;
        virtual bool GetGLSLMaterials()=0;
 
+       // cache materials during conversion
+       virtual void SetCacheMaterials(bool val) =0;
+       virtual bool GetCacheMaterials()=0;
+
        virtual struct Scene* GetBlenderSceneForName(const STR_String& name)=0;