diff options
Diffstat (limited to 'source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp')
-rw-r--r-- | source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp | 159 |
1 files changed, 97 insertions, 62 deletions
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp index ed4cfb2ae42..2c4b55ff964 100644 --- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp +++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp @@ -6,15 +6,11 @@ #ifdef WIN32 #include <windows.h> #endif // WIN32 -#ifdef __APPLE__ -#define GL_GLEXT_LEGACY 1 -#include <OpenGL/gl.h> -#else -#include <GL/gl.h> -#endif +#include "GL/glew.h" + +#include "RAS_MaterialBucket.h" #include "RAS_TexVert.h" -#include "RAS_GLExtensionManager.h" #include "MT_assert.h" //#ifndef NDEBUG @@ -25,11 +21,21 @@ #define spit(x) //#endif -RAS_ListSlot::RAS_ListSlot() +RAS_ListSlot::RAS_ListSlot(RAS_ListRasterizer* rasty) : KX_ListSlot(), + m_list(0), m_flag(LIST_MODIFY|LIST_CREATE), - m_list(0) + m_rasty(rasty) +{ +} + +int RAS_ListSlot::Release() { + if (--m_refcount > 0) + return m_refcount; + m_rasty->RemoveListSlot(this); + delete this; + return 0; } RAS_ListSlot::~RAS_ListSlot() @@ -96,8 +102,9 @@ bool RAS_ListSlot::End() -RAS_ListRasterizer::RAS_ListRasterizer(RAS_ICanvas* canvas) -: RAS_OpenGLRasterizer(canvas) +RAS_ListRasterizer::RAS_ListRasterizer(RAS_ICanvas* canvas, bool useVertexArrays, bool lock) +: RAS_VAOpenGLRasterizer(canvas, lock), + mUseVertexArrays(useVertexArrays) { // -- } @@ -107,22 +114,34 @@ RAS_ListRasterizer::~RAS_ListRasterizer() ReleaseAlloc(); } -RAS_ListSlot* RAS_ListRasterizer::FindOrAdd(const vecVertexArray& vertexarrays, KX_ListSlot** slot) +void RAS_ListRasterizer::RemoveListSlot(RAS_ListSlot* list) +{ + RAS_Lists::iterator it = mLists.begin(); + while(it != mLists.end()) { + if (it->second == list) { + mLists.erase(it); + break; + } + it++; + } +} + +RAS_ListSlot* RAS_ListRasterizer::FindOrAdd(RAS_MeshSlot& ms) { /* Keep a copy of constant lists submitted for rendering, this guards against (replicated)new...delete every frame, and we can reuse lists! - :: sorted by vertex array + :: sorted by mesh slot */ - RAS_ListSlot* localSlot = (RAS_ListSlot*)*slot; + RAS_ListSlot* localSlot = (RAS_ListSlot*)ms.m_DisplayList; if(!localSlot) { - RAS_Lists::iterator it = mLists.find(vertexarrays); + RAS_Lists::iterator it = mLists.find(&ms); if(it == mLists.end()) { - localSlot = new RAS_ListSlot(); - mLists.insert(std::pair<vecVertexArray, RAS_ListSlot*>(vertexarrays, localSlot)); + localSlot = new RAS_ListSlot(this); + mLists.insert(std::pair<RAS_MeshSlot*, RAS_ListSlot*>(&ms, localSlot)); } else { - localSlot = it->second; + localSlot = static_cast<RAS_ListSlot*>(it->second->AddRef()); } } MT_assert(localSlot); @@ -139,71 +158,87 @@ void RAS_ListRasterizer::ReleaseAlloc() mLists.clear(); } - -void RAS_ListRasterizer::IndexPrimitives( - 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) +void RAS_ListRasterizer::IndexPrimitives(RAS_MeshSlot& ms) { RAS_ListSlot* localSlot =0; - // useObjectColor(are we updating every frame?) - if(!useObjectColor) { - localSlot = FindOrAdd(vertexarrays, slot); + if(ms.m_bDisplayList) { + localSlot = FindOrAdd(ms); localSlot->DrawList(); - if(localSlot->End()) + if(localSlot->End()) { + // save slot here too, needed for replicas and object using same mesh + // => they have the same vertexarray but different mesh slot + ms.m_DisplayList = localSlot; return; + } } + + if (mUseVertexArrays) + RAS_VAOpenGLRasterizer::IndexPrimitives(ms); + else + RAS_OpenGLRasterizer::IndexPrimitives(ms); - RAS_OpenGLRasterizer::IndexPrimitives( - vertexarrays, indexarrays, - mode, polymat, - rendertools, useObjectColor, - rgbacolor,slot - ); - - if(!useObjectColor) { + if(ms.m_bDisplayList) { localSlot->EndList(); - *slot = localSlot; + ms.m_DisplayList = localSlot; } } -void RAS_ListRasterizer::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) +void RAS_ListRasterizer::IndexPrimitivesMulti(RAS_MeshSlot& ms) { RAS_ListSlot* localSlot =0; - // useObjectColor(are we updating every frame?) - if(!useObjectColor) { - localSlot = FindOrAdd(vertexarrays, slot); + if(ms.m_bDisplayList) { + localSlot = FindOrAdd(ms); localSlot->DrawList(); - if(localSlot->End()) + if(localSlot->End()) { + // save slot here too, needed for replicas and object using same mesh + // => they have the same vertexarray but different mesh slot + ms.m_DisplayList = localSlot; return; + } } - RAS_OpenGLRasterizer::IndexPrimitivesMulti( - vertexarrays, indexarrays, - mode, polymat, - rendertools, useObjectColor, - rgbacolor,slot - ); - if(!useObjectColor) { + // 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(ms); + else + RAS_OpenGLRasterizer::IndexPrimitivesMulti(ms); + + if(ms.m_bDisplayList) { localSlot->EndList(); - *slot = localSlot; + ms.m_DisplayList = localSlot; + } +} + +bool RAS_ListRasterizer::Init(void) +{ + if (mUseVertexArrays) { + return RAS_VAOpenGLRasterizer::Init(); + } else { + return RAS_OpenGLRasterizer::Init(); + } +} + +void RAS_ListRasterizer::SetDrawingMode(int drawingmode) +{ + if (mUseVertexArrays) { + RAS_VAOpenGLRasterizer::SetDrawingMode(drawingmode); + } else { + RAS_OpenGLRasterizer::SetDrawingMode(drawingmode); + } +} + +void RAS_ListRasterizer::Exit() +{ + if (mUseVertexArrays) { + RAS_VAOpenGLRasterizer::Exit(); + } else { + RAS_OpenGLRasterizer::Exit(); } } |