From 76beb7b7d4d3e8777b3cbf9eb0f85f991dd147bc Mon Sep 17 00:00:00 2001 From: Porteries Tristan Date: Mon, 27 Jul 2015 10:58:19 +0200 Subject: [PATCH] BGE: Fix T19241: draw debug shape with overlay/background scene. It's for the function render.drawLine and physics debug. --- source/gameengine/Ketsji/KX_KetsjiEngine.cpp | 5 ++- source/gameengine/Ketsji/KX_PythonInit.cpp | 8 ++--- .../gameengine/Rasterizer/RAS_IRasterizer.h | 9 ++--- .../RAS_OpenGLRasterizer.cpp | 35 +++++++++---------- .../RAS_OpenGLRasterizer.h | 16 +++++---- 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp index 423e41e4e7f..c2ca9b82c8b 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 95b92a223c5..2eaacf43041 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 aadecd56992..7fbaf076d25 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 KX_IndexArray; typedef vector 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 ¢er, 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 ¢er, 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 5b7b752ee98..269cd7dec0a 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 &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 +#include 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 ¢er, const MT_Scalar radius, const MT_Vector3 &color, - const MT_Vector3 &normal, int nsector) + virtual void DrawDebugCircle(SCA_IScene *scene, const MT_Vector3 ¢er, 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 m_debugShapes; + // We store each debug shape by scene. + std::map > m_debugShapes; virtual void SetTexCoordNum(int num); virtual void SetAttribNum(int num);