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
This commit is contained in:
parent
cc1a7a9eca
commit
7a5415ecdb
4 changed files with 162 additions and 0 deletions
|
@ -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
|
||||
|
|
102
effects/test_fbo.cpp
Normal file
102
effects/test_fbo.cpp
Normal file
|
@ -0,0 +1,102 @@
|
|||
/*****************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
||||
|
||||
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 <kwinglutils.h>
|
||||
|
||||
|
||||
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
|
||||
|
4
effects/test_fbo.desktop
Normal file
4
effects/test_fbo.desktop
Normal file
|
@ -0,0 +1,4 @@
|
|||
[Desktop Entry]
|
||||
Encoding=UTF-8
|
||||
Name=Test_FBO
|
||||
X-KDE-Library=kwin4_effect_tests
|
51
effects/test_fbo.h
Normal file
51
effects/test_fbo.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*****************************************************************
|
||||
KWin - the KDE window manager
|
||||
This file is part of the KDE project.
|
||||
|
||||
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
||||
|
||||
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 <kwineffects.h>
|
||||
|
||||
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
|
Loading…
Reference in a new issue