not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kwin / effects / test / test_fbo.cpp
blob3b12b535d0ab4598bf9191b63ec2732f6bd3faa4
1 /********************************************************************
2 KWin - the KDE window manager
3 This file is part of the KDE project.
5 Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *********************************************************************/
21 #include "test_fbo.h"
23 #include <kwinglutils.h>
25 #include <assert.h>
27 namespace KWin
30 KWIN_EFFECT( test_fbo, TestFBOEffect )
31 KWIN_EFFECT_SUPPORTED( test_fbo, TestFBOEffect::supported() )
34 TestFBOEffect::TestFBOEffect() : Effect()
36 mRot = 0.0f;
38 // Create texture and render target
39 mTexture = new GLTexture(displayWidth(), displayHeight());
40 mTexture->setFilter(GL_LINEAR_MIPMAP_LINEAR);
42 mRenderTarget = new GLRenderTarget(mTexture);
44 mValid = mRenderTarget->valid();
47 TestFBOEffect::~TestFBOEffect()
49 delete mTexture;
50 delete mRenderTarget;
53 bool TestFBOEffect::supported()
55 return GLRenderTarget::supported() && GLTexture::NPOTTextureSupported() &&
56 (effects->compositingType() == OpenGLCompositing);
60 void TestFBOEffect::prePaintScreen( ScreenPrePaintData& data, int time )
62 if(mValid)
64 data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
65 // Start rendering to texture
66 effects->pushRenderTarget(mRenderTarget);
69 effects->prePaintScreen(data, time);
72 void TestFBOEffect::postPaintScreen()
74 // Call the next effect.
75 effects->postPaintScreen();
77 if(mValid)
79 // Disable render texture
80 assert( effects->popRenderTarget() == mRenderTarget );
81 mTexture->bind();
83 // Render fullscreen quad with screen contents
84 glBegin(GL_QUADS);
85 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, displayHeight());
86 glTexCoord2f(1.0, 0.0); glVertex2f(displayWidth(), displayHeight());
87 glTexCoord2f(1.0, 1.0); glVertex2f(displayWidth(), 0.0);
88 glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 0.0);
89 glEnd();
91 // Render rotated screen thumbnail
92 mRot += 0.5f;
93 glTranslatef(displayWidth()/2.0f, displayHeight()/2.0f, 0.0f);
94 glRotatef(mRot, 0.0, 0.0, 1.0);
95 glScalef(0.2, 0.2, 0.2);
96 glTranslatef(-displayWidth()/2.0f, -displayHeight()/2.0f, 0.0f);
98 glEnable(GL_BLEND);
99 glColor4f(1.0, 1.0, 1.0, 0.8);
100 glBegin(GL_QUADS);
101 glTexCoord2f(0.0, 0.0); glVertex2f(0.0, displayHeight());
102 glTexCoord2f(1.0, 0.0); glVertex2f(displayWidth(), displayHeight());
103 glTexCoord2f(1.0, 1.0); glVertex2f(displayWidth(), 0.0);
104 glTexCoord2f(0.0, 1.0); glVertex2f(0.0, 0.0);
105 glEnd();
106 glColor4f(1.0, 1.0, 1.0, 1.0);
107 glDisable(GL_BLEND);
109 // Reset matrix and unbind texture
110 glLoadIdentity();
112 mTexture->unbind();
114 // Make sure the animation continues
115 effects->addRepaintFull();
121 } // namespace