From 7a5415ecdb84d957658f54ac58e70ac1b2bfbf0e Mon Sep 17 00:00:00 2001 From: Rivo Laks Date: Wed, 18 Apr 2007 15:42:06 +0000 Subject: [PATCH] Add a demo/test effect for GLRenderTarget. It renders a small rotating thumbnail of the scene in the middle of the screen. svn path=/branches/work/kwin_composite/; revision=655498 --- effects/CMakeLists.txt | 5 ++ effects/test_fbo.cpp | 102 +++++++++++++++++++++++++++++++++++++++ effects/test_fbo.desktop | 4 ++ effects/test_fbo.h | 51 ++++++++++++++++++++ 4 files changed, 162 insertions(+) create mode 100644 effects/test_fbo.cpp create mode 100644 effects/test_fbo.desktop create mode 100644 effects/test_fbo.h diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index a54f60f96e..f5999ea899 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -44,11 +44,16 @@ if(OPENGL_FOUND) trackmouse.cpp wavywindows.cpp ) + SET(kwin4_effect_tests_sources ${kwin4_effect_tests_sources} + test_fbo.cpp + ) + install( FILES magnifier.desktop shadow.desktop trackmouse.desktop wavywindows.desktop + test_fbo.desktop DESTINATION ${DATA_INSTALL_DIR}/kwin/effects ) install( FILES diff --git a/effects/test_fbo.cpp b/effects/test_fbo.cpp new file mode 100644 index 0000000000..f8bec93948 --- /dev/null +++ b/effects/test_fbo.cpp @@ -0,0 +1,102 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Rivo Laks + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + + +#include "test_fbo.h" + +#include + + +namespace KWin +{ + +KWIN_EFFECT( Test_FBO, TestFBOEffect ); +KWIN_EFFECT_SUPPORTED( Test_FBO, TestFBOEffect::supported() ); + + +TestFBOEffect::TestFBOEffect() : Effect() + { + mRot = 0.0f; + + // Create texture and render target + mTexture = new GLTexture(displayWidth(), displayHeight()); + mTexture->setFilter(GL_LINEAR_MIPMAP_LINEAR); + + mRenderTarget = new GLRenderTarget(mTexture); + + mValid = mRenderTarget->valid(); + } + +bool TestFBOEffect::supported() + { + return hasGLExtension("GL_EXT_framebuffer_object") && + (effects->compositingType() == OpenGLCompositing); + } + + +void TestFBOEffect::prePaintScreen( int* mask, QRegion* region, int time ) + { + if(mValid) + { + *mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS; + // Start rendering to texture + mRenderTarget->enable(); + } + + effects->prePaintScreen(mask, region, time); + } + +void TestFBOEffect::postPaintScreen() + { + // Call the next effect. + effects->postPaintScreen(); + + if(mValid) + { + // Disable render texture + mRenderTarget->disable(); + mTexture->bind(); + + // Render fullscreen quad with screen contents + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex2f(0.0, displayHeight()); + glTexCoord2f(1.0, 0.0); glVertex2f(displayWidth(), displayHeight()); + glTexCoord2f(1.0, 1.0); glVertex2f(displayWidth(), 0.0); + glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 0.0); + glEnd(); + + // Render rotated screen thumbnail + mRot += 0.5f; + glTranslatef(displayWidth()/2.0f, displayHeight()/2.0f, 0.0f); + glRotatef(mRot, 0.0, 0.0, 1.0); + glScalef(0.2, 0.2, 0.2); + glTranslatef(-displayWidth()/2.0f, -displayHeight()/2.0f, 0.0f); + + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex2f(0.0, displayHeight()); + glTexCoord2f(1.0, 0.0); glVertex2f(displayWidth(), displayHeight()); + glTexCoord2f(1.0, 1.0); glVertex2f(displayWidth(), 0.0); + glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 0.0); + glEnd(); + + // Reset matrix and unbind texture + glLoadIdentity(); + + mTexture->unbind(); + + // Make sure the animation continues + effects->addRepaintFull(); + } + + } + + +} // namespace + diff --git a/effects/test_fbo.desktop b/effects/test_fbo.desktop new file mode 100644 index 0000000000..63fd80aed2 --- /dev/null +++ b/effects/test_fbo.desktop @@ -0,0 +1,4 @@ +[Desktop Entry] +Encoding=UTF-8 +Name=Test_FBO +X-KDE-Library=kwin4_effect_tests diff --git a/effects/test_fbo.h b/effects/test_fbo.h new file mode 100644 index 0000000000..2690736f9d --- /dev/null +++ b/effects/test_fbo.h @@ -0,0 +1,51 @@ +/***************************************************************** + KWin - the KDE window manager + This file is part of the KDE project. + +Copyright (C) 2007 Rivo Laks + +You can Freely distribute this program under the GNU General Public +License. See the file "COPYING" for the exact licensing terms. +******************************************************************/ + +#ifndef KWIN_TESTFBOEFFECT_H +#define KWIN_TESTFBOEFFECT_H + +// Include with base class for effects. +#include + +namespace KWin +{ + +class GLRenderTarget; +class GLTexture; + +/** + * Demonstrates usage of GLRenderTarget by first rendering the scene onto a + * texture and then rendering a small rotating thumbnail of the entire scene + * on top of the usual scene. + **/ +class TestFBOEffect : public Effect + { + public: + TestFBOEffect(); + + virtual void prePaintScreen( int* mask, QRegion* region, int time ); + virtual void postPaintScreen(); + + static bool supported(); + + protected: + bool loadData(); + + private: + GLTexture* mTexture; + GLRenderTarget* mRenderTarget; + bool mValid; + + float mRot; + }; + +} // namespace + +#endif