2007-04-18 15:42:06 +00:00
|
|
|
/*****************************************************************
|
|
|
|
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>
|
|
|
|
|
2007-04-20 15:53:30 +00:00
|
|
|
#include <assert.h>
|
2007-04-18 15:42:06 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2007-04-28 14:38:06 +00:00
|
|
|
TestFBOEffect::~TestFBOEffect()
|
|
|
|
{
|
|
|
|
delete mTexture;
|
|
|
|
delete mRenderTarget;
|
|
|
|
}
|
|
|
|
|
2007-04-18 15:42:06 +00:00
|
|
|
bool TestFBOEffect::supported()
|
|
|
|
{
|
2007-04-29 15:39:33 +00:00
|
|
|
return GLRenderTarget::supported() && GLTexture::NPOTTextureSupported() &&
|
2007-04-18 15:42:06 +00:00
|
|
|
(effects->compositingType() == OpenGLCompositing);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TestFBOEffect::prePaintScreen( int* mask, QRegion* region, int time )
|
|
|
|
{
|
|
|
|
if(mValid)
|
|
|
|
{
|
|
|
|
*mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
|
|
|
// Start rendering to texture
|
2007-04-20 15:53:30 +00:00
|
|
|
effects->pushRenderTarget(mRenderTarget);
|
2007-04-18 15:42:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
effects->prePaintScreen(mask, region, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TestFBOEffect::postPaintScreen()
|
|
|
|
{
|
|
|
|
// Call the next effect.
|
|
|
|
effects->postPaintScreen();
|
|
|
|
|
|
|
|
if(mValid)
|
|
|
|
{
|
|
|
|
// Disable render texture
|
2007-04-20 15:53:30 +00:00
|
|
|
assert( effects->popRenderTarget() == mRenderTarget );
|
2007-04-18 15:42:06 +00:00
|
|
|
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);
|
|
|
|
|
2007-04-28 14:38:06 +00:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glColor4f(1.0, 1.0, 1.0, 0.8);
|
2007-04-18 15:42:06 +00:00
|
|
|
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();
|
2007-04-28 14:38:06 +00:00
|
|
|
glColor4f(1.0, 1.0, 1.0, 1.0);
|
|
|
|
glDisable(GL_BLEND);
|
2007-04-18 15:42:06 +00:00
|
|
|
|
|
|
|
// Reset matrix and unbind texture
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
mTexture->unbind();
|
|
|
|
|
|
|
|
// Make sure the animation continues
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|