From 7250a8edcdc7562cf471fccb4e3213beac79c049 Mon Sep 17 00:00:00 2001 From: Rivo Laks Date: Fri, 20 Apr 2007 15:53:30 +0000 Subject: [PATCH] Support having multiple rendertarget-using effects active at once svn path=/branches/work/kwin_composite/; revision=656210 --- effects.cpp | 22 ++++++++++++++++++++++ effects.h | 6 ++++++ effects/demo_liquid.cpp | 5 +++-- effects/test_fbo.cpp | 5 +++-- lib/kwineffects.h | 4 ++++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/effects.cpp b/effects.cpp index 753c7f87d3..4bfdb7833a 100644 --- a/effects.cpp +++ b/effects.cpp @@ -16,6 +16,7 @@ License. See the file "COPYING" for the exact licensing terms. #include "scene_xrender.h" #include "scene_opengl.h" #include "workspace.h" +#include "kwinglutils.h" #include @@ -393,6 +394,27 @@ EffectWindow* EffectsHandlerImpl::currentTabBoxWindow() const return NULL; } +void EffectsHandlerImpl::pushRenderTarget(GLRenderTarget* target) +{ +#ifdef HAVE_OPENGL + target->enable(); + render_targets.push(target); +#endif +} + +GLRenderTarget* EffectsHandlerImpl::popRenderTarget() +{ +#ifdef HAVE_OPENGL + GLRenderTarget* ret = render_targets.pop(); + ret->disable(); + if( !render_targets.isEmpty() ) + render_targets.top()->enable(); + return ret; +#else + return 0; +#endif +} + void EffectsHandlerImpl::addRepaintFull() { Workspace::self()->addRepaintFull(); diff --git a/effects.h b/effects.h index b5ecdedf72..6f1950f269 100644 --- a/effects.h +++ b/effects.h @@ -15,6 +15,8 @@ License. See the file "COPYING" for the exact licensing terms. #include "scene.h" +#include + namespace KWin @@ -60,6 +62,9 @@ class EffectsHandlerImpl : public EffectsHandler virtual int currentTabBoxDesktop() const; virtual EffectWindow* currentTabBoxWindow() const; + virtual void pushRenderTarget(GLRenderTarget* target); + virtual GLRenderTarget* popRenderTarget(); + virtual void addRepaintFull(); virtual void addRepaint( const QRect& r ); virtual void addRepaint( int x, int y, int w, int h ); @@ -107,6 +112,7 @@ class EffectsHandlerImpl : public EffectsHandler protected: KLibrary* findEffectLibrary( const QString& effectname ); Effect* keyboard_grab_effect; + QStack render_targets; }; class EffectWindowImpl : public EffectWindow diff --git a/effects/demo_liquid.cpp b/effects/demo_liquid.cpp index 00d7248f83..2808eff490 100644 --- a/effects/demo_liquid.cpp +++ b/effects/demo_liquid.cpp @@ -17,6 +17,7 @@ License. See the file "COPYING" for the exact licensing terms. #include #include +#include namespace KWin @@ -79,7 +80,7 @@ void LiquidEffect::prePaintScreen( int* mask, QRegion* region, int time ) { *mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; // Start rendering to texture - mRenderTarget->enable(); + effects->pushRenderTarget(mRenderTarget); } effects->prePaintScreen(mask, region, time); @@ -93,7 +94,7 @@ void LiquidEffect::postPaintScreen() if(mValid) { // Disable render texture - mRenderTarget->disable(); + assert( effects->popRenderTarget() == mRenderTarget ); mTexture->bind(); // Use the shader diff --git a/effects/test_fbo.cpp b/effects/test_fbo.cpp index f8bec93948..98c1358b68 100644 --- a/effects/test_fbo.cpp +++ b/effects/test_fbo.cpp @@ -13,6 +13,7 @@ License. See the file "COPYING" for the exact licensing terms. #include +#include namespace KWin { @@ -47,7 +48,7 @@ void TestFBOEffect::prePaintScreen( int* mask, QRegion* region, int time ) { *mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; // Start rendering to texture - mRenderTarget->enable(); + effects->pushRenderTarget(mRenderTarget); } effects->prePaintScreen(mask, region, time); @@ -61,7 +62,7 @@ void TestFBOEffect::postPaintScreen() if(mValid) { // Disable render texture - mRenderTarget->disable(); + assert( effects->popRenderTarget() == mRenderTarget ); mTexture->bind(); // Render fullscreen quad with screen contents diff --git a/lib/kwineffects.h b/lib/kwineffects.h index 9ae0c39c20..0013cfc391 100644 --- a/lib/kwineffects.h +++ b/lib/kwineffects.h @@ -36,6 +36,7 @@ class EffectWindow; class EffectWindowGroup; class Effect; class Vertex; +class GLRenderTarget; typedef QPair< QString, Effect* > EffectPair; typedef QPair< Effect*, Window > InputWindowPair; @@ -208,6 +209,9 @@ class KWIN_EXPORT EffectsHandler virtual int currentTabBoxDesktop() const = 0; virtual EffectWindow* currentTabBoxWindow() const = 0; + virtual void pushRenderTarget(GLRenderTarget* target) = 0; + virtual GLRenderTarget* popRenderTarget() = 0; + // Repaints the entire workspace virtual void addRepaintFull() = 0; virtual void addRepaint( const QRect& r ) = 0;