BGE 2D Filters: filters run per scene now (fix for [#18152]) - it (slightly) breaks...
authorDalai Felinto <dfelinto@gmail.com>
Wed, 3 Mar 2010 06:38:47 +0000 (06:38 +0000)
committerDalai Felinto <dfelinto@gmail.com>
Wed, 3 Mar 2010 06:38:47 +0000 (06:38 +0000)
Originally we had 2DFilters (m_filtermanager) stored in RenderTools. That way filters were stored globally and were being called once per each scene. This was producing two big problems: (1) performance and (2) flexibility of use.

(1) Performance - To run the filters 2X == 2X slower
(2) flexibility of use - Very often we want the filter in the scene but not in the UI for example.

For those reasons I believe that 2DFilters with multiple scenes was very useless or unpredictable. I hope they work fine now.
To make it work as before (2.4) you can simply recreate the 2dfilter actuators across the scenes.

* * * * *

Imagine that we have:
(a) Main Scene
(b) Overlay Scene

in Main Scene the Z Buffer and RGB will be from the main scene.
in Overlay Scene the Z Buffer will be from the Overlay Scene and the RBG buffer is from both [(a + 2D Filter) + b].

So in pseudo code if we have a,b,c,d,e scenes we have: (2DFilterE(2DFilterD(2DFilterC(2DFilterB(2DFilterA(a) + b) + c) + d) + e)

19 files changed:
source/blender/editors/screen/screen_ops.c
source/gameengine/BlenderRoutines/KX_BlenderRenderTools.cpp
source/gameengine/BlenderRoutines/KX_BlenderRenderTools.h
source/gameengine/Converter/KX_ConvertActuators.cpp
source/gameengine/GameLogic/CMakeLists.txt
source/gameengine/GameLogic/Makefile
source/gameengine/GameLogic/SCA_2DFilterActuator.cpp
source/gameengine/GameLogic/SCA_2DFilterActuator.h
source/gameengine/GameLogic/SConscript
source/gameengine/GamePlayer/common/GPC_RenderTools.cpp
source/gameengine/GamePlayer/common/GPC_RenderTools.h
source/gameengine/Ketsji/KX_KetsjiEngine.cpp
source/gameengine/Ketsji/KX_KetsjiEngine.h
source/gameengine/Ketsji/KX_Scene.cpp
source/gameengine/Ketsji/KX_Scene.h
source/gameengine/Rasterizer/CMakeLists.txt
source/gameengine/Rasterizer/Makefile
source/gameengine/Rasterizer/RAS_2DFilterManager.h
source/gameengine/Rasterizer/RAS_IRenderTools.h

index 0c958654722485a9b04e356f53dd35d127ab1469..98cbd95b86735470de466d420c83fd45d8f0e804 100644 (file)
@@ -2246,7 +2246,6 @@ static void SCREEN_OT_region_flip(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= region_flip_exec;
-       
        ot->poll= ED_operator_areaactive;
        ot->flag= 0;
 }
index 60d60ca9045f3224d8133151ef6301f325d6a669..3d73655753597a3e70dc4dfe79ba0eb3ab60eb40 100644 (file)
@@ -379,13 +379,3 @@ void KX_BlenderRenderTools::MotionBlur(RAS_IRasterizer* rasterizer)
                }
        }
 }
-
-void KX_BlenderRenderTools::Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text)
-{
-       m_filtermanager.EnableFilter(propNames, gameObj, filtermode, pass, text);
-}
-
-void KX_BlenderRenderTools::Render2DFilters(RAS_ICanvas* canvas)
-{
-       m_filtermanager.RenderFilters(canvas);
-}
index 54c89454c903c6b12edcc3f97383b73e2725003b..072265245383d2ef29f996f905c91d5826daead3 100644 (file)
@@ -94,10 +94,6 @@ public:
 
        virtual void MotionBlur(RAS_IRasterizer* rasterizer);
 
-       virtual void Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text);
-
-       virtual void Render2DFilters(RAS_ICanvas* canvas);
-
        virtual void SetClientObject(RAS_IRasterizer *rasty, void* obj);
        
        
index 5aa7283f14c89a0ad54a8c635a88ac6c003a80f5..9b41470769f6e2815bd15be2f6d6a1c07265ec20 100644 (file)
@@ -969,7 +969,7 @@ void BL_ConvertActuators(char* maggiename,
                        }
             
                        tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag,
-                               _2dfilter->float_arg,_2dfilter->int_arg,ketsjiEngine->GetRasterizer(),rendertools);
+                               _2dfilter->float_arg,_2dfilter->int_arg,ketsjiEngine->GetRasterizer(),scene);
 
                        if (_2dfilter->text)
                        {
index 3ffba14ec95de1be4fc0075ffd353ef8f22aba36..958e697aa3961e957f088a5218a92fd7b7914346 100644 (file)
@@ -32,6 +32,7 @@ SET(INC
        ../../../intern/string
        ../../../source/gameengine/Expressions 
        ../../../source/gameengine/SceneGraph
+       ../../../source/gameengine/Ketsji
        ../../../intern/moto/include
        ../../../source/gameengine/Rasterizer
 )
index a1794a60452c85885e52ebc2e1ce5da12a1b0a2c..0d4d50b32a0597d24c9805380ee2646adb92c7a1 100644 (file)
@@ -41,6 +41,7 @@ CCFLAGS += $(LEVEL_1_CPP_WARNINGS)
 CPPFLAGS += -I../Expressions 
 CPPFLAGS += -I../SceneGraph
 CPPFLAGS += -I../Rasterizer
+CPPFLAGS += -I../Ketsji
 CPPFLAGS += -I$(NAN_STRING)/include    
 CPPFLAGS += -I$(NAN_MOTO)/include
 CPPFLAGS += -I../../blender/makesdna
index 5cda00d901fd4dfc8aec716e73373ffdfa72c065..43cf36b7db8502822e159f8021af37948b2c5093 100644 (file)
@@ -42,14 +42,14 @@ SCA_2DFilterActuator::SCA_2DFilterActuator(
                float float_arg,
                int int_arg,
                RAS_IRasterizer* rasterizer,
-               RAS_IRenderTools* rendertools)
+               KX_Scene* scene)
     : SCA_IActuator(gameobj, KX_ACT_2DFILTER),
      m_type(type),
         m_disableMotionBlur(flag),
         m_float_arg(float_arg),
         m_int_arg(int_arg),
         m_rasterizer(rasterizer),
-        m_rendertools(rendertools)
+        m_scene(scene)
 {
        m_gameObj = NULL;
        if(gameobj){
@@ -87,7 +87,7 @@ bool SCA_2DFilterActuator::Update()
        }
        else if(m_type < RAS_2DFilterManager::RAS_2DFILTER_NUMBER_OF_FILTERS)
        {
-               m_rendertools->Update2DFilter(m_propNames, m_gameObj, m_type, m_int_arg, m_shaderText);
+               m_scene->Update2DFilter(m_propNames, m_gameObj, m_type, m_int_arg, m_shaderText);
        }
        // once the filter is in place, no need to update it again => disable the actuator
     return false;
index d47cfb203f8f2cf06f6911c2db870ca6df8346c1..beb4cb886088afc8c88b8d4309c8f7ccc68dfcde 100644 (file)
@@ -29,8 +29,8 @@
 #define __SCA_2DFILETRACTUATOR_H__
 
 #include "RAS_IRasterizer.h"
-#include "RAS_IRenderTools.h"
 #include "SCA_IActuator.h"
+#include "KX_Scene.h"
 
 class SCA_2DFilterActuator : public SCA_IActuator
 {
@@ -45,7 +45,7 @@ private:
        int   m_int_arg;
        STR_String      m_shaderText;
        RAS_IRasterizer* m_rasterizer;
-       RAS_IRenderTools* m_rendertools;
+       KX_Scene* m_scene;
 
 public:
 
@@ -56,7 +56,7 @@ public:
                float float_arg,
                int int_arg,
                RAS_IRasterizer* rasterizer,
-               RAS_IRenderTools* rendertools);
+               KX_Scene* scene);
 
        void    SetShaderText(const char *text);
     virtual ~SCA_2DFilterActuator();
index 3840754ed06685e0638f8b801fe108af86271b34..57325d99d046dd9e1926dfffc95d213b75544486 100644 (file)
@@ -6,6 +6,7 @@ sources = env.Glob('*.cpp') + env.Glob('Joystick/*.cpp')
 incs = '. #/source/kernel/gen_system #/intern/string'
 incs += ' #/source/gameengine/Expressions #/intern/moto/include'
 incs += ' #/source/gameengine/Rasterizer #/source/gameengine/SceneGraph'
+incs += ' #/source/gameengine/Ketsji'
 
 defs = []
 
index bf474e4e42f287cab6a250e22fcf1d8c8ca38a52..e02b5fedaf0763833582477fdd0dfe1644979240 100644 (file)
@@ -433,13 +433,3 @@ void GPC_RenderTools::MotionBlur(RAS_IRasterizer* rasterizer)
        }
 }
 
-void GPC_RenderTools::Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text)
-{
-       m_filtermanager.EnableFilter(propNames, gameObj, filtermode, pass, text);
-}
-
-void GPC_RenderTools::Render2DFilters(RAS_ICanvas* canvas)
-{
-       m_filtermanager.RenderFilters(canvas);
-}
-
index 1f58c5cb543a38c158dd6cc6d4c1be2c4dcd1d0d..378c6d8580f96c95f793d5dfb03c4fe781f662d0 100644 (file)
@@ -94,10 +94,6 @@ public:
 
        virtual void MotionBlur(RAS_IRasterizer* rasterizer);
 
-       virtual void Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text);
-
-       virtual void Render2DFilters(RAS_ICanvas* canvas);
-
        virtual void SetClientObject(RAS_IRasterizer *rasty, void* obj);
 };
 
index 18ae80c78c3fda36e65b5ead38166942f52498db..d1fecb769988707dc68711fa087fd4dfc736078d 100644 (file)
@@ -334,6 +334,11 @@ void KX_KetsjiEngine::RenderDome()
                                
                                it++;
                        }
+                       // Part of PostRenderScene()
+                       m_rendertools->MotionBlur(m_rasterizer);
+                       scene->Render2DFilters(m_canvas);
+                       // no RunDrawingCallBacks
+                       // no FlushDebugLines
                }
                m_dome->BindImages(i);
        }       
@@ -362,11 +367,7 @@ void KX_KetsjiEngine::RenderDome()
                        1.0
                        );
        }
-
        m_dome->Draw();
-
-       // run the 2dfilters and motion blur once for all the scenes
-       PostRenderFrame();
        EndFrame();
 }
 
@@ -859,6 +860,7 @@ void KX_KetsjiEngine::Render()
                        
                        it++;
                }
+               PostRenderScene(scene);
        }
 
        // only one place that checks for stereo
@@ -908,6 +910,7 @@ void KX_KetsjiEngine::Render()
                                
                                it++;
                        }
+                       PostRenderScene(scene);
                }
        } // if(m_rasterizer->Stereo())
 
@@ -1313,20 +1316,16 @@ void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam)
        
        if (scene->GetPhysicsEnvironment())
                scene->GetPhysicsEnvironment()->debugDrawWorld();
-       
-       m_rasterizer->FlushDebugLines();
-
-       //it's running once for every scene (i.e. overlay scenes have  it running twice). That's not the ideal.
-       PostRenderFrame();
-
-       // Run any post-drawing python callbacks
-       scene->RunDrawingCallbacks(scene->GetPostDrawCB());     
 }
-
-void KX_KetsjiEngine::PostRenderFrame()
+/*
+To run once per scene
+*/
+void KX_KetsjiEngine::PostRenderScene(KX_Scene* scene)
 {
-       m_rendertools->Render2DFilters(m_canvas);
        m_rendertools->MotionBlur(m_rasterizer);
+       scene->Render2DFilters(m_canvas);
+       scene->RunDrawingCallbacks(scene->GetPostDrawCB());     
+       m_rasterizer->FlushDebugLines();
 }
 
 void KX_KetsjiEngine::StopEngine()
index a6ca5fb6519308f5157267dcc9667bfc04c1e942..36db8685afbe86e5fb86aa622f2816fb14e198a4 100644 (file)
@@ -185,7 +185,7 @@ private:
        float                                   m_overrideFrameColorB;
 
        void                                    RenderFrame(KX_Scene* scene, KX_Camera* cam);
-       void                                    PostRenderFrame();
+       void                                    PostRenderScene(KX_Scene* scene);
        void                                    RenderDebugProperties();
        void                                    RenderShadowBuffers(KX_Scene *scene);
        void                                    SetBackGround(KX_WorldInfo* worldinfo);
index 986476acd998b53e4aa08ce32ce78813824996cf..3547a6db545d06960884bb7afda085c8559fb309 100644 (file)
@@ -1842,6 +1842,16 @@ bool KX_Scene::MergeScene(KX_Scene *other)
        return true;
 }
 
+void KX_Scene::Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text)
+{
+       m_filtermanager.EnableFilter(propNames, gameObj, filtermode, pass, text);
+}
+
+void KX_Scene::Render2DFilters(RAS_ICanvas* canvas)
+{
+       m_filtermanager.RenderFilters(canvas);
+}
+
 //----------------------------------------------------------------------------
 //Python
 
index 52062aa57f17a548b6b4cd981eef5c1590cece68..c3fc23f29795f69a92920e0addfacd7dc0435ea8 100644 (file)
@@ -46,6 +46,7 @@
 #include "RAS_Rect.h"
 
 #include "PyObjectPlus.h"
+#include "RAS_2DFilterManager.h"
 
 /**
  * @section Forward declarations
@@ -273,6 +274,7 @@ protected:
 
        struct Scene* m_blenderScene;
 
+       RAS_2DFilterManager m_filtermanager;
 public:        
        KX_Scene(class SCA_IInputDevice* keyboarddevice,
                class SCA_IInputDevice* mousedevice,
@@ -535,6 +537,12 @@ public:
         */
        void SetNodeTree(SG_Tree* root);
 
+       /**
+       * 2D Filters
+       */
+       void Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text);
+       void Render2DFilters(RAS_ICanvas* canvas);
+
 #ifndef DISABLE_PYTHON
        /* --------------------------------------------------------------------- */
        /* Python interface ---------------------------------------------------- */
index 981fd2833b5e0dc960d81f9e26a9e3668f0a02ea..096b1583e3e0bf2c7bde31c25b2dc41e819dae03 100644 (file)
@@ -31,6 +31,7 @@ SET(INC
        ../../../source/kernel/gen_system
        ../../../source/blender/makesdna
        ../../../source/gameengine/SceneGraph
+       ../../../source/gameengine/Ketsji
        ../../../intern/string
        ../../../intern/moto/include
        ../../../extern/glew/include
index d4cc6ab2652a674229653877155c907422aac107..a12d599b60ba6182d0356c2a21c7286f4729d57a 100644 (file)
@@ -45,6 +45,7 @@ CPPFLAGS += -I../../blender/makesdna
 CPPFLAGS += -I../SceneGraph
 CPPFLAGS += -I../BlenderRoutines
 CPPFLAGS += -I../Expressions
+CPPFLAGS += -I../Ketsji
 
 CPPFLAGS += -I$(NAN_PYTHON)/include/python$(NAN_PYTHON_VERSION)
 
index cd3dc359847decac664e7d109b49a3c45533ed1e..7ff7cde788269e952de5832d189fd23a047d2494 100644 (file)
@@ -28,6 +28,7 @@
 #ifndef __RAS_I2DFILTER
 #define __RAS_I2DFILTER
 
+#include "RAS_ICanvas.h"
 #define MAX_RENDER_PASS        100
 
 #ifdef WITH_CXX_GUARDEDALLOC
index 1d069351ff6fb7f8da70f2cc0272e4b0b4e92752..0d89cb41e3cfec986a721bd3aa9a5c607ca5b4b3 100644 (file)
@@ -176,14 +176,6 @@ public:
        virtual
                void
        MotionBlur(RAS_IRasterizer* rasterizer)=0;
-
-       virtual
-               void
-               Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text)=0;
-
-       virtual
-               void
-               Render2DFilters(RAS_ICanvas* canvas)=0;
                
                
 #ifdef WITH_CXX_GUARDEDALLOC