Commit: 76beb7b7d4d3e8777b3cbf9eb0f85f991dd147bc
Author: Porteries Tristan
Date:   Mon Jul 27 10:58:19 2015 +0200
Branches: master
https://developer.blender.org/rB76beb7b7d4d3e8777b3cbf9eb0f85f991dd147bc

BGE: Fix T19241: draw debug shape with overlay/background scene.

It's for the function render.drawLine and physics debug.

===================================================================

M       source/gameengine/Ketsji/KX_KetsjiEngine.cpp
M       source/gameengine/Ketsji/KX_PythonInit.cpp
M       source/gameengine/Rasterizer/RAS_IRasterizer.h
M       
source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
M       source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h

===================================================================

diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp 
b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
index 423e41e..c2ca9b8 100644
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
+++ b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
@@ -1252,12 +1252,15 @@ void KX_KetsjiEngine::PostRenderScene(KX_Scene* scene)
        // We need to first make sure our viewport is correct (enabling 
multiple viewports can mess this up)
        m_canvas->SetViewPort(0, 0, m_canvas->GetWidth(), 
m_canvas->GetHeight());
        
-       m_rasterizer->FlushDebugShapes();
+       m_rasterizer->FlushDebugShapes(scene);
        scene->Render2DFilters(m_canvas);
 
 #ifdef WITH_PYTHON
        PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
        scene->RunDrawingCallbacks(scene->GetPostDrawCB());
+
+       // Python draw callback can also call debug draw functions, so we have 
to clear debug shapes.
+       m_rasterizer->FlushDebugShapes(scene);
 #endif
 }
 
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp 
b/source/gameengine/Ketsji/KX_PythonInit.cpp
index 95b92a2..2eaacf4 100644
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ b/source/gameengine/Ketsji/KX_PythonInit.cpp
@@ -186,17 +186,17 @@ class KX_KetsjiEngine* KX_GetActiveEngine()
 }
 
 /* why is this in python? */
-void   KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& 
to,const MT_Vector3& color)
+void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& 
to,const MT_Vector3& color)
 {
        if (gp_Rasterizer)
-               gp_Rasterizer->DrawDebugLine(from,to,color);
+               gp_Rasterizer->DrawDebugLine(gp_KetsjiScene, from, to, color);
 }
 
 void KX_RasterizerDrawDebugCircle(const MT_Vector3& center, const MT_Scalar 
radius, const MT_Vector3& color,
                                   const MT_Vector3& normal, int nsector)
 {
        if (gp_Rasterizer)
-               gp_Rasterizer->DrawDebugCircle(center, radius, color, normal, 
nsector);
+               gp_Rasterizer->DrawDebugCircle(gp_KetsjiScene, center, radius, 
color, normal, nsector);
 }
 
 #ifdef WITH_PYTHON
@@ -1265,7 +1265,7 @@ static PyObject *gPyDrawLine(PyObject *, PyObject *args)
        if (!PyVecTo(ob_color, color))
                return NULL;
 
-       gp_Rasterizer->DrawDebugLine(from,to,color);
+       gp_Rasterizer->DrawDebugLine(gp_KetsjiScene, from, to, color);
        
        Py_RETURN_NONE;
 }
diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h 
b/source/gameengine/Rasterizer/RAS_IRasterizer.h
index aadecd5..7fbaf07 100644
--- a/source/gameengine/Rasterizer/RAS_IRasterizer.h
+++ b/source/gameengine/Rasterizer/RAS_IRasterizer.h
@@ -54,6 +54,7 @@ class RAS_ICanvas;
 class RAS_IPolyMaterial;
 class RAS_MeshSlot;
 class RAS_ILightObject;
+class SCA_IScene;
 
 typedef vector<unsigned short> KX_IndexArray;
 typedef vector<RAS_TexVert> KX_VertexArray;
@@ -384,10 +385,10 @@ public:
         */
        virtual void    SetPolygonOffset(float mult, float add) = 0;
        
-       virtual void DrawDebugLine(const MT_Vector3 &from, const MT_Vector3 
&to, const MT_Vector3& color) = 0;
-       virtual void DrawDebugCircle(const MT_Vector3 &center, const MT_Scalar 
radius, const MT_Vector3 &color,
-                                    const MT_Vector3 &normal, int nsector) = 0;
-       virtual void FlushDebugShapes() = 0;
+       virtual void DrawDebugLine(SCA_IScene *scene, const MT_Vector3 &from, 
const MT_Vector3 &to, const MT_Vector3& color) = 0;
+       virtual void DrawDebugCircle(SCA_IScene *scene, const MT_Vector3 
&center, const MT_Scalar radius,
+                                                                const 
MT_Vector3 &color, const MT_Vector3 &normal, int nsector) = 0;
+       virtual void FlushDebugShapes(SCA_IScene *scene) = 0;
        
        virtual void SetTexCoordNum(int num) = 0;
        virtual void SetAttribNum(int num) = 0;
diff --git 
a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp 
b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
index 5b7b752..269cd7d 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
@@ -356,9 +356,10 @@ void RAS_OpenGLRasterizer::ClearCachingInfo(void)
        m_materialCachingInfo = 0;
 }
 
-void RAS_OpenGLRasterizer::FlushDebugShapes()
+void RAS_OpenGLRasterizer::FlushDebugShapes(SCA_IScene *scene)
 {
-       if (m_debugShapes.empty())
+       std::vector<OglDebugShape> &debugShapes = m_debugShapes[scene];
+       if (debugShapes.empty())
                return;
 
        // DrawDebugLines
@@ -372,28 +373,26 @@ void RAS_OpenGLRasterizer::FlushDebugShapes()
 
        //draw lines
        glBegin(GL_LINES);
-       for (unsigned int i=0;i<m_debugShapes.size();i++)
-       {
-               if (m_debugShapes[i].m_type != OglDebugShape::LINE)
+       for (unsigned int i = 0; i < debugShapes.size(); i++) {
+               if (debugShapes[i].m_type != OglDebugShape::LINE)
                        continue;
-               
glColor4f(m_debugShapes[i].m_color[0],m_debugShapes[i].m_color[1],m_debugShapes[i].m_color[2],1.f);
-               const MT_Scalar* fromPtr = &m_debugShapes[i].m_pos.x();
-               const MT_Scalar* toPtr= &m_debugShapes[i].m_param.x();
+               glColor4f(debugShapes[i].m_color[0], debugShapes[i].m_color[1], 
debugShapes[i].m_color[2], 1.0f);
+               const MT_Scalar *fromPtr = &debugShapes[i].m_pos.x();
+               const MT_Scalar *toPtr= &debugShapes[i].m_param.x();
                glVertex3dv(fromPtr);
                glVertex3dv(toPtr);
        }
        glEnd();
 
        //draw circles
-       for (unsigned int i=0;i<m_debugShapes.size();i++)
-       {
-               if (m_debugShapes[i].m_type != OglDebugShape::CIRCLE)
+       for (unsigned int i = 0; i < debugShapes.size(); i++) {
+               if (debugShapes[i].m_type != OglDebugShape::CIRCLE)
                        continue;
                glBegin(GL_LINE_LOOP);
-               
glColor4f(m_debugShapes[i].m_color[0],m_debugShapes[i].m_color[1],m_debugShapes[i].m_color[2],1.f);
+               glColor4f(debugShapes[i].m_color[0], debugShapes[i].m_color[1], 
debugShapes[i].m_color[2], 1.0f);
 
                static const MT_Vector3 worldUp(0.0, 0.0, 1.0);
-               MT_Vector3 norm = m_debugShapes[i].m_param;
+               MT_Vector3 norm = debugShapes[i].m_param;
                MT_Matrix3x3 tr;
                if (norm.fuzzyZero() || norm == worldUp)
                {
@@ -408,14 +407,14 @@ void RAS_OpenGLRasterizer::FlushDebugShapes()
                                yaxis.x(), yaxis.y(), yaxis.z(),
                                norm.x(), norm.y(), norm.z());
                }
-               MT_Scalar rad = m_debugShapes[i].m_param2.x();
-               int n = (int) m_debugShapes[i].m_param2.y();
+               MT_Scalar rad = debugShapes[i].m_param2.x();
+               int n = (int)debugShapes[i].m_param2.y();
                for (int j = 0; j<n; j++)
                {
                        MT_Scalar theta = j*M_PI*2/n;
                        MT_Vector3 pos(cos(theta) * rad, sin(theta) * rad, 0.0);
                        pos = pos*tr;
-                       pos += m_debugShapes[i].m_pos;
+                       pos += debugShapes[i].m_pos;
                        const MT_Scalar* posPtr = &pos.x();
                        glVertex3dv(posPtr);
                }
@@ -425,13 +424,11 @@ void RAS_OpenGLRasterizer::FlushDebugShapes()
        if (light) glEnable(GL_LIGHTING);
        if (tex) glEnable(GL_TEXTURE_2D);
 
-       m_debugShapes.clear();
+       debugShapes.clear();
 }
 
 void RAS_OpenGLRasterizer::EndFrame()
 {
-       FlushDebugShapes();
-
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
 
        glDisable(GL_MULTISAMPLE_ARB);
diff --git 
a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h 
b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
index b034315..ad49ebe 100644
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
+++ b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
@@ -38,6 +38,7 @@
 
 #include "MT_CmMatrix4x4.h"
 #include <vector>
+#include <map>
 using namespace std;
 
 #include "RAS_IRasterizer.h"
@@ -223,20 +224,20 @@ public:
 
        virtual void SetPolygonOffset(float mult, float add);
 
-       virtual void FlushDebugShapes();
+       virtual void FlushDebugShapes(SCA_IScene *scene);
 
-       virtual void DrawDebugLine(const MT_Vector3 &from,const MT_Vector3 &to, 
const MT_Vector3 &color)
+       virtual void DrawDebugLine(SCA_IScene *scene, const MT_Vector3 
&from,const MT_Vector3 &to, const MT_Vector3 &color)
        {
                OglDebugShape line;
                line.m_type = OglDebugShape::LINE;
                line.m_pos= from;
                line.m_param = to;
                line.m_color = color;
-               m_debugShapes.push_back(line);
+               m_debugShapes[scene].push_back(line);
        }
 
-       virtual void DrawDebugCircle(const MT_Vector3 &center, const MT_Scalar 
radius, const MT_Vector3 &color,
-                                    const MT_Vector3 &normal, int nsector)
+       virtual void DrawDebugCircle(SCA_IScene *scene, const MT_Vector3 
&center, const MT_Scalar radius,
+                                                                const 
MT_Vector3 &color, const MT_Vector3 &normal, int nsector)
        {
                OglDebugShape line;
                line.m_type = OglDebugShape::CIRCLE;
@@ -245,10 +246,11 @@ public:
                line.m_color = color;
                line.m_param2.x() = radius;
                line.m_param2.y() = (float) nsector;
-               m_debugShapes.push_back(line);
+               m_debugShapes[scene].push_back(line);
        }
 
-       std::vector <OglDebugShape>     m_debugShapes;
+       // We store each debug shape by scene.
+       std::map<SCA_IScene *, std::vector<OglDebugShape> > m_debugShapes;
 
        virtual void SetTexCoordNum(int num);
        virtual void SetAttribNum(int num);

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to