diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-07-07 21:14:44 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-07-07 21:14:44 +0400 |
commit | f26485d28da12e861c36ae0f2c03343ec24b7338 (patch) | |
tree | cf514723ac5caa92f16b175b7ec948c4d742cbbe | |
parent | e232ea3a4f052b9106bbc3d902f7ee9106b52595 (diff) |
Apricot Branch: two minor optimizations to avoid unneeded shader
and opengl light state changes.
-rw-r--r-- | source/blender/gpu/intern/gpu_material.c | 2 | ||||
-rw-r--r-- | source/gameengine/Ketsji/BL_BlenderShader.cpp | 6 | ||||
-rw-r--r-- | source/gameengine/Ketsji/BL_BlenderShader.h | 4 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_BlenderMaterial.cpp | 17 | ||||
-rw-r--r-- | source/gameengine/Ketsji/KX_BlenderMaterial.h | 1 | ||||
-rw-r--r-- | source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp | 16 | ||||
-rw-r--r-- | source/gameengine/Rasterizer/RAS_IPolygonMaterial.h | 2 | ||||
-rw-r--r-- | source/gameengine/Rasterizer/RAS_MaterialBucket.cpp | 14 |
8 files changed, 46 insertions, 16 deletions
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c index a26602225a3..ee063cd0c38 100644 --- a/source/blender/gpu/intern/gpu_material.c +++ b/source/blender/gpu/intern/gpu_material.c @@ -1184,7 +1184,7 @@ void GPU_lamp_shadow_buffer_unbind(GPULamp *lamp) int GPU_lamp_shadow_layer(GPULamp *lamp) { - if(lamp->fb && lamp->tex && (lamp->mode & LA_LAYER|LA_LAYER_SHADOW)) + if(lamp->fb && lamp->tex && (lamp->mode & (LA_LAYER|LA_LAYER_SHADOW))) return lamp->lay; else return -1; diff --git a/source/gameengine/Ketsji/BL_BlenderShader.cpp b/source/gameengine/Ketsji/BL_BlenderShader.cpp index 70a5c7d65c3..208cae1fa29 100644 --- a/source/gameengine/Ketsji/BL_BlenderShader.cpp +++ b/source/gameengine/Ketsji/BL_BlenderShader.cpp @@ -137,4 +137,10 @@ void BL_BlenderShader::Update( const KX_MeshSlot & ms, RAS_IRasterizer* rasty ) GPU_material_bind_uniforms(mGPUMat, obmat, viewmat); } +bool BL_BlenderShader::Identical(BL_BlenderShader *blshader) +{ + /* to avoid unneeded state switches */ + return (blshader && mGPUMat == blshader->mGPUMat && mLightLayer == blshader->mLightLayer); +} + // eof diff --git a/source/gameengine/Ketsji/BL_BlenderShader.h b/source/gameengine/Ketsji/BL_BlenderShader.h index 79e92347704..112c2a7c327 100644 --- a/source/gameengine/Ketsji/BL_BlenderShader.h +++ b/source/gameengine/Ketsji/BL_BlenderShader.h @@ -10,6 +10,8 @@ #include "MT_Tuple3.h" #include "MT_Tuple4.h" +#include "RAS_IPolygonMaterial.h" + struct Material; class BL_Material; @@ -36,6 +38,8 @@ public: int GetAttribNum(); void SetAttribs(class RAS_IRasterizer* ras, const BL_Material *mat); void Update(const class KX_MeshSlot & ms, class RAS_IRasterizer* rasty); + + bool Identical(BL_BlenderShader *blshader); }; #endif//__BL_GPUSHADER_H__ diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp index ebd465601bf..824cdce7e65 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp @@ -238,8 +238,9 @@ void KX_BlenderMaterial::setBlenderShaderData( bool enable, RAS_IRasterizer *ras return; } - BL_Texture::DisableAllTextures(); - if(mBlenderShader != mLastBlenderShader) { + if(!mBlenderShader->Identical(mLastBlenderShader)) { + BL_Texture::DisableAllTextures(); + if(mLastBlenderShader) mLastBlenderShader->SetProg(false); @@ -484,6 +485,18 @@ KX_BlenderMaterial::Activate( return dopass; } +bool KX_BlenderMaterial::UsesLighting(RAS_IRasterizer *rasty) const +{ + if(!RAS_IPolyMaterial::UsesLighting(rasty)) + return false; + + if(mShader && mShader->Ok()); + else if(mBlenderShader && mBlenderShader->Ok()) + return false; + + return true; +} + void KX_BlenderMaterial::ActivateMeshSlot(const KX_MeshSlot & ms, RAS_IRasterizer* rasty) const { if(mShader && GLEW_ARB_shader_objects) diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.h b/source/gameengine/Ketsji/KX_BlenderMaterial.h index ee293f08682..bf6d2095e7c 100644 --- a/source/gameengine/Ketsji/KX_BlenderMaterial.h +++ b/source/gameengine/Ketsji/KX_BlenderMaterial.h @@ -107,6 +107,7 @@ private: void ActivatGLMaterials( RAS_IRasterizer* rasty )const; void ActivateTexGen( RAS_IRasterizer *ras ) const; + bool UsesLighting(RAS_IRasterizer *rasty) const; // message centers void setTexData( bool enable,RAS_IRasterizer *ras); diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp index bff98abe058..cb10ba6bf37 100644 --- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp +++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp @@ -27,6 +27,7 @@ */ #include "RAS_IPolygonMaterial.h" +#include "RAS_IRasterizer.h" #ifdef HAVE_CONFIG_H #include <config.h> @@ -148,4 +149,19 @@ const unsigned int RAS_IPolyMaterial::GetFlag() const return m_flag; } +bool RAS_IPolyMaterial::UsesLighting(RAS_IRasterizer *rasty) const +{ + bool dolights = false; + + if(m_flag & RAS_BLENDERMAT) + dolights = (m_flag &RAS_MULTILIGHT)!=0; + else if(rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID); + else if(rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW); + else + dolights = (m_drawingmode & 16)!=0; + + return dolights; +} + unsigned int RAS_IPolyMaterial::m_newpolymatid = 0; + diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h index 09824f6975c..d2d1dba99d9 100644 --- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h +++ b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h @@ -140,6 +140,8 @@ public: const STR_String& GetMaterialName() const; const STR_String& GetTextureName() const; const unsigned int GetFlag() const; + + virtual bool UsesLighting(RAS_IRasterizer *rasty) const; /* * PreCalculate texture gen diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp index fe4f56568bf..705b3ea47d7 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp @@ -174,19 +174,7 @@ bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_I if (!rasty->SetMaterial(*m_material)) return false; - bool dolights = false; - const unsigned int flag = m_material->GetFlag(); - - if( flag & RAS_BLENDERMAT) - dolights = (flag &RAS_MULTILIGHT)!=0; - else if(rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID) - dolights = false; - else if(rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW) - dolights = false; - else - dolights = (m_material->GetDrawingMode()&16)!=0; - - if (dolights) + if (m_material->UsesLighting(rasty)) rendertools->ProcessLighting(RAS_IRenderTools::RAS_LIGHT_OBJECT_LAYER/*m_material->GetLightLayer()*/); else rendertools->ProcessLighting(-1); |