Merged 15170:15635 from trunk (no conflicts or even merges)
[blender.git] / source / gameengine / BlenderRoutines / BL_KetsjiEmbedStart.cpp
index fa8409b123e56973a4e0b4ddc805556f303cbc22..b3a3a47152ad03a54a710f023020308a9efb4e57 100644 (file)
@@ -40,9 +40,7 @@
 #pragma warning (disable:4786)
 #endif
 
-#ifdef __APPLE__
-#define GL_GLEXT_LEGACY 1
-#endif 
+#include "GL/glew.h"
 
 #include "KX_BlenderGL.h"
 #include "KX_BlenderCanvas.h"
 #include "KX_PythonInit.h"
 #include "KX_PyConstraintBinding.h"
 
+#include "RAS_GLExtensionManager.h"
 #include "RAS_OpenGLRasterizer.h"
 #include "RAS_VAOpenGLRasterizer.h"
 #include "RAS_ListRasterizer.h"
-#include "RAS_GLExtensionManager.h"
 
 #include "NG_LoopBackNetworkDeviceInterface.h"
 #include "SND_DeviceManager.h"
@@ -142,12 +140,12 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
        // so we can safely run Python code and API calls
        PyGILState_STATE gilstate = PyGILState_Ensure();
 
-       bgl::InitExtensions(1);
-       
+       bgl::InitExtensions(true);
+
        do
        {
                View3D *v3d= (View3D*) area->spacedata.first;
-               
+
                // get some preferences
                SYS_SystemHandle syshandle = SYS_GetSystem();
                bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
@@ -156,22 +154,10 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
                bool game2ipo = (SYS_GetCommandLineInt(syshandle, "game2ipo", 0) != 0);
                bool displaylists = (SYS_GetCommandLineInt(syshandle, "displaylists", 0) != 0);
-               bool usemat = false;
-               
-               #if defined(GL_ARB_multitexture) && defined(WITH_GLEXT)
-               if (!getenv("WITHOUT_GLEXT")) {
-                       if(bgl::RAS_EXT_support._ARB_multitexture && bgl::QueryVersion(1, 1)) {
-                               usemat = (SYS_GetCommandLineInt(syshandle, "blender_material", 0) != 0);
-                               int unitmax=0;
-                               glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, (GLint*)&unitmax);
-                               bgl::max_texture_units = MAXTEX>unitmax?unitmax:MAXTEX;
-                               //std::cout << "using(" << bgl::max_texture_units << ") of(" << unitmax << ") texture units." << std::endl;
-                       } else {
-                               bgl::max_texture_units = 0;
-                       }
-               }
-               #endif
+               bool usemat = false, useglslmat = false;
 
+               if(GLEW_ARB_multitexture && GLEW_VERSION_1_1)
+                       usemat = (SYS_GetCommandLineInt(syshandle, "blender_material", 0) != 0);
 
                // create the canvas, rasterizer and rendertools
                RAS_ICanvas* canvas = new KX_BlenderCanvas(area);
@@ -179,20 +165,14 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                RAS_IRenderTools* rendertools = new KX_BlenderRenderTools();
                RAS_IRasterizer* rasterizer = NULL;
                
-               // let's see if we want to use vertexarrays or not
-               int usevta = SYS_GetCommandLineInt(syshandle,"vertexarrays",1);
-               bool useVertexArrays = (usevta > 0);
-               
-               bool lock_arrays = (displaylists && useVertexArrays);
-
-               if(displaylists){
-                       if (useVertexArrays) {
-                               rasterizer = new RAS_ListRasterizer(canvas, true, lock_arrays);
-                       } else {
+               if(displaylists) {
+                       if (GLEW_VERSION_1_1)
+                               rasterizer = new RAS_ListRasterizer(canvas, true, true);
+                       else
                                rasterizer = new RAS_ListRasterizer(canvas);
-                       }
-               } else if (useVertexArrays && bgl::QueryVersion(1, 1))
-                       rasterizer = new RAS_VAOpenGLRasterizer(canvas, lock_arrays);
+               }
+               else if (GLEW_VERSION_1_1)
+                       rasterizer = new RAS_VAOpenGLRasterizer(canvas, false);
                else
                        rasterizer = new RAS_OpenGLRasterizer(canvas);
                
@@ -338,6 +318,8 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                        
                        if(usemat)
                                sceneconverter->SetMaterials(true);
+                       if(useglslmat)
+                               sceneconverter->SetGLSLMaterials(true);
                                        
                        KX_Scene* startscene = new KX_Scene(keyboarddevice,
                                mousedevice,
@@ -350,6 +332,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                        ketsjiengine->SetPythonDictionary(dictionaryobject);
                        initRasterizer(rasterizer, canvas);
                        PyObject *gameLogic = initGameLogic(startscene);
+                       PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module.
                        initGameKeys();
                        initPythonConstraintBinding();
 
@@ -372,6 +355,12 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                                // start the engine
                                ketsjiengine->StartEngine(true);
                                
+
+                               // Set the animation playback rate for ipo's and actions
+                               // the framerate below should patch with FPS macro defined in blendef.h
+                               // Could be in StartEngine set the framerate, we need the scene to do this
+                               ketsjiengine->SetAnimFrameRate( (((double) blscene->r.frs_sec) / blscene->r.frs_sec_base) );
+                               
                                // the mainloop
                                while (!exitrequested)
                                {
@@ -411,7 +400,14 @@ extern "C" void StartKetsjiShell(struct ScrArea *area,
                                exitstring = ketsjiengine->GetExitString();
                                
                                // when exiting the mainloop
-                               dictionaryClearByHand(gameLogic);
+                               
+                               // Clears the dictionary by hand:
+                               // This prevents, extra references to global variables
+                               // inside the GameLogic dictionary when the python interpreter is finalized.
+                               // which allows the scene to safely delete them :)
+                               // see: (space.c)->start_game
+                               PyDict_Clear(PyModule_GetDict(gameLogic));
+                               
                                ketsjiengine->StopEngine();
                                exitGamePythonScripting();
                                networkdevice->Disconnect();
@@ -498,7 +494,7 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
        // so we can safely run Python code and API calls
        PyGILState_STATE gilstate = PyGILState_Ensure();
 
-       bgl::InitExtensions(1);
+       bgl::InitExtensions(true);
 
        do
        {
@@ -519,16 +515,14 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
                RAS_IRenderTools* rendertools = new KX_BlenderRenderTools();
                RAS_IRasterizer* rasterizer = NULL;
 
-               // let's see if we want to use vertexarrays or not
-               int usevta = SYS_GetCommandLineInt(syshandle,"vertexarrays",1);
-               bool useVertexArrays = (usevta > 0);
-
-               bool lock_arrays = (displaylists && useVertexArrays);
-
-               if(displaylists && !useVertexArrays)
-                       rasterizer = new RAS_ListRasterizer(canvas);
-               else if (useVertexArrays && bgl::QueryVersion(1, 1))
-                       rasterizer = new RAS_VAOpenGLRasterizer(canvas, lock_arrays);
+               if(displaylists) {
+                       if (GLEW_VERSION_1_1)
+                               rasterizer = new RAS_ListRasterizer(canvas, true, true);
+                       else
+                               rasterizer = new RAS_ListRasterizer(canvas);
+               }
+               else if (GLEW_VERSION_1_1)
+                       rasterizer = new RAS_VAOpenGLRasterizer(canvas, false);
                else
                        rasterizer = new RAS_OpenGLRasterizer(canvas);
 
@@ -605,6 +599,7 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area,
                        ketsjiengine->SetPythonDictionary(dictionaryobject);
                        initRasterizer(rasterizer, canvas);
                        PyObject *gameLogic = initGameLogic(startscene);
+                       PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module
                        initGameKeys();
                        initPythonConstraintBinding();