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/Ketsji/KX_BlenderMaterial.cpp | |
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/Ketsji/KX_BlenderMaterial.cpp')
-rw-r--r-- | source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 476 |
1 files changed, 309 insertions, 167 deletions
diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index bbf5640f8e0..f92200780d5 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -6,21 +6,7 @@ #include <config.h> #endif -#ifdef WIN32 -#include <windows.h> -#endif // WIN32 -#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 "GL/glew.h" #include "KX_BlenderMaterial.h" #include "BL_Material.h" @@ -33,14 +19,12 @@ #include "MT_Vector4.h" #include "MT_Matrix4x4.h" +#include "RAS_BucketManager.h" #include "RAS_MeshObject.h" #include "RAS_IRasterizer.h" #include "RAS_OpenGLRasterizer/RAS_GLExtensionManager.h" -#include "RAS_OpenGLRasterizer/ARB_multitexture.h" -extern "C" { -//XXX #include "BDR_drawmesh.h" -} +#include "GPU_draw.h" #include "STR_HashedString.h" @@ -51,9 +35,11 @@ extern "C" { #include "DNA_meshdata_types.h" #include "BKE_mesh.h" // ------------------------------------ -using namespace bgl; #define spit(x) std::cout << x << std::endl; +BL_Shader *KX_BlenderMaterial::mLastShader = NULL; +BL_BlenderShader *KX_BlenderMaterial::mLastBlenderShader = NULL; + //static PyObject *gTextureDict = 0; KX_BlenderMaterial::KX_BlenderMaterial( @@ -61,7 +47,6 @@ KX_BlenderMaterial::KX_BlenderMaterial( BL_Material *data, bool skin, int lightlayer, - void *clientobject, PyTypeObject *T ) : PyObjectPlus(T), @@ -72,35 +57,33 @@ KX_BlenderMaterial::KX_BlenderMaterial( data->tilexrep[0], data->tileyrep[0], data->mode, - ((data->ras_mode &TRANSP)!=0), + data->transp, + ((data->ras_mode &ALPHA)!=0), ((data->ras_mode &ZSORT)!=0), - lightlayer, - ((data->ras_mode &TRIANGLE)!=0), - clientobject + lightlayer ), mMaterial(data), mShader(0), + mBlenderShader(0), mScene(scene), mUserDefBlend(0), mModified(0), + mConstructed(false), mPass(0) { // -------------------------------- // RAS_IPolyMaterial variables... - m_flag |=RAS_BLENDERMAT; - m_flag |=(mMaterial->IdMode>=ONETEX)?RAS_MULTITEX:0; - m_flag |=(mMaterial->ras_mode & USE_LIGHT)!=0?RAS_MULTILIGHT:0; - m_flag |=(mMaterial->ras_mode &ALPHA_TEST)!=0?RAS_FORCEALPHA:0; + m_flag |= RAS_BLENDERMAT; + m_flag |= (mMaterial->IdMode>=ONETEX)? RAS_MULTITEX: 0; + m_flag |= ((mMaterial->ras_mode & USE_LIGHT)!=0)? RAS_MULTILIGHT: 0; + m_flag |= (mMaterial->glslmat)? RAS_BLENDERGLSL: 0; // figure max int enabled = mMaterial->num_enabled; int max = BL_Texture::GetMaxUnits(); mMaterial->num_enabled = enabled>=max?max:enabled; - // base class - m_enabled = mMaterial->num_enabled; - // test the sum of the various modes for equality // so we can ether accept or reject this material // as being equal, this is rather important to @@ -111,14 +94,16 @@ KX_BlenderMaterial::KX_BlenderMaterial( mMaterial->blend_mode[i] ); } - m_multimode += mMaterial->IdMode+mMaterial->ras_mode; + m_multimode += mMaterial->IdMode+ (mMaterial->ras_mode & ~(COLLIDER|USE_LIGHT)); } KX_BlenderMaterial::~KX_BlenderMaterial() { // cleanup work - OnExit(); + if (mConstructed) + // clean only if material was actually used + OnExit(); } @@ -137,41 +122,77 @@ unsigned int* KX_BlenderMaterial::GetMCol(void) const void KX_BlenderMaterial::OnConstruction() { + if (mConstructed) + // when material are reused between objects + return; + + if(mMaterial->glslmat) + SetBlenderGLSLShader(); + // for each unique material... int i; for(i=0; i<mMaterial->num_enabled; i++) { if( mMaterial->mapping[i].mapping & USEENV ) { - if(!RAS_EXT_support._ARB_texture_cube_map) { + if(!GLEW_ARB_texture_cube_map) { spit("CubeMap textures not supported"); continue; } if(!mTextures[i].InitCubeMap(i, mMaterial->cubemap[i] ) ) spit("unable to initialize image("<<i<<") in "<< - mMaterial->matname<< ", image will not be available"); + mMaterial->matname<< ", image will not be available"); } else { if( mMaterial->img[i] ) { if( ! mTextures[i].InitFromImage(i, mMaterial->img[i], (mMaterial->flag[i] &MIPMAP)!=0 )) spit("unable to initialize image("<<i<<") in "<< - mMaterial->matname<< ", image will not be available"); + mMaterial->matname<< ", image will not be available"); } } } + mBlendFunc[0] =0; mBlendFunc[1] =0; + mConstructed = true; +} + +void KX_BlenderMaterial::EndFrame() +{ + if(mLastBlenderShader) { + mLastBlenderShader->SetProg(false); + mLastBlenderShader = NULL; + } + + if(mLastShader) { + mLastShader->SetProg(false); + mLastShader = NULL; + } } void KX_BlenderMaterial::OnExit() { if( mShader ) { - //note, the shader here is allocated, per unique material - //and this function is called per face - mShader->SetProg(0); + //note, the shader here is allocated, per unique material + //and this function is called per face + if(mShader == mLastShader) { + mShader->SetProg(false); + mLastShader = NULL; + } + delete mShader; mShader = 0; } + if( mBlenderShader ) { + if(mBlenderShader == mLastBlenderShader) { + mBlenderShader->SetProg(false); + mLastBlenderShader = NULL; + } + + delete mBlenderShader; + mBlenderShader = 0; + } + BL_Texture::ActivateFirst(); for(int i=0; i<mMaterial->num_enabled; i++) { BL_Texture::ActivateUnit(i); @@ -180,24 +201,30 @@ void KX_BlenderMaterial::OnExit() } if( mMaterial->tface ) - ; //XXX set_tpage(mMaterial->tface); + GPU_set_tpage(mMaterial->tface); } void KX_BlenderMaterial::setShaderData( bool enable, RAS_IRasterizer *ras) { - MT_assert(RAS_EXT_support._ARB_shader_objects && mShader); + MT_assert(GLEW_ARB_shader_objects && mShader); int i; if( !enable || !mShader->Ok() ) { // frame cleanup. - mShader->SetProg(false); + if(mShader == mLastShader) { + mShader->SetProg(false); + mLastShader = NULL; + } + + ras->SetBlendingMode(TF_SOLID); BL_Texture::DisableAllTextures(); return; } BL_Texture::DisableAllTextures(); mShader->SetProg(true); + mLastShader = mShader; BL_Texture::ActivateFirst(); @@ -211,29 +238,60 @@ void KX_BlenderMaterial::setShaderData( bool enable, RAS_IRasterizer *ras) } if(!mUserDefBlend) { - setDefaultBlending(); + ras->SetBlendingMode(mMaterial->transp); } else { + ras->SetBlendingMode(TF_SOLID); + ras->SetBlendingMode(-1); // indicates custom mode + // tested to be valid enums glEnable(GL_BLEND); glBlendFunc(mBlendFunc[0], mBlendFunc[1]); } } +void KX_BlenderMaterial::setBlenderShaderData( bool enable, RAS_IRasterizer *ras) +{ + if( !enable || !mBlenderShader->Ok() ) { + ras->SetBlendingMode(TF_SOLID); + + // frame cleanup. + if(mLastBlenderShader) { + mLastBlenderShader->SetProg(false); + mLastBlenderShader= NULL; + } + else + BL_Texture::DisableAllTextures(); + + return; + } + + if(!mBlenderShader->Equals(mLastBlenderShader)) { + ras->SetBlendingMode(mMaterial->transp); + + if(mLastBlenderShader) + mLastBlenderShader->SetProg(false); + else + BL_Texture::DisableAllTextures(); + + mBlenderShader->SetProg(true, ras->GetTime()); + mLastBlenderShader= mBlenderShader; + } +} void KX_BlenderMaterial::setTexData( bool enable, RAS_IRasterizer *ras) { - if(RAS_EXT_support._ARB_shader_objects && mShader) - mShader->SetProg(false); - BL_Texture::DisableAllTextures(); - if( !enable ) + + if( !enable ) { + ras->SetBlendingMode(TF_SOLID); return; + } BL_Texture::ActivateFirst(); if( mMaterial->IdMode == DEFAULT_BLENDER ) { - setDefaultBlending(); + ras->SetBlendingMode(mMaterial->transp); return; } @@ -243,7 +301,7 @@ void KX_BlenderMaterial::setTexData( bool enable, RAS_IRasterizer *ras) mTextures[0].ActivateTexture(); mTextures[0].setTexEnv(0, true); mTextures[0].SetMapping(mMaterial->mapping[0].mapping); - setDefaultBlending(); + ras->SetBlendingMode(mMaterial->transp); } return; } @@ -266,9 +324,12 @@ void KX_BlenderMaterial::setTexData( bool enable, RAS_IRasterizer *ras) } if(!mUserDefBlend) { - setDefaultBlending(); + ras->SetBlendingMode(mMaterial->transp); } else { + ras->SetBlendingMode(TF_SOLID); + ras->SetBlendingMode(-1); // indicates custom mode + glEnable(GL_BLEND); glBlendFunc(mBlendFunc[0], mBlendFunc[1]); } @@ -284,29 +345,31 @@ KX_BlenderMaterial::ActivatShaders( // reset... if(tmp->mMaterial->IsShared()) cachingInfo =0; - + + if(mLastBlenderShader) { + mLastBlenderShader->SetProg(false); + mLastBlenderShader= NULL; + } + if (GetCachingInfo() != cachingInfo) { if (!cachingInfo) - tmp->setShaderData( false, rasty); + tmp->setShaderData(false, rasty); cachingInfo = GetCachingInfo(); - if (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED ) { - tmp->setShaderData( true, rasty); - rasty->EnableTextures(true); - } - else { - tmp->setShaderData( false, rasty); - rasty->EnableTextures(false); - } + if(rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED) + tmp->setShaderData(true, rasty); + else + tmp->setShaderData(false, rasty); if(mMaterial->mode & RAS_IRasterizer::KX_TWOSIDE) rasty->SetCullFace(false); else rasty->SetCullFace(true); - if (((mMaterial->ras_mode &WIRE)!=0) || mMaterial->mode & RAS_IRasterizer::KX_LINES) + if (((mMaterial->ras_mode &WIRE)!=0) || (mMaterial->mode & RAS_IRasterizer::KX_LINES) || + (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME)) { if((mMaterial->ras_mode &WIRE)!=0) rasty->SetCullFace(false); @@ -321,33 +384,84 @@ KX_BlenderMaterial::ActivatShaders( } void +KX_BlenderMaterial::ActivateBlenderShaders( + RAS_IRasterizer* rasty, + TCachingInfo& cachingInfo)const +{ + KX_BlenderMaterial *tmp = const_cast<KX_BlenderMaterial*>(this); + + if(mLastShader) { + mLastShader->SetProg(false); + mLastShader= NULL; + } + + if (GetCachingInfo() != cachingInfo) { + if (!cachingInfo) + tmp->setBlenderShaderData(false, rasty); + + cachingInfo = GetCachingInfo(); + + if(rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED) + tmp->setBlenderShaderData(true, rasty); + else + tmp->setBlenderShaderData(false, rasty); + + if(mMaterial->mode & RAS_IRasterizer::KX_TWOSIDE) + rasty->SetCullFace(false); + else + rasty->SetCullFace(true); + + if (((mMaterial->ras_mode & WIRE)!=0) || (mMaterial->mode & RAS_IRasterizer::KX_LINES) || + (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME)) + { + if((mMaterial->ras_mode &WIRE)!=0) + rasty->SetCullFace(false); + rasty->SetLines(true); + } + else + rasty->SetLines(false); + + ActivatGLMaterials(rasty); + mBlenderShader->SetAttribs(rasty, mMaterial); + } +} + +void KX_BlenderMaterial::ActivateMat( RAS_IRasterizer* rasty, TCachingInfo& cachingInfo )const { KX_BlenderMaterial *tmp = const_cast<KX_BlenderMaterial*>(this); + + if(mLastShader) { + mLastShader->SetProg(false); + mLastShader= NULL; + } + + if(mLastBlenderShader) { + mLastBlenderShader->SetProg(false); + mLastBlenderShader= NULL; + } + if (GetCachingInfo() != cachingInfo) { if (!cachingInfo) tmp->setTexData( false,rasty ); cachingInfo = GetCachingInfo(); - if (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED) { + if (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED) tmp->setTexData( true,rasty ); - rasty->EnableTextures(true); - } - else{ + else tmp->setTexData( false,rasty); - rasty->EnableTextures(false); - } if(mMaterial->mode & RAS_IRasterizer::KX_TWOSIDE) rasty->SetCullFace(false); else rasty->SetCullFace(true); - if (((mMaterial->ras_mode &WIRE)!=0) || mMaterial->mode & RAS_IRasterizer::KX_LINES) + if (((mMaterial->ras_mode &WIRE)!=0) || (mMaterial->mode & RAS_IRasterizer::KX_LINES) || + (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME)) { if((mMaterial->ras_mode &WIRE)!=0) rasty->SetCullFace(false); @@ -356,77 +470,113 @@ KX_BlenderMaterial::ActivateMat( else rasty->SetLines(false); } + ActivatGLMaterials(rasty); ActivateTexGen(rasty); } - bool KX_BlenderMaterial::Activate( RAS_IRasterizer* rasty, TCachingInfo& cachingInfo )const { - bool dopass = false; - if( RAS_EXT_support._ARB_shader_objects && ( mShader && mShader->Ok() ) ) { - if( (mPass++) < mShader->getNumPass() ) { + if(GLEW_ARB_shader_objects && (mShader && mShader->Ok())) { + if((mPass++) < mShader->getNumPass() ) { ActivatShaders(rasty, cachingInfo); - dopass = true; - return dopass; + return true; + } + else { + if(mShader == mLastShader) { + mShader->SetProg(false); + mLastShader = NULL; + } + mPass = 0; + return false; + } + } + else if( GLEW_ARB_shader_objects && (mBlenderShader && mBlenderShader->Ok() ) ) { + if(mPass++ == 0) { + ActivateBlenderShaders(rasty, cachingInfo); + return true; } else { - mShader->SetProg(false); mPass = 0; - dopass = false; - return dopass; + return false; } } else { - switch (mPass++) - { - case 0: - ActivateMat(rasty, cachingInfo); - dopass = true; - break; - default: - mPass = 0; - dopass = false; - break; + if(mPass++ == 0) { + ActivateMat(rasty, cachingInfo); + return true; + } + else { + mPass = 0; + return false; } } - return dopass; } -void KX_BlenderMaterial::ActivateMeshSlot(const KX_MeshSlot & ms, RAS_IRasterizer* rasty) const +bool KX_BlenderMaterial::UsesLighting(RAS_IRasterizer *rasty) const { - if(mShader && RAS_EXT_support._ARB_shader_objects) + if(!RAS_IPolyMaterial::UsesLighting(rasty)) + return false; + + if(mShader && mShader->Ok()) + return true; + else if(mBlenderShader && mBlenderShader->Ok()) + return false; + else + return true; +} + +void KX_BlenderMaterial::ActivateMeshSlot(const RAS_MeshSlot & ms, RAS_IRasterizer* rasty) const +{ + if(mShader && GLEW_ARB_shader_objects) { mShader->Update(ms, rasty); + } + else if(mBlenderShader && GLEW_ARB_shader_objects) { + int blendmode; + + mBlenderShader->Update(ms, rasty); + + /* we do blend modes here, because they can change per object + * with the same material due to obcolor/obalpha */ + blendmode = mBlenderShader->GetBlendMode(); + if((blendmode == TF_SOLID || blendmode == TF_ALPHA) && mMaterial->transp != TF_SOLID) + blendmode = mMaterial->transp; + + rasty->SetBlendingMode(blendmode); + } } void KX_BlenderMaterial::ActivatGLMaterials( RAS_IRasterizer* rasty )const { - rasty->SetSpecularity( - mMaterial->speccolor[0]*mMaterial->spec_f, - mMaterial->speccolor[1]*mMaterial->spec_f, - mMaterial->speccolor[2]*mMaterial->spec_f, - mMaterial->spec_f - ); + if(mShader || !mBlenderShader) { + rasty->SetSpecularity( + mMaterial->speccolor[0]*mMaterial->spec_f, + mMaterial->speccolor[1]*mMaterial->spec_f, + mMaterial->speccolor[2]*mMaterial->spec_f, + mMaterial->spec_f + ); - rasty->SetShinyness( mMaterial->hard ); + rasty->SetShinyness( mMaterial->hard ); - rasty->SetDiffuse( - mMaterial->matcolor[0]*mMaterial->ref+mMaterial->emit, - mMaterial->matcolor[1]*mMaterial->ref+mMaterial->emit, - mMaterial->matcolor[2]*mMaterial->ref+mMaterial->emit, - 1.0f); + rasty->SetDiffuse( + mMaterial->matcolor[0]*mMaterial->ref+mMaterial->emit, + mMaterial->matcolor[1]*mMaterial->ref+mMaterial->emit, + mMaterial->matcolor[2]*mMaterial->ref+mMaterial->emit, + 1.0f); - rasty->SetEmissive( - mMaterial->matcolor[0]*mMaterial->emit, - mMaterial->matcolor[1]*mMaterial->emit, - mMaterial->matcolor[2]*mMaterial->emit, - 1.0 ); + rasty->SetEmissive( + mMaterial->matcolor[0]*mMaterial->emit, + mMaterial->matcolor[1]*mMaterial->emit, + mMaterial->matcolor[2]*mMaterial->emit, + 1.0 ); + + rasty->SetAmbient(mMaterial->amb); + } - rasty->SetAmbient(mMaterial->amb); if (mMaterial->material) rasty->SetPolygonOffset(-mMaterial->material->zoffs, 0.0); } @@ -434,52 +584,43 @@ void KX_BlenderMaterial::ActivatGLMaterials( RAS_IRasterizer* rasty )const void KX_BlenderMaterial::ActivateTexGen(RAS_IRasterizer *ras) const { - if(mShader && RAS_EXT_support._ARB_shader_objects) - if(mShader->GetAttribute() == BL_Shader::SHD_TANGENT) - ras->SetAttrib(RAS_IRasterizer::RAS_TEXTANGENT); + if(ras->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED) { + ras->SetAttribNum(0); + if(mShader && GLEW_ARB_shader_objects) { + if(mShader->GetAttribute() == BL_Shader::SHD_TANGENT) { + ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_DISABLE, 0); + ras->SetAttrib(RAS_IRasterizer::RAS_TEXTANGENT, 1); + ras->SetAttribNum(2); + } + } - for(int i=0; i<mMaterial->num_enabled; i++) { - int mode = mMaterial->mapping[i].mapping; + ras->SetTexCoordNum(mMaterial->num_enabled); - if (mode &USECUSTOMUV) - { - STR_String str = mMaterial->mapping[i].uvCoName; - if (!str.IsEmpty()) - ras->SetTexCoords(RAS_IRasterizer::RAS_TEXCO_UV2, i); - continue; - } + for(int i=0; i<mMaterial->num_enabled; i++) { + int mode = mMaterial->mapping[i].mapping; - if( mode &(USEREFL|USEOBJ)) - ras->SetTexCoords(RAS_IRasterizer::RAS_TEXCO_GEN, i); - else if(mode &USEORCO) - ras->SetTexCoords(RAS_IRasterizer::RAS_TEXCO_ORCO, i); - else if(mode &USENORM) - ras->SetTexCoords(RAS_IRasterizer::RAS_TEXCO_NORM, i); - else if(mode &USEUV) - ras->SetTexCoords(RAS_IRasterizer::RAS_TEXCO_UV1, i); - else if(mode &USETANG) - ras->SetTexCoords(RAS_IRasterizer::RAS_TEXTANGENT, i); - else - ras->SetTexCoords(RAS_IRasterizer::RAS_TEXCO_DISABLE, i); - } -} + if (mode &USECUSTOMUV) + { + STR_String str = mMaterial->mapping[i].uvCoName; + if (!str.IsEmpty()) + ras->SetTexCoord(RAS_IRasterizer::RAS_TEXCO_UV2, i); + continue; + } -bool KX_BlenderMaterial::setDefaultBlending() -{ - if( mMaterial->transp &TF_ADD) { - glEnable(GL_BLEND); - glBlendFunc(GL_ONE, GL_ONE); - return true; - } - - if( mMaterial->transp & TF_ALPHA ) { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - return true; + if( mode &(USEREFL|USEOBJ)) + ras->SetTexCoord(RAS_IRasterizer::RAS_TEXCO_GEN, i); + else if(mode &USEORCO) + ras->SetTexCoord(RAS_IRasterizer::RAS_TEXCO_ORCO, i); + else if(mode &USENORM) + ras->SetTexCoord(RAS_IRasterizer::RAS_TEXCO_NORM, i); + else if(mode &USEUV) + ras->SetTexCoord(RAS_IRasterizer::RAS_TEXCO_UV1, i); + else if(mode &USETANG) + ras->SetTexCoord(RAS_IRasterizer::RAS_TEXTANGENT, i); + else + ras->SetTexCoord(RAS_IRasterizer::RAS_TEXCO_DISABLE, i); + } } - - glDisable(GL_BLEND); - return false; } void KX_BlenderMaterial::setTexMatrixData(int i) @@ -487,8 +628,7 @@ void KX_BlenderMaterial::setTexMatrixData(int i) glMatrixMode(GL_TEXTURE); glLoadIdentity(); -#ifdef GL_ARB_texture_cube_map - if( RAS_EXT_support._ARB_texture_cube_map && + if( GLEW_ARB_texture_cube_map && mTextures[i].GetTextureType() == GL_TEXTURE_CUBE_MAP_ARB && mMaterial->mapping[i].mapping & USEREFL) { glScalef( @@ -498,7 +638,6 @@ void KX_BlenderMaterial::setTexMatrixData(int i) ); } else -#endif { glScalef( mMaterial->mapping[i].scale[0], @@ -556,8 +695,7 @@ void KX_BlenderMaterial::setObjectMatrixData(int i, RAS_IRasterizer *ras) glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_GEN_R); - MT_Matrix4x4 mvmat; - ras->GetViewMatrix(mvmat); + const MT_Matrix4x4& mvmat = ras->GetViewMatrix(); glMatrixMode(GL_TEXTURE); glLoadIdentity(); @@ -647,28 +785,23 @@ int KX_BlenderMaterial::_setattr(const STR_String& attr, PyObject *pyvalue) KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()") { -#ifdef GL_ARB_fragment_shader - if( !RAS_EXT_support._ARB_fragment_shader) { + if( !GLEW_ARB_fragment_shader) { if(!mModified) spit("Fragment shaders not supported"); mModified = true; Py_Return; } -#endif -#ifdef GL_ARB_vertex_shader - if( !RAS_EXT_support._ARB_vertex_shader) { + if( !GLEW_ARB_vertex_shader) { if(!mModified) spit("Vertex shaders not supported"); mModified = true; Py_Return; } -#endif -#ifdef GL_ARB_shader_objects - if(!RAS_EXT_support._ARB_shader_objects) { + if(!GLEW_ARB_shader_objects) { if(!mModified) spit("GLSL not supported"); mModified = true; @@ -684,7 +817,9 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()") } if(mShader && !mShader->GetError()) { + m_flag &= ~RAS_BLENDERGLSL; mMaterial->SetSharedMaterial(true); + mScene->GetBucketManager()->ReleaseDisplayLists(this); Py_INCREF(mShader); return mShader; }else @@ -707,13 +842,20 @@ KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()") } PyErr_Format(PyExc_ValueError, "GLSL Error"); return NULL; - -#else - Py_Return; -#endif//GL_ARB_shader_objects } +void KX_BlenderMaterial::SetBlenderGLSLShader(void) +{ + if(!mBlenderShader) + mBlenderShader = new BL_BlenderShader(mScene, mMaterial->material, m_lightlayer); + + if(!mBlenderShader->Ok()) { + delete mBlenderShader; + mBlenderShader = 0; + } +} + KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getMaterialIndex, "getMaterialIndex()") { return PyInt_FromLong( mMaterial->material_index ); |