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 *********************************************************************/
23 #include <kwinglutils.h>
30 KWIN_EFFECT( test_fbo
, TestFBOEffect
)
31 KWIN_EFFECT_SUPPORTED( test_fbo
, TestFBOEffect::supported() )
34 TestFBOEffect::TestFBOEffect() : Effect()
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()
53 bool TestFBOEffect::supported()
55 return GLRenderTarget::supported() && GLTexture::NPOTTextureSupported() &&
56 (effects
->compositingType() == OpenGLCompositing
);
60 void TestFBOEffect::prePaintScreen( ScreenPrePaintData
& data
, int time
)
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();
79 // Disable render texture
80 assert( effects
->popRenderTarget() == mRenderTarget
);
83 // Render fullscreen quad with screen contents
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);
91 // Render rotated screen thumbnail
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
);
99 glColor4f(1.0, 1.0, 1.0, 0.8);
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);
106 glColor4f(1.0, 1.0, 1.0, 1.0);
109 // Reset matrix and unbind texture
114 // Make sure the animation continues
115 effects
->addRepaintFull();