Game engine: added Rasterizer.get/setMaterialMode to set texface,
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 13 Sep 2008 19:19:51 +0000 (19:19 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Sat, 13 Sep 2008 19:19:51 +0000 (19:19 +0000)
multitexture or glsl materials. This does not affect existing
scenes, only newly created ones.

source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
source/gameengine/GamePlayer/ghost/GPG_Application.cpp
source/gameengine/Ketsji/KX_PythonInit.cpp
source/gameengine/PyDoc/Rasterizer.py

index 1f66335c7496c8b0647541b2b0165d979b525972..fa771cb3ce8d4cf2ad4af4c6d619df5844d90f34 100644 (file)
@@ -138,10 +138,12 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                bool usemat = false, useglslmat = false;
 
                if(GLEW_ARB_multitexture && GLEW_VERSION_1_1)
-                       usemat = (SYS_GetCommandLineInt(syshandle, "blender_material", 0) != 0);
+                       usemat = (SYS_GetCommandLineInt(syshandle, "blender_material", 1) != 0);
 
                if(GPU_extensions_minimum_support())
-                       useglslmat = (SYS_GetCommandLineInt(syshandle, "blender_glsl_material", 0) != 0);
+                       useglslmat = (SYS_GetCommandLineInt(syshandle, "blender_glsl_material", 1) != 0);
+               else if(G.fileflags & G_FILE_GAME_MAT_GLSL)
+                       usemat = false;
 
                // create the canvas, rasterizer and rendertools
                RAS_ICanvas* canvas = new KX_BlenderCanvas(area);
@@ -299,10 +301,10 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                        sceneconverter->addInitFromFrame=false;
                        if (always_use_expand_framing)
                                sceneconverter->SetAlwaysUseExpandFraming(true);
-                       
-                       if(usemat)
+
+                       if(usemat && (G.fileflags & G_FILE_GAME_MAT))
                                sceneconverter->SetMaterials(true);
-                       if(useglslmat)
+                       if(useglslmat && (G.fileflags & G_FILE_GAME_MAT_GLSL))
                                sceneconverter->SetGLSLMaterials(true);
                                        
                        KX_Scene* startscene = new KX_Scene(keyboarddevice,
index 0287178004df6b026cdf5a90a5c5ba96f3f0b275..580c80ee0a57ee74548cf07a9b999fb42cffd06a 100644 (file)
@@ -524,17 +524,14 @@ bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
                bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
                bool useLists = (SYS_GetCommandLineInt(syshandle, "displaylists", G.fileflags & G_FILE_DISPLAY_LISTS) != 0);
 
-               if(GLEW_ARB_multitexture && GLEW_VERSION_1_1) {
-                       int gameflag =(G.fileflags & G_FILE_GAME_MAT);
-                       m_blendermat = (SYS_GetCommandLineInt(syshandle, "blender_material", gameflag) != 0);
-               }
+               if(GLEW_ARB_multitexture && GLEW_VERSION_1_1)
+                       m_blendermat = (SYS_GetCommandLineInt(syshandle, "blender_material", 1) != 0);
 
-               if(GPU_extensions_minimum_support()) {
-                       int gameflag = (G.fileflags & G_FILE_GAME_MAT_GLSL);
+               if(GPU_extensions_minimum_support())
+                       m_blenderglslmat = (SYS_GetCommandLineInt(syshandle, "blender_glsl_material", 1) != 0);
+               else if(G.fileflags & G_FILE_GAME_MAT_GLSL)
+                       m_blendermat = false;
 
-                       m_blenderglslmat = (SYS_GetCommandLineInt(syshandle, "blender_glsl_material", gameflag) != 0);
-               }
-       
                // create the canvas, rasterizer and rendertools
                m_canvas = new GPG_Canvas(window);
                if (!m_canvas)
@@ -657,12 +654,12 @@ bool GPG_Application::startEngine(void)
        {
                STR_String startscenename = m_startSceneName.Ptr();
                m_ketsjiengine->SetSceneConverter(m_sceneconverter);
-               
+
                //      if (always_use_expand_framing)
                //              sceneconverter->SetAlwaysUseExpandFraming(true);
-               if(m_blendermat)
+               if(m_blendermat && (G.fileflags & G_FILE_GAME_MAT))
                        m_sceneconverter->SetMaterials(true);
-               if(m_blenderglslmat)
+               if(m_blenderglslmat && (G.fileflags & G_FILE_GAME_MAT_GLSL))
                        m_sceneconverter->SetGLSLMaterials(true);
 
                KX_Scene* startscene = new KX_Scene(m_keyboard,
index 5742c530f6d9aa6bb22b1b88d0b3eb4dbf015b47..5308a0b95363b17b3e827d13314950432d064449 100644 (file)
@@ -303,7 +303,7 @@ static PyObject* gPyGetBlendFileList(PyObject*, PyObject* args)
        
     if((dp  = opendir(cpath)) == NULL) {
                /* todo, show the errno, this shouldnt happen anyway if the blendfile is readable */
-               fprintf(stderr, "Could not read directoty () failed, code %d (%s)\n", cpath, errno, strerror(errno));
+               fprintf(stderr, "Could not read directoty (%s) failed, code %d (%s)\n", cpath, errno, strerror(errno));
                return list;
     }
        
@@ -696,7 +696,7 @@ static PyObject* gPySetGLSLMaterialSetting(PyObject*,
                                                                                        PyObject*)
 {
        char *setting;
-       int enable, flag;
+       int enable, flag, fileflags;
 
        if (!PyArg_ParseTuple(args,"si",&setting,&enable))
                return NULL;
@@ -707,6 +707,8 @@ static PyObject* gPySetGLSLMaterialSetting(PyObject*,
                PyErr_SetString(PyExc_ValueError, "glsl setting is not known");
                return NULL;
        }
+
+       fileflags = G.fileflags;
        
        if (enable)
                G.fileflags &= ~flag;
@@ -714,17 +716,19 @@ static PyObject* gPySetGLSLMaterialSetting(PyObject*,
                G.fileflags |= flag;
 
        /* display lists and GLSL materials need to be remade */
-       if(gp_KetsjiEngine) {
-               KX_SceneList *scenes = gp_KetsjiEngine->CurrentScenes();
-               KX_SceneList::iterator it;
+       if(G.fileflags != fileflags) {
+               if(gp_KetsjiEngine) {
+                       KX_SceneList *scenes = gp_KetsjiEngine->CurrentScenes();
+                       KX_SceneList::iterator it;
+
+                       for(it=scenes->begin(); it!=scenes->end(); it++)
+                               if((*it)->GetBucketManager())
+                                       (*it)->GetBucketManager()->ReleaseDisplayLists();
+               }
 
-               for(it=scenes->begin(); it!=scenes->end(); it++)
-                       if((*it)->GetBucketManager())
-                               (*it)->GetBucketManager()->ReleaseDisplayLists();
+               GPU_materials_free();
        }
 
-       GPU_materials_free();
-
        Py_RETURN_NONE;
 }
 
@@ -749,6 +753,50 @@ static PyObject* gPyGetGLSLMaterialSetting(PyObject*,
        return PyInt_FromLong(enabled);
 }
 
+#define KX_TEXFACE_MATERIAL                            0
+#define KX_BLENDER_MULTITEX_MATERIAL   1
+#define KX_BLENDER_GLSL_MATERIAL               2
+
+static PyObject* gPySetMaterialType(PyObject*,
+                                                                       PyObject* args,
+                                                                       PyObject*)
+{
+       int flag, type;
+
+       if (!PyArg_ParseTuple(args,"i",&type))
+               return NULL;
+
+       if(type == KX_BLENDER_GLSL_MATERIAL)
+               flag = G_FILE_GAME_MAT|G_FILE_GAME_MAT_GLSL;
+       else if(type == KX_BLENDER_MULTITEX_MATERIAL)
+               flag = G_FILE_GAME_MAT;
+       else if(type == KX_TEXFACE_MATERIAL)
+               flag = 0;
+       else {
+               PyErr_SetString(PyExc_ValueError, "material type is not known");
+               return NULL;
+       }
+
+       G.fileflags &= ~(G_FILE_GAME_MAT|G_FILE_GAME_MAT_GLSL);
+       G.fileflags |= flag;
+
+       Py_RETURN_NONE;
+}
+
+static PyObject* gPyGetMaterialType(PyObject*)
+{
+       int flag;
+
+       if(G.fileflags & (G_FILE_GAME_MAT|G_FILE_GAME_MAT_GLSL))
+               flag = KX_BLENDER_GLSL_MATERIAL;
+       else if(G.fileflags & G_FILE_GAME_MAT)
+               flag = KX_BLENDER_MULTITEX_MATERIAL;
+       else
+               flag = KX_TEXFACE_MATERIAL;
+       
+       return PyInt_FromLong(flag);
+}
+
 STR_String     gPyGetWindowHeight__doc__="getWindowHeight doc";
 STR_String     gPyGetWindowWidth__doc__="getWindowWidth doc";
 STR_String     gPyEnableVisibility__doc__="enableVisibility doc";
@@ -782,6 +830,10 @@ static struct PyMethodDef rasterizer_methods[] = {
   {"getEyeSeparation", (PyCFunction) gPyGetEyeSeparation, METH_VARARGS, "get the eye separation for stereo mode"},
   {"setFocalLength", (PyCFunction) gPySetFocalLength, METH_VARARGS, "set the focal length for stereo mode"},
   {"getFocalLength", (PyCFunction) gPyGetFocalLength, METH_VARARGS, "get the focal length for stereo mode"},
+  {"setMaterialMode",(PyCFunction) gPySetMaterialType,
+   METH_VARARGS, "set the material mode to use for OpenGL rendering"},
+  {"getMaterialMode",(PyCFunction) gPyGetMaterialType,
+   METH_NOARGS, "get the material mode being used for OpenGL rendering"},
   {"setGLSLMaterialSetting",(PyCFunction) gPySetGLSLMaterialSetting,
    METH_VARARGS, "set the state of a GLSL material setting"},
   {"getGLSLMaterialSetting",(PyCFunction) gPyGetGLSLMaterialSetting,
@@ -1111,6 +1163,11 @@ PyObject* initRasterizer(RAS_IRasterizer* rasty,RAS_ICanvas* canvas)
   ErrorObject = PyString_FromString("Rasterizer.error");
   PyDict_SetItemString(d, "error", ErrorObject);
 
+  /* needed for get/setMaterialType */
+  KX_MACRO_addTypesToDict(d, KX_TEXFACE_MATERIAL, KX_TEXFACE_MATERIAL);
+  KX_MACRO_addTypesToDict(d, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL);
+  KX_MACRO_addTypesToDict(d, KX_BLENDER_GLSL_MATERIAL, KX_BLENDER_GLSL_MATERIAL);
+
   // XXXX Add constants here
 
   // Check for errors
index 7afdcf07f2eaf16734c16502634d2e118e1525b4..ebb5332d98dd8df6146db68f71443d81d98cad56 100644 (file)
@@ -37,6 +37,10 @@ Example Uses an L{SCA_MouseSensor}, and two L{KX_ObjectActuator}s to implement M
        # Centre the mouse
        Rasterizer.setMousePosition(Rasterizer.getWindowWidth()/2, Rasterizer.getWindowHeight()/2)
 
+@group Material Types: KX_TEXFACE_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_GLSL_MATERIAL
+@var KX_TEXFACE_MATERIAL: Materials as defined by the texture face settings.
+@var KX_BLENDER_MULTITEX_MATERIAL: Materials approximating blender materials with multitexturing.
+@var KX_BLENDER_BLENDER_MATERIAL: Materials approximating blender materials with GLSL.
        
 """
 
@@ -147,6 +151,21 @@ def getFocalLength():
        @rtype: float
        """
 
+def setMaterialMode(mode):
+       """
+       Set the material mode to use for OpenGL rendering.
+       
+       @type mode: KX_TEXFACE_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_GLSL_MATERIAL
+       @note: Changes will only affect newly created scenes.
+       """
+
+def getMaterialMode(mode):
+       """
+       Get the material mode to use for OpenGL rendering.
+       
+       @rtype: KX_TEXFACE_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_GLSL_MATERIAL
+       """
+
 def setGLSLMaterialSetting(setting, enable):
        """
        Enables or disables a GLSL material setting.