diff options
Diffstat (limited to 'source/gameengine/Rasterizer')
15 files changed, 104 insertions, 41 deletions
diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp index 282c7306285..176da51b183 100644 --- a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp +++ b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp @@ -435,11 +435,12 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) glViewport(0,0, texturewidth, textureheight); glDisable(GL_DEPTH_TEST); + glPushMatrix(); //GL_MODELVIEW + glLoadIdentity(); // GL_MODELVIEW glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glMatrixMode(GL_MODELVIEW); + glPushMatrix(); glLoadIdentity(); for(passindex =0; passindex<MAX_RENDER_PASS; passindex++) @@ -466,6 +467,9 @@ void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas) glEnable(GL_DEPTH_TEST); glViewport(viewport[0],viewport[1],viewport[2],viewport[3]); EndShaderProgram(); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); } void RAS_2DFilterManager::EnableFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFILTER_MODE mode, int pass, STR_String& text) diff --git a/source/gameengine/Rasterizer/RAS_BucketManager.cpp b/source/gameengine/Rasterizer/RAS_BucketManager.cpp index f7938bb62e6..ec290f89d9e 100644 --- a/source/gameengine/Rasterizer/RAS_BucketManager.cpp +++ b/source/gameengine/Rasterizer/RAS_BucketManager.cpp @@ -148,6 +148,10 @@ void RAS_BucketManager::RenderAlphaBuckets( while(sit->m_bucket->ActivateMaterial(cameratrans, rasty, rendertools)) sit->m_bucket->RenderMeshSlot(cameratrans, rasty, rendertools, *(sit->m_ms)); + + // make this mesh slot culled automatically for next frame + // it will be culled out by frustrum culling + sit->m_ms->SetCulled(true); } rasty->SetDepthMask(RAS_IRasterizer::KX_DEPTHMASK_ENABLED); @@ -170,6 +174,10 @@ void RAS_BucketManager::RenderSolidBuckets( while ((*bit)->ActivateMaterial(cameratrans, rasty, rendertools)) (*bit)->RenderMeshSlot(cameratrans, rasty, rendertools, *mit); + + // make this mesh slot culled automatically for next frame + // it will be culled out by frustrum culling + mit->SetCulled(true); } } diff --git a/source/gameengine/Rasterizer/RAS_FramingManager.h b/source/gameengine/Rasterizer/RAS_FramingManager.h index 610bd13ff12..0a226ac30f9 100644 --- a/source/gameengine/Rasterizer/RAS_FramingManager.h +++ b/source/gameengine/Rasterizer/RAS_FramingManager.h @@ -163,6 +163,13 @@ struct RAS_FrameFrustum float x2,y2; }; +/* must match R_CULLING_... from DNA_scene_types.h */ +enum RAS_CullingMode +{ + RAS_CULLING_DBVT = 0, + RAS_CULLING_NORMAL, + RAS_CULLING_NONE +}; /** * @section RAS_FramingManager diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h index 83adcfd8321..cfeda06e670 100644 --- a/source/gameengine/Rasterizer/RAS_IRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h @@ -113,6 +113,7 @@ public: RAS_STEREO_ANAGLYPH, RAS_STEREO_SIDEBYSIDE, RAS_STEREO_VINTERLACE, + RAS_STEREO_DOME, RAS_STEREO_MAXSTEREO }; diff --git a/source/gameengine/Rasterizer/RAS_IRenderTools.h b/source/gameengine/Rasterizer/RAS_IRenderTools.h index a289ffed492..52f6397cf6c 100644 --- a/source/gameengine/Rasterizer/RAS_IRenderTools.h +++ b/source/gameengine/Rasterizer/RAS_IRenderTools.h @@ -58,10 +58,6 @@ public: RAS_TEXT_PADDED, RAS_TEXT_MAX }; - enum RAS_LIGHT_MODE { - RAS_LIGHT_NONE = -1, - RAS_LIGHT_OBJECT_LAYER = 0 - }; RAS_IRenderTools( ) : @@ -135,7 +131,7 @@ public: void ProcessLighting( RAS_IRasterizer *rasty, - int layer, + bool uselights, const MT_Transform& trans )=0; diff --git a/source/gameengine/Rasterizer/RAS_LightObject.h b/source/gameengine/Rasterizer/RAS_LightObject.h index 4c54857dc39..6b63a891981 100644 --- a/source/gameengine/Rasterizer/RAS_LightObject.h +++ b/source/gameengine/Rasterizer/RAS_LightObject.h @@ -40,6 +40,7 @@ struct RAS_LightObject }; bool m_modified; int m_layer; + void *m_scene; float m_energy; float m_distance; diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp index d8631c1edf6..6beab28d61f 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp @@ -60,12 +60,14 @@ RAS_MeshSlot::RAS_MeshSlot() RAS_MeshSlot::~RAS_MeshSlot() { - vector<RAS_DisplayArray*>::iterator it; + RAS_DisplayArrayList::iterator it; +#ifdef USE_SPLIT Split(true); while(m_joinedSlots.size()) m_joinedSlots.front()->Split(true); +#endif for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) { (*it)->m_users--; @@ -81,7 +83,7 @@ RAS_MeshSlot::~RAS_MeshSlot() RAS_MeshSlot::RAS_MeshSlot(const RAS_MeshSlot& slot) { - vector<RAS_DisplayArray*>::iterator it; + RAS_DisplayArrayList::iterator it; m_clientObj = NULL; m_pDeformer = NULL; @@ -203,7 +205,7 @@ RAS_DisplayArray *RAS_MeshSlot::CurrentDisplayArray() void RAS_MeshSlot::SetDisplayArray(int numverts) { - vector<RAS_DisplayArray*>::iterator it; + RAS_DisplayArrayList::iterator it; RAS_DisplayArray *darray = NULL; for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) { @@ -295,7 +297,7 @@ bool RAS_MeshSlot::Equals(RAS_MeshSlot *target) bool RAS_MeshSlot::Join(RAS_MeshSlot *target, MT_Scalar distance) { - vector<RAS_DisplayArray*>::iterator it; + RAS_DisplayArrayList::iterator it; iterator mit; size_t i; @@ -330,6 +332,9 @@ bool RAS_MeshSlot::Join(RAS_MeshSlot *target, MT_Scalar distance) for(begin(mit); !end(mit); next(mit)) for(i=mit.startvertex; i<mit.endvertex; i++) mit.vertex[i].Transform(transform, ntransform); + + /* We know we'll need a list at least this big, reserve in advance */ + target->m_displayArrays.reserve(target->m_displayArrays.size() + m_displayArrays.size()); for(it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) { target->m_displayArrays.push_back(*it); @@ -357,7 +362,7 @@ bool RAS_MeshSlot::Split(bool force) { list<RAS_MeshSlot*>::iterator jit; RAS_MeshSlot *target = m_joinSlot; - vector<RAS_DisplayArray*>::iterator it, jt; + RAS_DisplayArrayList::iterator it, jt; iterator mit; size_t i, found0 = 0, found1 = 0; @@ -425,11 +430,11 @@ bool RAS_MeshSlot::IsCulled() return true; if(!m_bCulled) return false; - +#ifdef USE_SPLIT for(it=m_joinedSlots.begin(); it!=m_joinedSlots.end(); it++) if(!(*it)->m_bCulled) return false; - +#endif return true; } @@ -513,13 +518,13 @@ list<RAS_MeshSlot>::iterator RAS_MaterialBucket::msEnd() bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_IRasterizer* rasty, RAS_IRenderTools *rendertools) { - if (!rasty->SetMaterial(*m_material)) + bool uselights; + + if(!rasty->SetMaterial(*m_material)) return false; - if (m_material->UsesLighting(rasty)) - rendertools->ProcessLighting(rasty, RAS_IRenderTools::RAS_LIGHT_OBJECT_LAYER, cameratrans); - else - rendertools->ProcessLighting(rasty, -1, cameratrans); + uselights= m_material->UsesLighting(rasty); + rendertools->ProcessLighting(rasty, uselights, cameratrans); return true; } diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.h b/source/gameengine/Rasterizer/RAS_MaterialBucket.h index 475f01d549a..f5c8cd3e107 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.h +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.h @@ -86,9 +86,11 @@ public: }; /* Entry of a RAS_MeshObject into RAS_MaterialBucket */ +typedef std::vector<RAS_DisplayArray*> RAS_DisplayArrayList; class RAS_MeshSlot { + friend class RAS_ListRasterizer; private: // indices into display arrays int m_startarray; @@ -97,7 +99,7 @@ private: int m_endindex; int m_startvertex; int m_endvertex; - vector<RAS_DisplayArray*> m_displayArrays; + RAS_DisplayArrayList m_displayArrays; // for construction only RAS_DisplayArray* m_currentArray; @@ -156,6 +158,7 @@ public: bool Join(RAS_MeshSlot *target, MT_Scalar distance); bool Equals(RAS_MeshSlot *target); bool IsCulled(); + void SetCulled(bool culled) { m_bCulled = culled; } }; /* Used by RAS_MeshObject, to point to it's slots in a bucket */ diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.cpp b/source/gameengine/Rasterizer/RAS_MeshObject.cpp index a907994bf57..162f9a81335 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.cpp +++ b/source/gameengine/Rasterizer/RAS_MeshObject.cpp @@ -406,7 +406,9 @@ void RAS_MeshObject::UpdateBuckets(void* clientobj, ms->m_bCulled = culled || !visible; /* split if necessary */ +#ifdef USE_SPLIT ms->Split(); +#endif } } diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.h b/source/gameengine/Rasterizer/RAS_MeshObject.h index 0d35a2f402b..404b7f16a59 100644 --- a/source/gameengine/Rasterizer/RAS_MeshObject.h +++ b/source/gameengine/Rasterizer/RAS_MeshObject.h @@ -147,6 +147,16 @@ public: /* polygon sorting by Z for alpha */ void SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transform); + + bool HasColliderPolygon() { + int numpolys= NumPolygons(); + for (int p=0; p<numpolys; p++) + if (m_Polygons[p]->IsCollider()) + return true; + + return false; + } + /* for construction to find shared vertices */ struct SharedVertex { RAS_DisplayArray *m_darray; diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp index 2c4b55ff964..65aadd63a40 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp @@ -136,10 +136,10 @@ RAS_ListSlot* RAS_ListRasterizer::FindOrAdd(RAS_MeshSlot& ms) */ RAS_ListSlot* localSlot = (RAS_ListSlot*)ms.m_DisplayList; if(!localSlot) { - RAS_Lists::iterator it = mLists.find(&ms); + RAS_Lists::iterator it = mLists.find(ms.m_displayArrays); if(it == mLists.end()) { localSlot = new RAS_ListSlot(this); - mLists.insert(std::pair<RAS_MeshSlot*, RAS_ListSlot*>(&ms, localSlot)); + mLists.insert(std::pair<RAS_DisplayArrayList, RAS_ListSlot*>(ms.m_displayArrays, localSlot)); } else { localSlot = static_cast<RAS_ListSlot*>(it->second->AddRef()); } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h index 96d6d2a995d..653bb43e534 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h @@ -35,7 +35,7 @@ enum RAS_ListSlotFlags { LIST_REGEN =64 }; -typedef std::map<class RAS_MeshSlot*, RAS_ListSlot*> RAS_Lists; +typedef std::map<RAS_DisplayArrayList, RAS_ListSlot*> RAS_Lists; class RAS_ListRasterizer : public RAS_VAOpenGLRasterizer { diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index d4d1b73c772..1a9a28916de 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -327,17 +327,23 @@ void RAS_OpenGLRasterizer::ClearCachingInfo(void) m_materialCachingInfo = 0; } -void RAS_OpenGLRasterizer::FlushDebugLines() +void RAS_OpenGLRasterizer::FlushDebugLines() { -//DrawDebugLines - glDisable(GL_LIGHTING); - glDisable(GL_TEXTURE_2D); + if(!m_debugLines.size()) + return; + + // DrawDebugLines + GLboolean light, tex; + + light= glIsEnabled(GL_LIGHTING); + tex= glIsEnabled(GL_TEXTURE_2D); + + if(light) glDisable(GL_LIGHTING); + if(tex) glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); for (unsigned int i=0;i<m_debugLines.size();i++) { - - glColor4f(m_debugLines[i].m_color[0],m_debugLines[i].m_color[1],m_debugLines[i].m_color[2],1.f); const MT_Scalar* fromPtr = &m_debugLines[i].m_from.x(); const MT_Scalar* toPtr= &m_debugLines[i].m_to.x(); @@ -347,11 +353,10 @@ void RAS_OpenGLRasterizer::FlushDebugLines() } glEnd(); - glEnable(GL_LIGHTING); - glEnable(GL_TEXTURE_2D); + if(light) glEnable(GL_LIGHTING); + if(tex) glEnable(GL_TEXTURE_2D); m_debugLines.clear(); - } void RAS_OpenGLRasterizer::EndFrame() @@ -431,7 +436,7 @@ RAS_IRasterizer::StereoMode RAS_OpenGLRasterizer::GetStereoMode() bool RAS_OpenGLRasterizer::Stereo() { - if(m_stereomode == RAS_STEREO_NOSTEREO) + if(m_stereomode == RAS_STEREO_NOSTEREO || m_stereomode == RAS_STEREO_DOME) return false; else return true; @@ -798,7 +803,7 @@ MT_Matrix4x4 RAS_OpenGLRasterizer::GetFrustumMatrix( double mat[16]; // correction for stereo - if(m_stereomode != RAS_STEREO_NOSTEREO) + if(Stereo()) { float near_div_focallength; // next 2 params should be specified on command line and in Blender publisher @@ -841,7 +846,7 @@ void RAS_OpenGLRasterizer::SetViewMatrix(const MT_Matrix4x4 &mat, const MT_Vecto m_viewmatrix = mat; // correction for stereo - if(m_stereomode != RAS_STEREO_NOSTEREO) + if(Stereo()) { MT_Matrix3x3 camOrientMat3x3(camOrientQuat); MT_Vector3 unitViewDir(0.0, -1.0, 0.0); // minus y direction, Blender convention diff --git a/source/gameengine/Rasterizer/RAS_Polygon.cpp b/source/gameengine/Rasterizer/RAS_Polygon.cpp index 50331d7a664..eacc1285166 100644 --- a/source/gameengine/Rasterizer/RAS_Polygon.cpp +++ b/source/gameengine/Rasterizer/RAS_Polygon.cpp @@ -39,7 +39,7 @@ RAS_Polygon::RAS_Polygon(RAS_MaterialBucket* bucket, RAS_DisplayArray *darray, i m_offset[0]= m_offset[1]= m_offset[2]= m_offset[3]= 0; m_numvert = numvert; - m_edgecode = 255; +// m_edgecode = 255; m_polyflags = 0; } @@ -63,6 +63,7 @@ int RAS_Polygon::GetVertexOffset(int i) return m_offset[i]; } +/* int RAS_Polygon::GetEdgeCode() { return m_edgecode; @@ -71,7 +72,7 @@ int RAS_Polygon::GetEdgeCode() void RAS_Polygon::SetEdgeCode(int edgecode) { m_edgecode = edgecode; -} +}*/ bool RAS_Polygon::IsVisible() @@ -96,6 +97,17 @@ void RAS_Polygon::SetCollider(bool visible) else m_polyflags &= ~COLLIDER; } +bool RAS_Polygon::IsTwoside() +{ + return (m_polyflags & TWOSIDE) != 0; +} + +void RAS_Polygon::SetTwoside(bool twoside) +{ + if(twoside) m_polyflags |= TWOSIDE; + else m_polyflags &= ~TWOSIDE; +} + RAS_MaterialBucket* RAS_Polygon::GetMaterial() { return m_bucket; diff --git a/source/gameengine/Rasterizer/RAS_Polygon.h b/source/gameengine/Rasterizer/RAS_Polygon.h index 18526ba45f7..41eaa6bdd4a 100644 --- a/source/gameengine/Rasterizer/RAS_Polygon.h +++ b/source/gameengine/Rasterizer/RAS_Polygon.h @@ -46,13 +46,18 @@ class RAS_Polygon unsigned short m_numvert; /* flags */ +#if 1 + unsigned short m_polyflags; +#else unsigned char m_edgecode; unsigned char m_polyflags; - +#endif + public: enum { VISIBLE = 1, - COLLIDER = 2 + COLLIDER = 2, + TWOSIDE = 4 }; RAS_Polygon(RAS_MaterialBucket* bucket, RAS_DisplayArray* darray, int numvert); @@ -65,8 +70,9 @@ public: int GetVertexOffset(int i); // each bit is for a visible edge, starting with bit 1 for the first edge, bit 2 for second etc. - int GetEdgeCode(); - void SetEdgeCode(int edgecode); + // - Not used yet! +/* int GetEdgeCode(); + void SetEdgeCode(int edgecode); */ bool IsVisible(); void SetVisible(bool visible); @@ -74,6 +80,9 @@ public: bool IsCollider(); void SetCollider(bool collider); + bool IsTwoside(); + void SetTwoside(bool twoside); + RAS_MaterialBucket* GetMaterial(); RAS_DisplayArray* GetDisplayArray(); }; |