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 "demo_liquid.h"
23
#include <kwinglutils.h>
34
KWIN_EFFECT(demo_liquid, LiquidEffect)
35
KWIN_EFFECT_SUPPORTED(demo_liquid, LiquidEffect::supported())
38
LiquidEffect::LiquidEffect() : Effect()
47
LiquidEffect::~LiquidEffect()
54
bool LiquidEffect::loadData()
56
// If NPOT textures are not supported, use nearest power-of-two sized
57
// texture. It wastes memory, but it's possible to support systems without
58
// NPOT textures that way
59
int texw = displayWidth();
60
int texh = displayHeight();
61
if (!GLTexture::NPOTTextureSupported()) {
62
kWarning(1212) << "NPOT textures not supported, wasting some memory" ;
63
texw = nearestPowerOfTwo(texw);
64
texh = nearestPowerOfTwo(texh);
66
// Create texture and render target
67
mTexture = new GLTexture(texw, texh);
68
mTexture->setFilter(GL_LINEAR_MIPMAP_LINEAR);
69
mTexture->setWrapMode(GL_CLAMP);
71
mRenderTarget = new GLRenderTarget(mTexture);
72
if (!mRenderTarget->valid())
75
QString fragmentshader = KGlobal::dirs()->findResource("data", "kwin/liquid.frag");
76
QString vertexshader = KGlobal::dirs()->findResource("data", "kwin/liquid.vert");
77
if (fragmentshader.isEmpty() || vertexshader.isEmpty()) {
78
kError(1212) << "Couldn't locate shader files" << endl;
81
mShader = new GLShader(vertexshader, fragmentshader);
82
if (!mShader->isValid()) {
83
kError(1212) << "The shader failed to load!" << endl;
87
mShader->setUniform("sceneTex", 0);
88
mShader->setUniform("textureWidth", (float)texw);
89
mShader->setUniform("textureHeight", (float)texh);
95
bool LiquidEffect::supported()
97
return GLRenderTarget::supported() &&
98
GLShader::fragmentShaderSupported() &&
99
(effects->compositingType() == OpenGLCompositing);
103
void LiquidEffect::prePaintScreen(ScreenPrePaintData& data, int time)
105
mTime += time / 1000.0f;
107
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
108
// Start rendering to texture
109
effects->pushRenderTarget(mRenderTarget);
112
effects->prePaintScreen(data, time);
115
void LiquidEffect::postPaintScreen()
117
// Call the next effect.
118
effects->postPaintScreen();
121
// Disable render texture
122
assert(effects->popRenderTarget() == mRenderTarget);
127
mShader->setUniform("time", (float)mTime);
129
// Render fullscreen quad with screen contents
131
glVertex2f(0.0, displayHeight());
132
glVertex2f(displayWidth(), displayHeight());
133
glVertex2f(displayWidth(), 0.0);
134
glVertex2f(0.0, 0.0);
140
// Make sure the animation continues
141
effects->addRepaintFull();