diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-13 00:16:53 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-13 00:16:53 +0300 |
commit | bdfe7d89e2f1292644577972c716931b4ce3c6c3 (patch) | |
tree | d00eb50b749cb001e2b08272c91791e66740b05d /source/gameengine/BlenderRoutines | |
parent | 78a1c27c4a6abe0ed31ca93ad21910f3df04da56 (diff) | |
parent | 7e4db234cee71ead34ee81a12e27da4bd548eb4b (diff) |
Merge of trunk into blender 2.5:
svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r12987:17416
Issues:
* GHOST/X11 had conflicting changes. Some code was added in 2.5, which was
later added in trunk also, but reverted partially, specifically revision
16683. I have left out this reversion in the 2.5 branch since I think it is
needed there.
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16683
* Scons had various conflicting changes, I decided to go with trunk version
for everything except priorities and some library renaming.
* In creator.c, there were various fixes and fixes for fixes related to the -w
-W and -p options. In 2.5 -w and -W is not coded yet, and -p is done
differently. Since this is changed so much, and I don't think those fixes
would be needed in 2.5, I've left them out.
* Also in creator.c: there was code for a python bugfix where the screen was not
initialized when running with -P. The code that initializes the screen there
I had to disable, that can't work in 2.5 anymore but left it commented as a
reminder.
Further I had to disable some new function calls. using src/ and python/, as
was done already in this branch, disabled function calls:
* bpath.c: error reporting
* BME_conversions.c: editmesh conversion functions.
* SHD_dynamic: disabled almost completely, there is no python/.
* KX_PythonInit.cpp and Ketsji/ build files: Mathutils is not there, disabled.
* text.c: clipboard copy call.
* object.c: OB_SUPPORT_MATERIAL.
* DerivedMesh.c and subsurf_ccg, stipple_quarttone.
Still to be done:
* Go over files and functions that were moved to a different location but could
still use changes that were done in trunk.
Diffstat (limited to 'source/gameengine/BlenderRoutines')
12 files changed, 383 insertions, 617 deletions
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 12c550c52b7..0dab583567d 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -33,15 +33,14 @@ #endif #include <signal.h> +#include <stdlib.h> #ifdef WIN32 // don't show stl-warnings #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" @@ -56,10 +55,10 @@ #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" @@ -71,6 +70,7 @@ #include "DNA_view3d_types.h" #include "DNA_screen_types.h" #include "BKE_global.h" +#include "BKE_utildefines.h" //XXX #include "BIF_screen.h" //XXX #include "BIF_scrarea.h" @@ -80,6 +80,8 @@ #include "DNA_scene_types.h" /***/ +#include "GPU_extensions.h" + #ifdef __cplusplus extern "C" { #endif @@ -91,28 +93,10 @@ void update_for_newframe(); static BlendFileData *load_game_data(char *filename) { BlendReadError error; - //this doesn't work anymore for relative paths, so use BLO_read_from_memory instead - //BlendFileData *bfd= BLO_read_from_file(filename, &error); - FILE* file = fopen(filename,"rb"); - BlendFileData *bfd = 0; - if (file) - { - fseek(file, 0L, SEEK_END); - int len= ftell(file); - fseek(file, 0L, SEEK_SET); - char* filebuffer= new char[len];//MEM_mallocN(len, "text_buffer"); - int sizeread = fread(filebuffer,len,1,file); - if (sizeread==1) - { - bfd = BLO_read_from_memory(filebuffer, len, &error); - } - fclose(file); - } - + BlendFileData *bfd= BLO_read_from_file(filename, &error); if (!bfd) { printf("Loading %s failed: %s\n", filename, BLO_bre_as_string(error)); } - return bfd; } @@ -127,17 +111,26 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, Main* blenderdata = maggie1; char* startscenename = scenename; - char pathname[160]; - strcpy (pathname, blenderdata->name); + char pathname[FILE_MAXDIR+FILE_MAXFILE], oldsce[FILE_MAXDIR+FILE_MAXFILE]; STR_String exitstring = ""; BlendFileData *bfd= NULL; - bgl::InitExtensions(1); + BLI_strncpy(pathname, blenderdata->name, sizeof(pathname)); + BLI_strncpy(oldsce, G.sce, sizeof(oldsce)); + setGamePythonPath(G.sce); + + // Acquire Python's GIL (global interpreter lock) + // so we can safely run Python code and API calls + PyGILState_STATE gilstate = PyGILState_Ensure(); + + PyObject *pyGlobalDict = PyDict_New(); /* python utility storage, spans blend file loading */ + 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); @@ -146,20 +139,6 @@ 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; - - #ifdef GL_ARB_multitexture - 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 - // create the canvas, rasterizer and rendertools RAS_ICanvas* canvas = new KX_BlenderCanvas(area); @@ -167,16 +146,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 && !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); @@ -188,6 +165,13 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, NG_NetworkDeviceInterface* networkdevice = new NG_LoopBackNetworkDeviceInterface(); + // + SYS_SystemHandle hSystem = SYS_GetSystem(); + bool noaudio = SYS_GetCommandLineInt(hSystem,"noaudio",0); + + if (noaudio)/*(noaudio) intrr: disable game engine audio (openal) */ + SND_DeviceManager::SetDeviceType(snd_e_dummydevice); + // get an audiodevice SND_DeviceManager::Subscribe(); SND_IAudioDevice* audiodevice = SND_DeviceManager::Instance(); @@ -211,11 +195,21 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, ketsjiengine->SetUseFixedTime(usefixed); ketsjiengine->SetTimingDisplay(frameRate, profile, properties); - + + //lock frame and camera enabled - storing global values + int tmp_lay= G.scene->lay; + Object *tmp_camera = G.scene->camera; + + if (G.vd->scenelock==0){ + G.scene->lay= v3d->lay; + G.scene->camera= v3d->camera; + } + // some blender stuff MT_CmMatrix4x4 projmat; MT_CmMatrix4x4 viewmat; + float camzoom; int i; for (i = 0; i < 16; i++) @@ -229,8 +223,13 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, projmat.setElem(i, projmat_linear[i]); } - float camzoom = (1.41421 + (v3d->camzoom / 50.0)); - camzoom *= camzoom; + if(v3d->persp==V3D_CAMOB) { + camzoom = (1.41421 + (v3d->camzoom / 50.0)); + camzoom *= camzoom; + } + else + camzoom = 2.0; + camzoom = 4.0 / camzoom; ketsjiengine->SetDrawType(v3d->drawtype); @@ -242,24 +241,29 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, exitrequested = KX_EXIT_REQUEST_NO_REQUEST; if (bfd) BLO_blendfiledata_free(bfd); - char basedpath[160]; + char basedpath[240]; // base the actuator filename with respect // to the original file working directory + if (exitstring != "") strcpy(basedpath, exitstring.Ptr()); - BLI_convertstringcode(basedpath, pathname, 0); + // load relative to the last loaded file, this used to be relative + // to the first file but that makes no sense, relative paths in + // blend files should be relative to that file, not some other file + // that happened to be loaded first + BLI_convertstringcode(basedpath, pathname); bfd = load_game_data(basedpath); // if it wasn't loaded, try it forced relative if (!bfd) { // just add "//" in front of it - char temppath[162]; + char temppath[242]; strcpy(temppath, "//"); strcat(temppath, basedpath); - BLI_convertstringcode(temppath, pathname, 0); + BLI_convertstringcode(temppath, pathname); bfd = load_game_data(temppath); } @@ -268,6 +272,11 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, { blenderdata = bfd->main; startscenename = bfd->curscene->id.name + 2; + + if(blenderdata) { + BLI_strncpy(G.sce, blenderdata->name, sizeof(G.sce)); + BLI_strncpy(pathname, blenderdata->name, sizeof(pathname)); + } } // else forget it, we can't find it else @@ -305,12 +314,13 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, if (exitrequested != KX_EXIT_REQUEST_QUIT_GAME) { - if (v3d->persp != 2) + if (v3d->persp != V3D_CAMOB) { ketsjiengine->EnableCameraOverride(startscenename); - ketsjiengine->SetCameraOverrideUseOrtho((v3d->persp == 0)); + ketsjiengine->SetCameraOverrideUseOrtho((v3d->persp == V3D_ORTHO)); ketsjiengine->SetCameraOverrideProjectionMatrix(projmat); ketsjiengine->SetCameraOverrideViewMatrix(viewmat); + ketsjiengine->SetCameraOverrideClipping(v3d->near, v3d->far); } // create a scene converter, create and convert the startingscene @@ -319,25 +329,43 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, sceneconverter->addInitFromFrame=false; if (always_use_expand_framing) sceneconverter->SetAlwaysUseExpandFraming(true); - - if(usemat) + + bool usemat = false, useglslmat = false; + + if(GLEW_ARB_multitexture && GLEW_VERSION_1_1) + usemat = true; + + if(GPU_extensions_minimum_support()) + useglslmat = true; + else if(G.fileflags & G_FILE_GAME_MAT_GLSL) + usemat = false; + + if(usemat && (G.fileflags & G_FILE_GAME_MAT)) sceneconverter->SetMaterials(true); + if(useglslmat && (G.fileflags & G_FILE_GAME_MAT_GLSL)) + sceneconverter->SetGLSLMaterials(true); KX_Scene* startscene = new KX_Scene(keyboarddevice, mousedevice, networkdevice, audiodevice, - startscenename); + startscenename, + blscene); // some python things PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest); ketsjiengine->SetPythonDictionary(dictionaryobject); initRasterizer(rasterizer, canvas); - PyObject *gameLogic = initGameLogic(startscene); + PyObject *gameLogic = initGameLogic(ketsjiengine, startscene); + PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module. + PyObject *gameLogic_keys = PyDict_Keys(PyModule_GetDict(gameLogic)); + PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module. + initGameKeys(); initPythonConstraintBinding(); + initMathutils(); + initVideoTexture(); - if (sceneconverter) { // convert and add scene @@ -356,7 +384,14 @@ 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 + printf("\nBlender Game Engine Started\n\n"); while (!exitrequested) { // first check if we want to exit @@ -392,10 +427,32 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, mousedevice->ConvertBlenderEvent(event,val); } } + printf("\nBlender Game Engine Finished\n\n"); 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)); + + // Keep original items, means python plugins will autocomplete members + int listIndex; + PyObject *gameLogic_keys_new = PyDict_Keys(PyModule_GetDict(gameLogic)); + for (listIndex=0; listIndex < PyList_Size(gameLogic_keys_new); listIndex++) { + PyObject* item = PyList_GET_ITEM(gameLogic_keys_new, listIndex); + if (!PySequence_Contains(gameLogic_keys, item)) { + PyDict_DelItem( PyModule_GetDict(gameLogic), item); + } + } + Py_DECREF(gameLogic_keys_new); + gameLogic_keys_new = NULL; + ketsjiengine->StopEngine(); exitGamePythonScripting(); networkdevice->Disconnect(); @@ -405,7 +462,16 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, delete sceneconverter; sceneconverter = NULL; } + + Py_DECREF(gameLogic_keys); + gameLogic_keys = NULL; + } + //lock frame and camera enabled - restoring global values + if (G.vd->scenelock==0){ + G.scene->lay= tmp_lay; + G.scene->camera= tmp_camera; } + // set the cursor back to normal canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL); @@ -457,6 +523,11 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, } while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME); if (bfd) BLO_blendfiledata_free(bfd); + + BLI_strncpy(G.sce, oldsce, sizeof(G.sce)); + + // Release Python's GIL + PyGILState_Release(gilstate); } extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, @@ -470,12 +541,16 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, Main* blenderdata = maggie; char* startscenename = scenename; - char pathname[160]; - strcpy (pathname, maggie->name); + char pathname[FILE_MAXDIR+FILE_MAXFILE]; STR_String exitstring = ""; - BlendFileData *bfd= NULL; - bgl::InitExtensions(1); + BLI_strncpy(pathname, blenderdata->name, sizeof(pathname)); + + // Acquire Python's GIL (global interpreter lock) + // so we can safely run Python code and API calls + PyGILState_STATE gilstate = PyGILState_Ensure(); + + bgl::InitExtensions(true); do { @@ -496,16 +571,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); @@ -528,24 +601,19 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, // create the ketsjiengine KX_KetsjiEngine* ketsjiengine = new KX_KetsjiEngine(kxsystem); - int i; - Scene *blscene = NULL; - if (!bfd) + + blscene = (Scene*) maggie->scene.first; + for (Scene *sce= (Scene*) maggie->scene.first; sce; sce= (Scene*) sce->id.next) { - blscene = (Scene*) maggie->scene.first; - for (Scene *sce= (Scene*) maggie->scene.first; sce; sce= (Scene*) sce->id.next) + if (startscenename == (sce->id.name+2)) { - if (startscenename == (sce->id.name+2)) - { - blscene = sce; - break; - } + blscene = sce; + break; } - } else { - blscene = bfd->curscene; } - int cframe,startFrame; + + int cframe = 1, startFrame; if (blscene) { cframe=blscene->r.cfra; @@ -576,14 +644,19 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, mousedevice, networkdevice, audiodevice, - startscenename); + startscenename, + blscene); + // some python things PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest); ketsjiengine->SetPythonDictionary(dictionaryobject); initRasterizer(rasterizer, canvas); - PyObject *gameLogic = initGameLogic(startscene); + PyObject *gameLogic = initGameLogic(ketsjiengine, startscene); + PyDict_SetItemString(dictionaryobject, "GameLogic", gameLogic); // Same as importing the module initGameKeys(); initPythonConstraintBinding(); + initMathutils(); + initVideoTexture(); if (sceneconverter) { @@ -661,5 +734,7 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, SND_DeviceManager::Unsubscribe(); } while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME); - if (bfd) BLO_blendfiledata_free(bfd); + + // Release Python's GIL + PyGILState_Release(gilstate); } diff --git a/source/gameengine/BlenderRoutines/CMakeLists.txt b/source/gameengine/BlenderRoutines/CMakeLists.txt index 11a87460f20..2300323a55e 100644 --- a/source/gameengine/BlenderRoutines/CMakeLists.txt +++ b/source/gameengine/BlenderRoutines/CMakeLists.txt @@ -33,8 +33,10 @@ SET(INC ../../../intern/SoundSystem ../../../source/blender/misc ../../../source/blender/blenloader + ../../../source/blender/gpu ../../../extern/bullet2/src ../../../extern/solid + ../../../extern/glew/include ${PYTHON_INC} ) diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp index a65275dda8f..750a1ef3f93 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp @@ -101,6 +101,13 @@ int KX_BlenderCanvas::GetHeight( return 0; //XXX scrarea_get_win_height(m_area); } +RAS_Rect & +KX_BlenderCanvas:: +GetWindowArea( +){ + return m_area_rect; +} + void KX_BlenderCanvas:: SetViewPort( @@ -112,6 +119,11 @@ SetViewPort( int minx = 0;//XXX scrarea_get_win_x(m_area); int miny = 0;//XXX scrarea_get_win_y(m_area); + m_area_rect.SetLeft(minx + x1); + m_area_rect.SetBottom(miny + y1); + m_area_rect.SetRight(minx + x2); + m_area_rect.SetTop(miny + y2); + glViewport(minx + x1, miny + y1, vp_width, vp_height); glScissor(minx + x1, miny + y1, vp_width, vp_height); } diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h index 0b3519efdbd..bc202a8558c 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h @@ -32,11 +32,8 @@ #ifdef WIN32 #include <windows.h> #endif -#ifdef __APPLE__ -#include <OpenGL/gl.h> -#else -#include <GL/gl.h> -#endif + +#include "GL/glew.h" #include "RAS_ICanvas.h" #include "RAS_Rect.h" @@ -120,6 +117,10 @@ public: return m_displayarea; }; + RAS_Rect & + GetWindowArea( + ); + void SetViewPort( int x1, int y1, @@ -162,6 +163,7 @@ public: private: /** Blender area the game engine is running within */ struct ScrArea* m_area; + RAS_Rect m_area_rect; }; #endif // __KX_BLENDERCANVAS diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp index bd3ae4ee912..b3b10e8bf07 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp @@ -44,21 +44,8 @@ #include "BMF_Api.h" +#include "BIF_gl.h" -#ifdef __APPLE__ -#define GL_GLEXT_LEGACY 1 -#include <OpenGL/gl.h> -#include <OpenGL/glu.h> -#else -#include <GL/gl.h> -#if defined(__sun__) && !defined(__sparc__) -#include <mesa/glu.h> -#else -#include <GL/glu.h> -#endif -#endif -#include "RAS_OpenGLRasterizer/RAS_GLExtensionManager.h" -#include "RAS_OpenGLRasterizer/ARB_multitexture.h" #include "BL_Material.h" // MAXTEX /* Data types encoding the game world: */ @@ -77,7 +64,6 @@ #include "BKE_bmfont.h" #include "BKE_image.h" -#include "BIF_gl.h" extern "C" { //XXX #include "BDR_drawmesh.h" //XXX #include "BIF_mywindow.h" @@ -88,12 +74,6 @@ extern "C" { /* end of blender block */ -#ifdef __APPLE__ -#include <OpenGL/gl.h> -#else -#include <GL/gl.h> -#endif - /* was in drawmesh.c */ void spack(unsigned int ucol) { @@ -112,103 +92,40 @@ void BL_SwapBuffers() //XXX myswapbuffers(); } -void BL_RenderText(int mode,const char* textstr,int textlen,struct MTFace* tface, - unsigned int *col,float v1[3],float v2[3],float v3[3],float v4[3]) -{ - Image* ima; - - if(mode & TF_BMFONT) { - //char string[MAX_PROPSTRING]; - int characters, index, character; - float centerx, centery, sizex, sizey, transx, transy, movex, movey, advance; - -// bProperty *prop; - - // string = "Frank van Beek"; - - characters = textlen; - - ima = (struct Image*) tface->tpage; - if (ima == NULL) { - characters = 0; - } - - if(!col) glColor3f(1.0f, 1.0f, 1.0f); - - glPushMatrix(); - for (index = 0; index < characters; index++) { - // lets calculate offset stuff - character = textstr[index]; - - // space starts at offset 1 - // character = character - ' ' + 1; - - matrixGlyph((ImBuf *)ima->ibufs.first, character, & centerx, ¢ery, &sizex, &sizey, &transx, &transy, &movex, &movey, &advance); - - glBegin(GL_POLYGON); - // printf(" %c %f %f %f %f\n", character, tface->uv[0][0], tface->uv[0][1], ); - // glTexCoord2f((tface->uv[0][0] - centerx) * sizex + transx, (tface->uv[0][1] - centery) * sizey + transy); - glTexCoord2f((tface->uv[0][0] - centerx) * sizex + transx, (tface->uv[0][1] - centery) * sizey + transy); - - if(col) spack(col[0]); - // glVertex3fv(v1); - glVertex3f(sizex * v1[0] + movex, sizey * v1[1] + movey, v1[2]); - - glTexCoord2f((tface->uv[1][0] - centerx) * sizex + transx, (tface->uv[1][1] - centery) * sizey + transy); - if(col) spack(col[1]); - // glVertex3fv(v2); - glVertex3f(sizex * v2[0] + movex, sizey * v2[1] + movey, v2[2]); - - glTexCoord2f((tface->uv[2][0] - centerx) * sizex + transx, (tface->uv[2][1] - centery) * sizey + transy); - if(col) spack(col[2]); - // glVertex3fv(v3); - glVertex3f(sizex * v3[0] + movex, sizey * v3[1] + movey, v3[2]); - - if(v4) { - // glTexCoord2f((tface->uv[3][0] - centerx) * sizex + transx, 1.0 - (1.0 - tface->uv[3][1]) * sizey - transy); - glTexCoord2f((tface->uv[3][0] - centerx) * sizex + transx, (tface->uv[3][1] - centery) * sizey + transy); - if(col) spack(col[3]); - // glVertex3fv(v4); - glVertex3f(sizex * v4[0] + movex, sizey * v4[1] + movey, v4[2]); - } - glEnd(); - - glTranslatef(advance, 0.0, 0.0); - } - glPopMatrix(); - - } -} - - void DisableForText() { - if(glIsEnabled(GL_BLEND)) - glDisable(GL_BLEND); + if(glIsEnabled(GL_BLEND)) glDisable(GL_BLEND); + if(glIsEnabled(GL_ALPHA_TEST)) glDisable(GL_ALPHA_TEST); if(glIsEnabled(GL_LIGHTING)) { glDisable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); } -#ifdef GL_ARB_multitexture - for(int i=0; i<MAXTEX; i++) { - if(bgl::RAS_EXT_support._ARB_multitexture) - bgl::blActiveTextureARB(GL_TEXTURE0_ARB+i); -#ifdef GL_ARB_texture_cube_map - if(bgl::RAS_EXT_support._ARB_texture_cube_map) - if(glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB)) - glDisable(GL_TEXTURE_CUBE_MAP_ARB); -#endif + + if(GLEW_ARB_multitexture) { + for(int i=0; i<MAXTEX; i++) { + glActiveTextureARB(GL_TEXTURE0_ARB+i); + + if(GLEW_ARB_texture_cube_map) + if(glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB)) + glDisable(GL_TEXTURE_CUBE_MAP_ARB); + + if(glIsEnabled(GL_TEXTURE_2D)) + glDisable(GL_TEXTURE_2D); + } + + glActiveTextureARB(GL_TEXTURE0_ARB); + } + else { + if(GLEW_ARB_texture_cube_map) + if(glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB)) + glDisable(GL_TEXTURE_CUBE_MAP_ARB); + if(glIsEnabled(GL_TEXTURE_2D)) glDisable(GL_TEXTURE_2D); } -#else//GL_ARB_multitexture - if(glIsEnabled(GL_TEXTURE_2D)) - glDisable(GL_TEXTURE_2D); -#endif } - void BL_print_gamedebug_line(char* text, int xco, int yco, int width, int height) { /* gl prepping */ diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.h b/source/gameengine/BlenderRoutines/KX_BlenderGL.h index c8e0d47afb6..b891a7343c2 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderGL.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.h @@ -46,9 +46,6 @@ void BL_HideMouse(); void BL_NormalMouse(); void BL_WaitMouse(); -void BL_RenderText(int mode,const char* textstr,int textlen,struct MTFace* tface, - unsigned int *col,float v1[3],float v2[3],float v3[3],float v4[3]); - void BL_print_gamedebug_line(char* text, int xco, int yco, int width, int height); void BL_print_gamedebug_line_padded(char* text, int xco, int yco, int width, int height); diff --git a/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.cpp b/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.cpp deleted file mode 100644 index d173b1c66d9..00000000000 --- a/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/** - * $Id$ - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -#include "KX_BlenderPolyMaterial.h" -#include "BKE_mesh.h" - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif -#if 0 -KX_BlenderPolyMaterial::KX_BlenderPolyMaterial(const STR_String &texname, - bool ba, - const STR_String& matname, - int tile, - int tilexrep, - int tileyrep, - int mode, - bool transparant, - bool zsort, - int lightlayer, - bool bIsTriangle, - void* clientobject, - struct MTFace* tface) - : RAS_IPolyMaterial(texname, - false, - matname, - tile, - tilexrep, - tileyrep, - mode, - transparant, - zsort, - lightlayer, - bIsTriangle, - clientobject), - m_tface(tface) -{ -} - -void KX_BlenderPolyMaterial::Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const -{ - - - if (GetCachingInfo() != cachingInfo) - { - if (!cachingInfo) - { - set_tpage(NULL); - } - cachingInfo = GetCachingInfo(); - - if ((m_drawingmode & 4)&& (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED)) - { - update_realtime_texture((struct MTFace*) m_tface, rasty->GetTime()); - set_tpage(m_tface); - rasty->EnableTextures(true); - } - else - { - set_tpage(NULL); - rasty->EnableTextures(false); - } - - if(m_drawingmode & RAS_IRasterizer::KX_TWOSIDE) - { - rasty->SetCullFace(false); - } - else - { - rasty->SetCullFace(true); - } - - if (m_drawingmode & RAS_IRasterizer::KX_LINES) { - rasty->SetLines(true); - } - else { - rasty->SetLines(false); - } - } - - rasty->SetSpecularity(m_specular[0],m_specular[1],m_specular[2],m_specularity); - rasty->SetShinyness(m_shininess); - rasty->SetDiffuse(m_diffuse[0], m_diffuse[1],m_diffuse[2], 1.0); -} - - -#endif - - diff --git a/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.h b/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.h deleted file mode 100644 index 35823b2125b..00000000000 --- a/source/gameengine/BlenderRoutines/KX_BlenderPolyMaterial.h +++ /dev/null @@ -1,99 +0,0 @@ -/** - * $Id$ - * - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. - * All rights reserved. - * - * The Original Code is: all of this file. - * - * Contributor(s): none yet. - * - * ***** END GPL LICENSE BLOCK ***** - */ -#ifndef __KX_BLENDERPOLYMATERIAL -#define __KX_BLENDERPOLYMATERIAL - -#include "RAS_MaterialBucket.h" -#include "RAS_IRasterizer.h" - -struct MTFace; -extern "C" int set_tpage(MTFace* tface); /* Worst hack ever */ - -#if 0 -class KX_BlenderPolyMaterial : public RAS_IPolyMaterial -{ - /** Blender texture face structure. */ - MTFace* m_tface; - -public: - - KX_BlenderPolyMaterial(const STR_String &texname, - bool ba, - const STR_String& matname, - int tile, - int tilexrep, - int tileyrep, - int mode, - bool transparant, - bool zsort, - int lightlayer, - bool bIsTriangle, - void* clientobject, - struct MTFace* tface); - - /** - * Returns the caching information for this material, - * This can be used to speed up the rasterizing process. - * @return The caching information. - */ - virtual TCachingInfo GetCachingInfo(void) const; - - /** - * Activates the material in the (OpenGL) rasterizer. - * On entry, the cachingInfo contains info about the last activated material. - * On exit, the cachingInfo should contain updated info about this material. - * @param rasty The rasterizer in which the material should be active. - * @param cachingInfo The information about the material used to speed up rasterizing. - */ - virtual void Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const; - - /** - * Returns the Blender texture face structure that is used for this material. - * @return The material's texture face. - */ - MTFace* GetMTFace(void) const; -protected: -private: -}; - - -inline MTFace* KX_BlenderPolyMaterial::GetMTFace(void) const -{ - return m_tface; -} - -inline RAS_IPolyMaterial::TCachingInfo KX_BlenderPolyMaterial::GetCachingInfo(void) const -{ - return GetMTFace(); -} - -#endif - -#endif // __KX_BLENDERPOLYMATERIAL - diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp index 6a098cc5491..1797d6c1a0f 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp @@ -26,18 +26,7 @@ * ***** END GPL LICENSE BLOCK ***** */ -#include "KX_BlenderRenderTools.h" - -#ifdef WIN32 -// OpenGL gl.h needs 'windows.h' on windows platforms -#include <windows.h> -#endif //WIN32 -#ifdef __APPLE__ -#define GL_GLEXT_LEGACY 1 -#include <OpenGL/gl.h> -#else -#include <GL/gl.h> -#endif +#include "GL/glew.h" #include "RAS_IRenderTools.h" #include "RAS_IRasterizer.h" @@ -45,24 +34,22 @@ #include "RAS_ICanvas.h" #include "RAS_GLExtensionManager.h" -// next two includes/dependencies come from the shadow feature -// it needs the gameobject and the sumo physics scene for a raycast #include "KX_GameObject.h" - -#include "KX_BlenderPolyMaterial.h" #include "KX_PolygonMaterial.h" #include "KX_BlenderMaterial.h" +#include "KX_RayCast.h" +#include "KX_IPhysicsController.h" -#include "Value.h" +#include "PHY_IPhysicsEnvironment.h" -#include "KX_BlenderGL.h" // for text printing #include "STR_String.h" -#include "RAS_BucketManager.h" // for polymaterial (needed for textprinting) -#include "KX_RayCast.h" -#include "KX_IPhysicsController.h" -#include "PHY_IPhysicsEnvironment.h" -#include "KX_Scene.h" +#include "GPU_draw.h" + +#include "KX_BlenderGL.h" // for text printing +#include "KX_BlenderRenderTools.h" + +unsigned int KX_BlenderRenderTools::m_numgllights; KX_BlenderRenderTools::KX_BlenderRenderTools() { @@ -71,61 +58,98 @@ KX_BlenderRenderTools::KX_BlenderRenderTools() m_numgllights = 8; } -/** -ProcessLighting performs lighting on objects. the layer is a bitfield that contains layer information. -There are 20 'official' layers in blender. -A light is applied on an object only when they are in the same layer. -OpenGL has a maximum of 8 lights (simultaneous), so 20 * 8 lights are possible in a scene. -*/ +KX_BlenderRenderTools::~KX_BlenderRenderTools() +{ +} -int KX_BlenderRenderTools::ProcessLighting(int layer) +void KX_BlenderRenderTools::BeginFrame(RAS_IRasterizer* rasty) { - - int result = false; + m_clientobject = NULL; + m_lastlightlayer = -1; + m_lastlighting = false; + DisableOpenGLLights(); +} - if (layer < 0) - { - DisableOpenGLLights(); - result = false; - } else +void KX_BlenderRenderTools::EndFrame(RAS_IRasterizer* rasty) +{ +} + +/* ProcessLighting performs lighting on objects. the layer is a bitfield that + * contains layer information. There are 20 'official' layers in blender. A + * light is applied on an object only when they are in the same layer. OpenGL + * has a maximum of 8 lights (simultaneous), so 20 * 8 lights are possible in + * a scene. */ + +void KX_BlenderRenderTools::ProcessLighting(int layer, const MT_Transform& viewmat) +{ + if(m_lastlightlayer == layer) + return; + + m_lastlightlayer = layer; + + bool enable = false; + + if (layer >= 0) { if (m_clientobject) { - if (applyLights(layer)) - { - EnableOpenGLLights(); - result = true; - } else - { - DisableOpenGLLights(); - result = false; - } + if (layer == RAS_LIGHT_OBJECT_LAYER) + layer = static_cast<KX_GameObject*>(m_clientobject)->GetLayer(); + + enable = applyLights(layer, viewmat); } } - return result; - - + + if(enable) + EnableOpenGLLights(); + else + DisableOpenGLLights(); } +void KX_BlenderRenderTools::EnableOpenGLLights() +{ + if(m_lastlighting == true) + return; -void KX_BlenderRenderTools::BeginFrame(RAS_IRasterizer* rasty) + glEnable(GL_LIGHTING); + glEnable(GL_COLOR_MATERIAL); + + glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, true); + if (GLEW_EXT_separate_specular_color || GLEW_VERSION_1_2) + glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); + + m_lastlighting = true; +} + +void KX_BlenderRenderTools::DisableOpenGLLights() { - m_clientobject = NULL; - m_lastblenderobject = NULL; - m_lastblenderlights = false; - m_lastlayer = -1; + if(m_lastlighting == false) + return; + + glDisable(GL_LIGHTING); + glDisable(GL_COLOR_MATERIAL); + m_lastlighting = false; - m_modified = true; - DisableOpenGLLights(); +} + +void KX_BlenderRenderTools::SetClientObject(RAS_IRasterizer *rasty, void* obj) +{ + if (m_clientobject != obj) + { + bool ccw = (obj == NULL || !((KX_GameObject*)obj)->IsNegativeScaling()); + rasty->SetFrontFace(ccw); + m_clientobject = obj; + } } -bool KX_BlenderRenderTools::RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data) +bool KX_BlenderRenderTools::RayHit(KX_ClientObjectInfo* client, KX_RayCast* result, void * const data) { double* const oglmatrix = (double* const) data; - MT_Point3 resultpoint(hit_point); - MT_Vector3 resultnormal(hit_normal); + MT_Point3 resultpoint(result->m_hitPoint); + MT_Vector3 resultnormal(result->m_hitNormal); MT_Vector3 left(oglmatrix[0],oglmatrix[1],oglmatrix[2]); MT_Vector3 dir = -(left.cross(resultnormal)).safe_normalized(); left = (dir.cross(resultnormal)).safe_normalized(); @@ -172,7 +196,7 @@ void KX_BlenderRenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmat MT_Vector3 dir = (campos - objpos).safe_normalized(); MT_Vector3 up(0,0,1.0); - KX_GameObject* gameobj = (KX_GameObject*) this->m_clientobject; + KX_GameObject* gameobj = (KX_GameObject*)m_clientobject; // get scaling of halo object MT_Vector3 size = gameobj->GetSGNode()->GetLocalScale(); @@ -208,7 +232,7 @@ void KX_BlenderRenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmat { // shadow must be cast to the ground, physics system needed here! MT_Point3 frompoint(oglmatrix[12],oglmatrix[13],oglmatrix[14]); - KX_GameObject *gameobj = (KX_GameObject*) this->m_clientobject; + KX_GameObject *gameobj = (KX_GameObject*)m_clientobject; MT_Vector3 direction = MT_Vector3(0,0,-1); direction.normalize(); @@ -226,9 +250,8 @@ void KX_BlenderRenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmat if (parent) parent->Release(); - MT_Point3 resultpoint; - MT_Vector3 resultnormal; - if (!KX_RayCast::RayTest(physics_controller, physics_environment, frompoint, topoint, resultpoint, resultnormal, KX_RayCast::Callback<KX_BlenderRenderTools>(this, oglmatrix))) + KX_RayCast::Callback<KX_BlenderRenderTools> callback(this, physics_controller, oglmatrix); + if (!KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback)) { // couldn't find something to cast the shadow on... glMultMatrixd(oglmatrix); @@ -243,13 +266,29 @@ void KX_BlenderRenderTools::applyTransform(RAS_IRasterizer* rasty,double* oglmat } -/** -Render Text renders text into a (series of) polygon, using a texture font, -Each character consists of one polygon (one quad or two triangles) -*/ -void KX_BlenderRenderTools::RenderText(int mode,RAS_IPolyMaterial* polymat,float v1[3],float v2[3],float v3[3],float v4[3]) +void KX_BlenderRenderTools::RenderText2D(RAS_TEXT_RENDER_MODE mode, + const char* text, + int xco, + int yco, + int width, + int height) +{ + STR_String tmpstr(text); + + if(mode == RAS_IRenderTools::RAS_TEXT_PADDED) + BL_print_gamedebug_line_padded(tmpstr.Ptr(), xco, yco, width, height); + else + BL_print_gamedebug_line(tmpstr.Ptr(), xco, yco, width, height); +} + +/* Render Text renders text into a (series of) polygon, using a texture font, + * Each character consists of one polygon (one quad or two triangles) */ + +void KX_BlenderRenderTools::RenderText( + int mode, + RAS_IPolyMaterial* polymat, + float v1[3], float v2[3], float v3[3], float v4[3], int glattrib) { - STR_String mytext = ((CValue*)m_clientobject)->GetPropertyText("Text"); const unsigned int flag = polymat->GetFlag(); @@ -266,67 +305,9 @@ void KX_BlenderRenderTools::RenderText(int mode,RAS_IPolyMaterial* polymat,float col = blenderpoly->GetMCol(); } - BL_RenderText( mode,mytext,mytext.Length(),tface,col,v1,v2,v3,v4); - -} - - - -KX_BlenderRenderTools::~KX_BlenderRenderTools() -{ -}; - - -void KX_BlenderRenderTools::EndFrame(RAS_IRasterizer* rasty) -{ -} - - - -void KX_BlenderRenderTools::DisableOpenGLLights() -{ - glDisable(GL_LIGHTING); - glDisable(GL_COLOR_MATERIAL); -} - - -void KX_BlenderRenderTools::EnableOpenGLLights() -{ - glEnable(GL_LIGHTING); - - glEnable(GL_COLOR_MATERIAL); - glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, true); - if (bgl::QueryExtension(bgl::_GL_EXT_separate_specular_color) || bgl::QueryVersion(1, 2)) - glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); - -} - - -/** - * Rendering text using 2D bitmap functionality. - */ -void KX_BlenderRenderTools::RenderText2D(RAS_TEXT_RENDER_MODE mode, - const char* text, - int xco, - int yco, - int width, - int height) -{ - switch (mode) { - case RAS_IRenderTools::RAS_TEXT_PADDED: { - STR_String tmpstr(text); - BL_print_gamedebug_line_padded(tmpstr.Ptr(),xco,yco,width,height); - break; - } - default: { - STR_String tmpstr(text); - BL_print_gamedebug_line(tmpstr.Ptr(),xco,yco,width,height); - } - } + GPU_render_text(tface, mode, mytext, mytext.Length(), col, v1, v2, v3, v4, glattrib); } - void KX_BlenderRenderTools::PushMatrix() { @@ -339,14 +320,13 @@ void KX_BlenderRenderTools::PopMatrix() } - -int KX_BlenderRenderTools::applyLights(int objectlayer) +int KX_BlenderRenderTools::applyLights(int objectlayer, const MT_Transform& viewmat) { -// taken from blender source, incompatibility between Blender Object / GameObject - + // taken from blender source, incompatibility between Blender Object / GameObject + float glviewmat[16]; unsigned int count; float vec[4]; - + vec[3]= 1.0; for(count=0; count<m_numgllights; count++) @@ -354,9 +334,11 @@ int KX_BlenderRenderTools::applyLights(int objectlayer) //std::vector<struct RAS_LightObject*> m_lights; std::vector<struct RAS_LightObject*>::iterator lit = m_lights.begin(); + + viewmat.getValue(glviewmat); glPushMatrix(); - glLoadMatrixf(m_viewmat); + glLoadMatrixf(glviewmat); for (lit = m_lights.begin(), count = 0; !(lit==m_lights.end()) && count < m_numgllights; ++lit) { RAS_LightObject* lightdata = (*lit); @@ -424,7 +406,6 @@ int KX_BlenderRenderTools::applyLights(int objectlayer) glEnable((GLenum)(GL_LIGHT0+count)); count++; - } } glPopMatrix(); @@ -433,22 +414,6 @@ int KX_BlenderRenderTools::applyLights(int objectlayer) } - - -RAS_IPolyMaterial* KX_BlenderRenderTools::CreateBlenderPolyMaterial( - const STR_String &texname, - bool ba,const STR_String& matname,int tile,int tilexrep,int tileyrep,int mode,bool transparant,bool zsort, int lightlayer - ,bool bIsTriangle,void* clientobject,void* tface) -{ - assert(!"Deprecated"); -/* return new KX_BlenderPolyMaterial( - - texname, - ba,matname,tile,tilexrep,tileyrep,mode,transparant,zsort, lightlayer - ,bIsTriangle,clientobject,(struct MTFace*)tface);*/ - return NULL; -} - void KX_BlenderRenderTools::MotionBlur(RAS_IRasterizer* rasterizer) { int state = rasterizer->GetMotionBlurState(); @@ -472,4 +437,13 @@ void KX_BlenderRenderTools::MotionBlur(RAS_IRasterizer* rasterizer) } } -unsigned int KX_BlenderRenderTools::m_numgllights; +void KX_BlenderRenderTools::Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text) +{ + m_filtermanager.EnableFilter(propNames, gameObj, filtermode, pass, text); +} + +void KX_BlenderRenderTools::Render2DFilters(RAS_ICanvas* canvas) +{ + m_filtermanager.RenderFilters(canvas); +} + diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h index 117d6a2be54..a7618462c9b 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h @@ -26,6 +26,7 @@ * * ***** END GPL LICENSE BLOCK ***** */ + #ifndef __KX_BLENDERRENDERTOOLS #define __KX_BLENDERRENDERTOOLS @@ -37,70 +38,65 @@ #include "RAS_IRenderTools.h" struct KX_ClientObjectInfo; +class KX_RayCast; -/** -BlenderRenderTools are a set of tools to apply 2D/3D graphics effects, which are not -part of the (polygon) Rasterizer. -Effects like 2D text, 3D (polygon) text, lighting. -*/ +/* BlenderRenderTools are a set of tools to apply 2D/3D graphics effects, which + * are not part of the (polygon) Rasterizer. Effects like 2D text, 3D (polygon) + * text, lighting. + * + * Most of this code is duplicated in GPC_RenderTools, so this should be + * moved to some common location to avoid duplication. */ class KX_BlenderRenderTools : public RAS_IRenderTools { - bool m_lastblenderlights; - void* m_lastblenderobject; - int m_lastlayer; + int m_lastlightlayer; bool m_lastlighting; static unsigned int m_numgllights; - + public: - KX_BlenderRenderTools(); virtual ~KX_BlenderRenderTools(); - virtual void EndFrame(class RAS_IRasterizer* rasty); - virtual void BeginFrame(class RAS_IRasterizer* rasty); - void DisableOpenGLLights(); + void EndFrame(RAS_IRasterizer* rasty); + void BeginFrame(RAS_IRasterizer* rasty); + void EnableOpenGLLights(); - int ProcessLighting(int layer); + void DisableOpenGLLights(); + void ProcessLighting(int layer, const MT_Transform& viewmat); - virtual void RenderText2D(RAS_TEXT_RENDER_MODE mode, + void RenderText2D(RAS_TEXT_RENDER_MODE mode, const char* text, int xco, int yco, int width, int height); - virtual void RenderText(int mode, + void RenderText(int mode, class RAS_IPolyMaterial* polymat, float v1[3], float v2[3], float v3[3], - float v4[3]); - void applyTransform(class RAS_IRasterizer* rasty, - double* oglmatrix, - int objectdrawmode ); - int applyLights(int objectlayer); - virtual void PushMatrix(); - virtual void PopMatrix(); - - virtual class RAS_IPolyMaterial* CreateBlenderPolyMaterial(const STR_String &texname, - bool ba, - const STR_String& matname, - int tile, - int tilexrep, - int tileyrep, - int mode, - bool transparant, - bool zsort, - int lightlayer, - bool bIsTriangle, - void* clientobject, - void* tface); - - bool RayHit(KX_ClientObjectInfo* client, MT_Point3& hit_point, MT_Vector3& hit_normal, void * const data); + float v4[3], + int glattrib); + + void applyTransform(RAS_IRasterizer* rasty, double* oglmatrix, int objectdrawmode); + int applyLights(int objectlayer, const MT_Transform& viewmat); + + void PushMatrix(); + void PopMatrix(); + + bool RayHit(KX_ClientObjectInfo* client, class KX_RayCast* result, void * const data); + bool NeedRayCast(KX_ClientObjectInfo*) { return true; } virtual void MotionBlur(RAS_IRasterizer* rasterizer); + + virtual void Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text); + + virtual void Render2DFilters(RAS_ICanvas* canvas); + + virtual void SetClientObject(RAS_IRasterizer *rasty, void* obj); }; #endif //__KX_BLENDERRENDERTOOLS + diff --git a/source/gameengine/BlenderRoutines/Makefile b/source/gameengine/BlenderRoutines/Makefile index 8d7ed46bc28..7ee825d186b 100644 --- a/source/gameengine/BlenderRoutines/Makefile +++ b/source/gameengine/BlenderRoutines/Makefile @@ -35,7 +35,6 @@ include nan_compile.mk CCFLAGS += $(LEVEL_1_CPP_WARNINGS) -CPPFLAGS += -I$(OPENGL_HEADERS) CPPFLAGS += -I$(NAN_SUMO)/include -I$(NAN_SOLID)/include CPPFLAGS += -I$(NAN_SOLID) CPPFLAGS += -I$(NAN_STRING)/include @@ -43,6 +42,8 @@ CPPFLAGS += -I$(NAN_MOTO)/include CPPFLAGS += -I$(NAN_BMFONT)/include CPPFLAGS += -I$(NAN_FUZZICS)/include CPPFLAGS += -I$(NAN_SOUNDSYSTEM)/include +CPPFLAGS += -I$(NAN_GLEW)/include +CPPFLAGS += -I$(OPENGL_HEADERS) # because of kernel dependency on makesdna CPPFLAGS += -I../../blender/makesdna CPPFLAGS += -I../../blender/editors/include @@ -54,6 +55,7 @@ CPPFLAGS += -I../../blender/blenkernel CPPFLAGS += -I../../blender/render/extern/include CPPFLAGS += -I../../blender/blenloader CPPFLAGS += -I../../blender/blenkernel +CPPFLAGS += -I../../blender/gpu CPPFLAGS += -I../Converter CPPFLAGS += -I../Expressions CPPFLAGS += -I../GameLogic @@ -66,6 +68,7 @@ CPPFLAGS += -I../Network CPPFLAGS += -I../Network/LoopBackNetwork CPPFLAGS += -I../Physics/common CPPFLAGS += -I../Physics/Sumo +CPPFLAGS += -I. ifeq ($(OS),windows) CPPFLAGS += -I../../blender diff --git a/source/gameengine/BlenderRoutines/SConscript b/source/gameengine/BlenderRoutines/SConscript index 52d187cbe20..7722b6f69a6 100644 --- a/source/gameengine/BlenderRoutines/SConscript +++ b/source/gameengine/BlenderRoutines/SConscript @@ -15,6 +15,7 @@ incs += ' #source/gameengine/SceneGraph #source/gameengine/Physics/common' incs += ' #source/gameengine/Physics/Bullet #source/gameengine/Physics/Sumo' incs += ' #source/gameengine/Physics/Sumo/Fuzzics/include #source/gameengine/Network/LoopBackNetwork' incs += ' #intern/SoundSystem #source/blender/misc #source/blender/blenloader' +incs += ' #extern/glew/include #source/blender/gpu' incs += ' #source/blender/windowmanager' incs += ' ' + env['BF_PYTHON_INC'] |