From ad103954e64917673077d61cb6b495e78e7a6be9 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Wed, 9 Jul 2008 19:15:15 +0000 Subject: Apricot Branch: GLSL ==================== ATI fixes: * Fix crash in glBitmap when rendering shadow buffers, it doesn't seem to like using that function with only a depth buffer. * Workaround either a bug in the driver or Blender, but I couldn't find anything wrong, glVertexAttribPointerARB doesn't seem to work inside display lists, so now it uses immediate mode to create the list. * Making deformable object for the game engine didn't check properly if there was actually a vertex group, causing some static objects to not use display lists. * Also some cleanup in the game engine drawing code, replacing magic numbers with an enum. The apricot demo seems to runs slightly faster on a ATI HD3750 than NVidia 8800 GTS. --- source/gameengine/Rasterizer/RAS_BucketManager.cpp | 2 +- source/gameengine/Rasterizer/RAS_IRasterizer.h | 55 ++++++++------ .../gameengine/Rasterizer/RAS_MaterialBucket.cpp | 18 ++--- source/gameengine/Rasterizer/RAS_MaterialBucket.h | 10 +-- .../RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp | 25 +++---- .../RAS_OpenGLRasterizer/RAS_ListRasterizer.h | 8 +- .../RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp | 87 ++++------------------ .../RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h | 10 +-- .../RAS_VAOpenGLRasterizer.cpp | 73 ++++++++---------- .../RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h | 8 +- 10 files changed, 110 insertions(+), 186 deletions(-) (limited to 'source/gameengine/Rasterizer') diff --git a/source/gameengine/Rasterizer/RAS_BucketManager.cpp b/source/gameengine/Rasterizer/RAS_BucketManager.cpp index 50df1a1e2ea..b4492ca03a9 100644 --- a/source/gameengine/Rasterizer/RAS_BucketManager.cpp +++ b/source/gameengine/Rasterizer/RAS_BucketManager.cpp @@ -109,7 +109,7 @@ void RAS_BucketManager::RenderAlphaBuckets( // it is needed for compatibility. rasty->SetDepthMask(RAS_IRasterizer::KX_DEPTHMASK_DISABLED); - int drawingmode; + RAS_IRasterizer::DrawMode drawingmode; std::multiset< alphamesh, backtofront>::iterator msit = alphameshset.begin(); for (; msit != alphameshset.end(); ++msit) { diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h index 81dcd6bd394..d4a9177a85d 100644 --- a/source/gameengine/Rasterizer/RAS_IRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h @@ -33,12 +33,23 @@ #pragma warning (disable:4786) #endif +#include "STR_HashedString.h" + #include "MT_CmMatrix4x4.h" #include "MT_Matrix4x4.h" +#include "RAS_TexVert.h" + +#include +using namespace std; + class RAS_ICanvas; class RAS_IPolyMaterial; -#include "RAS_MaterialBucket.h" + +typedef vector KX_IndexArray; +typedef vector KX_VertexArray; +typedef vector< KX_VertexArray* > vecVertexArray; +typedef vector< KX_IndexArray* > vecIndexArrays; /** * 3D rendering device context interface. @@ -66,6 +77,16 @@ public: KX_SHADOW }; + /** + * Drawing modes + */ + + enum DrawMode { + KX_MODE_LINES = 1, + KX_MODE_TRIANGLES, + KX_MODE_QUADS + }; + /** * Valid SetDepthMask parameters */ @@ -199,45 +220,37 @@ public: * IndexPrimitives: Renders primitives. * @param vertexarrays is an array of vertex arrays * @param indexarrays is an array of index arrays - * @param mode determines the type of primitive stored in the vertex/index arrays: - * 0 triangles - * 1 lines (default) - * 2 quads - * @param polymat (reserved) + * @param mode determines the type of primitive stored in the vertex/index arrays * @param useObjectColor will render the object using @param rgbacolor instead of * vertex colors. */ - virtual void IndexPrimitives( const vecVertexArray& vertexarrays, + virtual void IndexPrimitives( const vecVertexArray& vertexarrays, const vecIndexArrays & indexarrays, - int mode, - class RAS_IPolyMaterial* polymat, - class RAS_IRenderTools* rendertools, + DrawMode mode, bool useObjectColor, const MT_Vector4& rgbacolor, class KX_ListSlot** slot)=0; + virtual void IndexPrimitivesMulti( + const vecVertexArray& vertexarrays, + const vecIndexArrays & indexarrays, + DrawMode mode, + bool useObjectColor, + const MT_Vector4& rgbacolor, + class KX_ListSlot** slot)=0; + /** * IndexPrimitives_3DText will render text into the polygons. * The text to be rendered is from @param rendertools client object's text property. */ virtual void IndexPrimitives_3DText( const vecVertexArray& vertexarrays, const vecIndexArrays & indexarrays, - int mode, + DrawMode mode, class RAS_IPolyMaterial* polymat, class RAS_IRenderTools* rendertools, bool useObjectColor, const MT_Vector4& rgbacolor)=0; - virtual void IndexPrimitivesMulti( - const vecVertexArray& vertexarrays, - const vecIndexArrays & indexarrays, - int mode, - class RAS_IPolyMaterial* polymat, - class RAS_IRenderTools* rendertools, - bool useObjectColor, - const MT_Vector4& rgbacolor, - class KX_ListSlot** slot)=0; - virtual void SetProjectionMatrix(MT_CmMatrix4x4 & mat)=0; /* This one should become our final version, methinks. */ /** diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp index 705b3ea47d7..e295d69e48e 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp @@ -167,7 +167,7 @@ RAS_MaterialBucket::T_MeshSlotList::iterator RAS_MaterialBucket::msEnd() } bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_IRasterizer* rasty, - RAS_IRenderTools *rendertools, int &drawmode) + RAS_IRenderTools *rendertools, RAS_IRasterizer::DrawMode &drawmode) { rendertools->SetViewMat(cameratrans); @@ -179,14 +179,18 @@ bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_I else rendertools->ProcessLighting(-1); - drawmode = (rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID ? - 1: (m_material->UsesTriangles() ? 0 : 2)); + if(rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID) + drawmode = RAS_IRasterizer::KX_MODE_LINES; + else if(m_material->UsesTriangles()) + drawmode = RAS_IRasterizer::KX_MODE_TRIANGLES; + else + drawmode = RAS_IRasterizer::KX_MODE_QUADS; return true; } void RAS_MaterialBucket::RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRasterizer* rasty, - RAS_IRenderTools* rendertools, const KX_MeshSlot &ms, int drawmode) + RAS_IRenderTools* rendertools, const KX_MeshSlot &ms, RAS_IRasterizer::DrawMode drawmode) { if (!ms.m_bVisible) return; @@ -244,8 +248,6 @@ void RAS_MaterialBucket::RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRa ms.m_mesh->GetVertexCache(m_material), ms.m_mesh->GetIndexCache(m_material), drawmode, - m_material, - rendertools, ms.m_bObjectColor, ms.m_RGBAcolor, displaylist); @@ -258,8 +260,6 @@ void RAS_MaterialBucket::RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRa ms.m_mesh->GetVertexCache(m_material), ms.m_mesh->GetIndexCache(m_material), drawmode, - m_material, - rendertools, // needed for textprinting on polys ms.m_bObjectColor, ms.m_RGBAcolor, displaylist); @@ -284,7 +284,7 @@ void RAS_MaterialBucket::Render(const MT_Transform& cameratrans, //rasty->SetMaterial(*m_material); - int drawmode; + RAS_IRasterizer::DrawMode drawmode; for (T_MeshSlotList::const_iterator it = m_meshSlots.begin(); ! (it == m_meshSlots.end()); ++it) { diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.h b/source/gameengine/Rasterizer/RAS_MaterialBucket.h index 5ad0c173a56..13d8a53714a 100644 --- a/source/gameengine/Rasterizer/RAS_MaterialBucket.h +++ b/source/gameengine/Rasterizer/RAS_MaterialBucket.h @@ -35,17 +35,13 @@ #include "MT_Transform.h" #include "RAS_IPolygonMaterial.h" +#include "RAS_IRasterizer.h" #include "RAS_Deformer.h" // __NLA #include #include #include using namespace std; -typedef vector KX_IndexArray; -typedef vector KX_VertexArray; -typedef vector< KX_VertexArray* > vecVertexArray; -typedef vector< KX_IndexArray* > vecIndexArrays; - /** * KX_VertexIndex */ @@ -146,9 +142,9 @@ public: const MT_Vector4& rgbavec); void RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRasterizer* rasty, - RAS_IRenderTools* rendertools, const KX_MeshSlot &ms, int drawmode); + RAS_IRenderTools* rendertools, const KX_MeshSlot &ms, RAS_IRasterizer::DrawMode drawmode); bool ActivateMaterial(const MT_Transform& cameratrans, RAS_IRasterizer* rasty, - RAS_IRenderTools *rendertools, int &drawmode); + RAS_IRenderTools *rendertools, RAS_IRasterizer::DrawMode& drawmode); unsigned int NumMeshSlots(); T_MeshSlotList::iterator msBegin(); diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp index 39080b80492..c2687319717 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp @@ -161,9 +161,7 @@ void RAS_ListRasterizer::ReleaseAlloc() void RAS_ListRasterizer::IndexPrimitives( const vecVertexArray & vertexarrays, const vecIndexArrays & indexarrays, - int mode, - class RAS_IPolyMaterial* polymat, - class RAS_IRenderTools* rendertools, + DrawMode mode, bool useObjectColor, const MT_Vector4& rgbacolor, class KX_ListSlot** slot) @@ -185,15 +183,13 @@ void RAS_ListRasterizer::IndexPrimitives( if (mUseVertexArrays) { RAS_VAOpenGLRasterizer::IndexPrimitives( vertexarrays, indexarrays, - mode, polymat, - rendertools, useObjectColor, + mode, useObjectColor, rgbacolor,slot ); } else { RAS_OpenGLRasterizer::IndexPrimitives( vertexarrays, indexarrays, - mode, polymat, - rendertools, useObjectColor, + mode, useObjectColor, rgbacolor,slot ); } @@ -208,9 +204,7 @@ void RAS_ListRasterizer::IndexPrimitives( void RAS_ListRasterizer::IndexPrimitivesMulti( const vecVertexArray& vertexarrays, const vecIndexArrays & indexarrays, - int mode, - class RAS_IPolyMaterial* polymat, - class RAS_IRenderTools* rendertools, + DrawMode mode, bool useObjectColor, const MT_Vector4& rgbacolor, class KX_ListSlot** slot) @@ -230,18 +224,19 @@ void RAS_ListRasterizer::IndexPrimitivesMulti( } } - if (mUseVertexArrays) { + // workaround: note how we do not use vertex arrays for making display + // lists, since glVertexAttribPointerARB doesn't seem to work correct + // in display lists on ATI? either a bug in the driver or in Blender .. + if (mUseVertexArrays && !localSlot) { RAS_VAOpenGLRasterizer::IndexPrimitivesMulti( vertexarrays, indexarrays, - mode, polymat, - rendertools, useObjectColor, + mode, useObjectColor, rgbacolor,slot ); } else { RAS_OpenGLRasterizer::IndexPrimitivesMulti( vertexarrays, indexarrays, - mode, polymat, - rendertools, useObjectColor, + mode, useObjectColor, rgbacolor,slot ); } diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h index 4b3304d7396..b1b19144c12 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h @@ -52,9 +52,7 @@ public: virtual void IndexPrimitives( const vecVertexArray& vertexarrays, const vecIndexArrays & indexarrays, - int mode, - class RAS_IPolyMaterial* polymat, - class RAS_IRenderTools* rendertools, + DrawMode mode, bool useObjectColor, const MT_Vector4& rgbacolor, class KX_ListSlot** slot @@ -63,9 +61,7 @@ public: virtual void IndexPrimitivesMulti( const vecVertexArray& vertexarrays, const vecIndexArrays & indexarrays, - int mode, - class RAS_IPolyMaterial* polymat, - class RAS_IRenderTools* rendertools, + DrawMode mode, bool useObjectColor, const MT_Vector4& rgbacolor, class KX_ListSlot** slot diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp index df77d8e0524..dcc36bf5a39 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp @@ -591,33 +591,14 @@ void RAS_OpenGLRasterizer::GetViewMatrix(MT_Matrix4x4 &mat) const void RAS_OpenGLRasterizer::IndexPrimitives(const vecVertexArray & vertexarrays, const vecIndexArrays & indexarrays, - int mode, - class RAS_IPolyMaterial* polymat, - class RAS_IRenderTools* rendertools, + DrawMode mode, bool useObjectColor, const MT_Vector4& rgbacolor, class KX_ListSlot** slot ) { - GLenum drawmode; - switch (mode) - { - case 0: - drawmode = GL_TRIANGLES; - break; - case 1: - drawmode = GL_LINES; - break; - case 2: - drawmode = GL_QUADS; - break; - default: - drawmode = GL_LINES; - break; - } - - const RAS_TexVert* vertexarray ; - unsigned int numindices,vt; + const RAS_TexVert* vertexarray; + unsigned int numindices, vt; for (vt=0;vtgetLocalXYZ()); - glTexCoordPointer(2,GL_FLOAT,vtxstride,vertexarray->getUV1()); - glColorPointer(4,GL_UNSIGNED_BYTE,vtxstride,vertexarray->getRGBA()); glNormalPointer(GL_FLOAT,vtxstride,vertexarray->getNormal()); + glTexCoordPointer(2,GL_FLOAT,vtxstride,vertexarray->getUV1()); + if(glIsEnabled(GL_COLOR_ARRAY)) + glColorPointer(4,GL_UNSIGNED_BYTE,vtxstride,vertexarray->getRGBA()); //if(m_Lock) // local->Begin(vertexarrays[vt]->size()); @@ -171,8 +167,6 @@ void RAS_VAOpenGLRasterizer::IndexPrimitives( const vecVertexArray& vertexarrays //if(m_Lock) // local->End(); - - } glDisableClientState(GL_TEXTURE_COORD_ARRAY); @@ -180,28 +174,21 @@ void RAS_VAOpenGLRasterizer::IndexPrimitives( const vecVertexArray& vertexarrays void RAS_VAOpenGLRasterizer::IndexPrimitivesMulti( const vecVertexArray& vertexarrays, const vecIndexArrays & indexarrays, - int mode, - class RAS_IPolyMaterial* polymat, - class RAS_IRenderTools* rendertools, + DrawMode mode, bool useObjectColor, const MT_Vector4& rgbacolor, class KX_ListSlot** slot) { static const GLsizei vtxstride = sizeof(RAS_TexVert); + GLenum drawmode; - switch (mode) - { - case 0: - drawmode = GL_TRIANGLES; - break; - case 2: - drawmode = GL_QUADS; - break; - case 1: //lines - default: - drawmode = GL_LINES; - break; - } + if(mode == KX_MODE_TRIANGLES) + drawmode = GL_TRIANGLES; + else if(mode == KX_MODE_QUADS) + drawmode = GL_QUADS; + else + drawmode = GL_LINES; + const RAS_TexVert* vertexarray; unsigned int numindices, vt; @@ -234,10 +221,10 @@ void RAS_VAOpenGLRasterizer::IndexPrimitivesMulti( const vecVertexArray& vertexa continue; glVertexPointer(3,GL_FLOAT,vtxstride,vertexarray->getLocalXYZ()); - TexCoordPtr(vertexarray); - - glColorPointer(4,GL_UNSIGNED_BYTE,vtxstride,vertexarray->getRGBA()); glNormalPointer(GL_FLOAT,vtxstride,vertexarray->getNormal()); + TexCoordPtr(vertexarray); + if(glIsEnabled(GL_COLOR_ARRAY)) + glColorPointer(4,GL_UNSIGNED_BYTE,vtxstride,vertexarray->getRGBA()); //if(m_Lock) // local->Begin(vertexarrays[vt]->size()); diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h index ea08887028f..e4cc4ace0e8 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_VAOpenGLRasterizer.h @@ -52,9 +52,7 @@ public: virtual void IndexPrimitives( const vecVertexArray& vertexarrays, const vecIndexArrays & indexarrays, - int mode, - class RAS_IPolyMaterial* polymat, - class RAS_IRenderTools* rendertools, + DrawMode mode, bool useObjectColor, const MT_Vector4& rgbacolor, class KX_ListSlot** slot); @@ -62,9 +60,7 @@ public: virtual void IndexPrimitivesMulti( const vecVertexArray& vertexarrays, const vecIndexArrays & indexarrays, - int mode, - class RAS_IPolyMaterial* polymat, - class RAS_IRenderTools* rendertools, + DrawMode mode, bool useObjectColor, const MT_Vector4& rgbacolor, class KX_ListSlot** slot); -- cgit v1.2.3