diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-04-20 19:06:46 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2009-04-20 19:06:46 +0400 |
commit | 874c29cea8e6f9bc411fccf2d6f4cb07e94328d0 (patch) | |
tree | 5971e577cf7c02e05a1e37b5ad058c71a6744877 /source/gameengine/BlenderRoutines | |
parent | 7555bfa793a2b0fc187c6211c56986f35b2d7b09 (diff) | |
parent | c5bc4e4fb1a33eda8c31f2ea02e91f32f74c8fa5 (diff) |
2.50: svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r19323:HEAD
Notes:
* blenderbuttons and ICON_SNAP_PEEL_OBJECT were not merged.
Diffstat (limited to 'source/gameengine/BlenderRoutines')
5 files changed, 107 insertions, 82 deletions
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp index 90d5a1860aa..d8de24c610c 100644 --- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp +++ b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp @@ -369,7 +369,7 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, blscene); // some python things - PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest); + PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest, blenderdata); ketsjiengine->SetPythonDictionary(dictionaryobject); initRasterizer(rasterizer, canvas); PyObject *gameLogic = initGameLogic(ketsjiengine, startscene); @@ -380,10 +380,15 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, initGameKeys(); initPythonConstraintBinding(); initMathutils(); + initBGL(); #ifdef WITH_FFMPEG initVideoTexture(); #endif + //initialize Dome Settings + if(blscene->r.stereomode == RAS_IRasterizer::RAS_STEREO_DOME) + ketsjiengine->InitDome(blscene->r.domesize, blscene->r.domeres, blscene->r.domemode, blscene->r.domeangle, blscene->r.domeresbuf, blscene->r.dometext); + if (sceneconverter) { // convert and add scene @@ -539,7 +544,9 @@ extern "C" void StartKetsjiShell(struct ScrArea *area, SND_DeviceManager::Unsubscribe(); } while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME); - + + Py_DECREF(pyGlobalDict); + if (bfd) BLO_blendfiledata_free(bfd); BLI_strncpy(G.sce, oldsce, sizeof(G.sce)); @@ -669,7 +676,7 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, blscene); // some python things - PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest); + PyObject* dictionaryobject = initGamePythonScripting("Ketsji", psl_Lowest, blenderdata); ketsjiengine->SetPythonDictionary(dictionaryobject); initRasterizer(rasterizer, canvas); PyObject *gameLogic = initGameLogic(ketsjiengine, startscene); @@ -677,6 +684,7 @@ extern "C" void StartKetsjiShellSimulation(struct ScrArea *area, initGameKeys(); initPythonConstraintBinding(); initMathutils(); + initBGL(); #ifdef WITH_FFMPEG initVideoTexture(); #endif diff --git a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp index b3b10e8bf07..648ad79210e 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderGL.cpp @@ -44,7 +44,7 @@ #include "BMF_Api.h" -#include "BIF_gl.h" +#include "GL/glew.h" #include "BL_Material.h" // MAXTEX diff --git a/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp b/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp index 4b794380610..877a0d39acf 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp @@ -74,7 +74,7 @@ void KX_BlenderKeyboardDevice::NextFrame() // now convert justpressed keyevents into regular (active) keyevents int previousTable = 1-m_currentTable; - for (int keyevent= KX_BEGINKEY; keyevent< KX_ENDKEY;keyevent++) + for (int keyevent= KX_BEGINKEY; keyevent<= KX_ENDKEY;keyevent++) { SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][keyevent]; if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED || @@ -100,7 +100,7 @@ bool KX_BlenderKeyboardDevice::ConvertBlenderEvent(unsigned short incode,short v KX_EnumInputs kxevent = this->ToNative(incode); // only process it, if it's a key - if (kxevent >= KX_BEGINKEY && kxevent < KX_ENDKEY) + if (kxevent >= KX_BEGINKEY && kxevent <= KX_ENDKEY) { int previousTable = 1-m_currentTable; diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp index 42ad7769cbd..9dbda3f195b 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp @@ -28,6 +28,8 @@ #include "GL/glew.h" +#include "DNA_scene_types.h" + #include "RAS_IRenderTools.h" #include "RAS_IRasterizer.h" #include "RAS_LightObject.h" @@ -67,6 +69,7 @@ void KX_BlenderRenderTools::BeginFrame(RAS_IRasterizer* rasty) m_clientobject = NULL; m_lastlightlayer = -1; m_lastlighting = false; + m_lastauxinfo = NULL; DisableOpenGLLights(); } @@ -80,25 +83,27 @@ void KX_BlenderRenderTools::EndFrame(RAS_IRasterizer* rasty) * has a maximum of 8 lights (simultaneous), so 20 * 8 lights are possible in * a scene. */ -void KX_BlenderRenderTools::ProcessLighting(RAS_IRasterizer *rasty, int layer, const MT_Transform& viewmat) +void KX_BlenderRenderTools::ProcessLighting(RAS_IRasterizer *rasty, bool uselights, const MT_Transform& viewmat) { - if(m_lastlightlayer == layer) - return; + bool enable = false; + int layer= -1; - m_lastlightlayer = layer; + /* find the layer */ + if(uselights) { + if(m_clientobject) + layer = static_cast<KX_GameObject*>(m_clientobject)->GetLayer(); + } - bool enable = false; + /* avoid state switching */ + if(m_lastlightlayer == layer && m_lastauxinfo == m_auxilaryClientInfo) + return; - if (layer >= 0) - { - if (m_clientobject) - { - if (layer == RAS_LIGHT_OBJECT_LAYER) - layer = static_cast<KX_GameObject*>(m_clientobject)->GetLayer(); + m_lastlightlayer = layer; + m_lastauxinfo = m_auxilaryClientInfo; - enable = applyLights(layer, viewmat); - } - } + /* enable/disable lights as needed */ + if(layer >= 0) + enable = applyLights(layer, viewmat); if(enable) EnableOpenGLLights(rasty); @@ -324,11 +329,16 @@ void KX_BlenderRenderTools::PopMatrix() int KX_BlenderRenderTools::applyLights(int objectlayer, const MT_Transform& viewmat) { // taken from blender source, incompatibility between Blender Object / GameObject + KX_Scene* kxscene = (KX_Scene*)m_auxilaryClientInfo; + int scenelayer = ~0; float glviewmat[16]; unsigned int count; float vec[4]; vec[3]= 1.0; + + if(kxscene && kxscene->GetBlenderScene()) + scenelayer = kxscene->GetBlenderScene()->lay; for(count=0; count<m_numgllights; count++) glDisable((GLenum)(GL_LIGHT0+count)); @@ -343,71 +353,77 @@ int KX_BlenderRenderTools::applyLights(int objectlayer, const MT_Transform& view for (lit = m_lights.begin(), count = 0; !(lit==m_lights.end()) && count < m_numgllights; ++lit) { RAS_LightObject* lightdata = (*lit); - if (lightdata->m_layer & objectlayer) - { - vec[0] = (*(lightdata->m_worldmatrix))(0,3); - vec[1] = (*(lightdata->m_worldmatrix))(1,3); - vec[2] = (*(lightdata->m_worldmatrix))(2,3); - vec[3] = 1; + KX_Scene* lightscene = (KX_Scene*)lightdata->m_scene; - if(lightdata->m_type==RAS_LightObject::LIGHT_SUN) { - - vec[0] = (*(lightdata->m_worldmatrix))(0,2); - vec[1] = (*(lightdata->m_worldmatrix))(1,2); - vec[2] = (*(lightdata->m_worldmatrix))(2,2); - //vec[0]= base->object->obmat[2][0]; - //vec[1]= base->object->obmat[2][1]; - //vec[2]= base->object->obmat[2][2]; - vec[3]= 0.0; - glLightfv((GLenum)(GL_LIGHT0+count), GL_POSITION, vec); - } - else { - //vec[3]= 1.0; - glLightfv((GLenum)(GL_LIGHT0+count), GL_POSITION, vec); - glLightf((GLenum)(GL_LIGHT0+count), GL_CONSTANT_ATTENUATION, 1.0); - glLightf((GLenum)(GL_LIGHT0+count), GL_LINEAR_ATTENUATION, lightdata->m_att1/lightdata->m_distance); - // without this next line it looks backward compatible. - //attennuation still is acceptable - glLightf((GLenum)(GL_LIGHT0+count), GL_QUADRATIC_ATTENUATION, lightdata->m_att2/(lightdata->m_distance*lightdata->m_distance)); - - if(lightdata->m_type==RAS_LightObject::LIGHT_SPOT) { - vec[0] = -(*(lightdata->m_worldmatrix))(0,2); - vec[1] = -(*(lightdata->m_worldmatrix))(1,2); - vec[2] = -(*(lightdata->m_worldmatrix))(2,2); - //vec[0]= -base->object->obmat[2][0]; - //vec[1]= -base->object->obmat[2][1]; - //vec[2]= -base->object->obmat[2][2]; - glLightfv((GLenum)(GL_LIGHT0+count), GL_SPOT_DIRECTION, vec); - glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_CUTOFF, lightdata->m_spotsize/2.0); - glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_EXPONENT, 128.0*lightdata->m_spotblend); - } - else glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_CUTOFF, 180.0); - } + /* only use lights in the same layer as the object */ + if(!(lightdata->m_layer & objectlayer)) + continue; + /* only use lights in the same scene, and in a visible layer */ + if(kxscene != lightscene || !(lightdata->m_layer & scenelayer)) + continue; + + vec[0] = (*(lightdata->m_worldmatrix))(0,3); + vec[1] = (*(lightdata->m_worldmatrix))(1,3); + vec[2] = (*(lightdata->m_worldmatrix))(2,3); + vec[3] = 1; + + if(lightdata->m_type==RAS_LightObject::LIGHT_SUN) { - if (lightdata->m_nodiffuse) - { - vec[0] = vec[1] = vec[2] = vec[3] = 0.0; - } else { - vec[0]= lightdata->m_energy*lightdata->m_red; - vec[1]= lightdata->m_energy*lightdata->m_green; - vec[2]= lightdata->m_energy*lightdata->m_blue; - vec[3]= 1.0; - } - glLightfv((GLenum)(GL_LIGHT0+count), GL_DIFFUSE, vec); - if (lightdata->m_nospecular) - { - vec[0] = vec[1] = vec[2] = vec[3] = 0.0; - } else if (lightdata->m_nodiffuse) { - vec[0]= lightdata->m_energy*lightdata->m_red; - vec[1]= lightdata->m_energy*lightdata->m_green; - vec[2]= lightdata->m_energy*lightdata->m_blue; - vec[3]= 1.0; + vec[0] = (*(lightdata->m_worldmatrix))(0,2); + vec[1] = (*(lightdata->m_worldmatrix))(1,2); + vec[2] = (*(lightdata->m_worldmatrix))(2,2); + //vec[0]= base->object->obmat[2][0]; + //vec[1]= base->object->obmat[2][1]; + //vec[2]= base->object->obmat[2][2]; + vec[3]= 0.0; + glLightfv((GLenum)(GL_LIGHT0+count), GL_POSITION, vec); + } + else { + //vec[3]= 1.0; + glLightfv((GLenum)(GL_LIGHT0+count), GL_POSITION, vec); + glLightf((GLenum)(GL_LIGHT0+count), GL_CONSTANT_ATTENUATION, 1.0); + glLightf((GLenum)(GL_LIGHT0+count), GL_LINEAR_ATTENUATION, lightdata->m_att1/lightdata->m_distance); + // without this next line it looks backward compatible. + //attennuation still is acceptable + glLightf((GLenum)(GL_LIGHT0+count), GL_QUADRATIC_ATTENUATION, lightdata->m_att2/(lightdata->m_distance*lightdata->m_distance)); + + if(lightdata->m_type==RAS_LightObject::LIGHT_SPOT) { + vec[0] = -(*(lightdata->m_worldmatrix))(0,2); + vec[1] = -(*(lightdata->m_worldmatrix))(1,2); + vec[2] = -(*(lightdata->m_worldmatrix))(2,2); + //vec[0]= -base->object->obmat[2][0]; + //vec[1]= -base->object->obmat[2][1]; + //vec[2]= -base->object->obmat[2][2]; + glLightfv((GLenum)(GL_LIGHT0+count), GL_SPOT_DIRECTION, vec); + glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_CUTOFF, lightdata->m_spotsize/2.0); + glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_EXPONENT, 128.0*lightdata->m_spotblend); } - glLightfv((GLenum)(GL_LIGHT0+count), GL_SPECULAR, vec); - glEnable((GLenum)(GL_LIGHT0+count)); - - count++; + else glLightf((GLenum)(GL_LIGHT0+count), GL_SPOT_CUTOFF, 180.0); + } + + if (lightdata->m_nodiffuse) + { + vec[0] = vec[1] = vec[2] = vec[3] = 0.0; + } else { + vec[0]= lightdata->m_energy*lightdata->m_red; + vec[1]= lightdata->m_energy*lightdata->m_green; + vec[2]= lightdata->m_energy*lightdata->m_blue; + vec[3]= 1.0; + } + glLightfv((GLenum)(GL_LIGHT0+count), GL_DIFFUSE, vec); + if (lightdata->m_nospecular) + { + vec[0] = vec[1] = vec[2] = vec[3] = 0.0; + } else if (lightdata->m_nodiffuse) { + vec[0]= lightdata->m_energy*lightdata->m_red; + vec[1]= lightdata->m_energy*lightdata->m_green; + vec[2]= lightdata->m_energy*lightdata->m_blue; + vec[3]= 1.0; } + glLightfv((GLenum)(GL_LIGHT0+count), GL_SPECULAR, vec); + glEnable((GLenum)(GL_LIGHT0+count)); + + count++; } glPopMatrix(); diff --git a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h index ebf7562503f..60130e6bfc9 100644 --- a/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h +++ b/source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h @@ -51,6 +51,7 @@ class KX_BlenderRenderTools : public RAS_IRenderTools { int m_lastlightlayer; bool m_lastlighting; + void *m_lastauxinfo; static unsigned int m_numgllights; public: @@ -62,7 +63,7 @@ public: void EnableOpenGLLights(RAS_IRasterizer *rasty); void DisableOpenGLLights(); - void ProcessLighting(RAS_IRasterizer *rasty, int layer, const MT_Transform& viewmat); + void ProcessLighting(RAS_IRasterizer *rasty, bool uselights, const MT_Transform& viewmat); void RenderText2D(RAS_TEXT_RENDER_MODE mode, const char* text, |