2007-11-27 19:40:25 +00:00
|
|
|
/********************************************************************
|
2007-04-29 17:35:43 +00:00
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-11-27 19:40:25 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include "test_fbo.h"
|
|
|
|
|
|
|
|
#include <kwinglutils.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(test_fbo, TestFBOEffect)
|
|
|
|
KWIN_EFFECT_SUPPORTED(test_fbo, TestFBOEffect::supported())
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
TestFBOEffect::TestFBOEffect() : Effect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
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();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
TestFBOEffect::~TestFBOEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
delete mTexture;
|
|
|
|
delete mRenderTarget;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool TestFBOEffect::supported()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
return GLRenderTarget::supported() && GLTexture::NPOTTextureSupported() &&
|
2011-01-30 14:34:42 +00:00
|
|
|
(effects->compositingType() == OpenGLCompositing);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void TestFBOEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (mValid) {
|
2007-07-07 14:01:32 +00:00
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
2007-04-29 17:35:43 +00:00
|
|
|
// Start rendering to texture
|
|
|
|
effects->pushRenderTarget(mRenderTarget);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2007-07-07 14:01:32 +00:00
|
|
|
effects->prePaintScreen(data, time);
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void TestFBOEffect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
// Call the next effect.
|
|
|
|
effects->postPaintScreen();
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (mValid) {
|
2007-04-29 17:35:43 +00:00
|
|
|
// Disable render texture
|
2011-01-30 14:34:42 +00:00
|
|
|
assert(effects->popRenderTarget() == mRenderTarget);
|
2007-04-29 17:35:43 +00:00
|
|
|
mTexture->bind();
|
|
|
|
|
|
|
|
// Render fullscreen quad with screen contents
|
|
|
|
glBegin(GL_QUADS);
|
2011-01-30 14:34:42 +00:00
|
|
|
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);
|
2007-04-29 17:35:43 +00:00
|
|
|
glEnd();
|
|
|
|
|
|
|
|
// Render rotated screen thumbnail
|
|
|
|
mRot += 0.5f;
|
2011-01-30 14:34:42 +00:00
|
|
|
glTranslatef(displayWidth() / 2.0f, displayHeight() / 2.0f, 0.0f);
|
2007-04-29 17:35:43 +00:00
|
|
|
glRotatef(mRot, 0.0, 0.0, 1.0);
|
|
|
|
glScalef(0.2, 0.2, 0.2);
|
2011-01-30 14:34:42 +00:00
|
|
|
glTranslatef(-displayWidth() / 2.0f, -displayHeight() / 2.0f, 0.0f);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
glColor4f(1.0, 1.0, 1.0, 0.8);
|
|
|
|
glBegin(GL_QUADS);
|
2011-01-30 14:34:42 +00:00
|
|
|
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);
|
2007-04-29 17:35:43 +00:00
|
|
|
glEnd();
|
|
|
|
glColor4f(1.0, 1.0, 1.0, 1.0);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
|
|
|
// Reset matrix and unbind texture
|
|
|
|
glLoadIdentity();
|
|
|
|
|
|
|
|
mTexture->unbind();
|
|
|
|
|
|
|
|
// Make sure the animation continues
|
|
|
|
effects->addRepaintFull();
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|