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
|
|
|
|
2009-02-05 15:35:38 +00:00
|
|
|
#include "explosion.h"
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include <kwinglutils.h>
|
2011-02-19 10:08:43 +00:00
|
|
|
#include <kwinglplatform.h>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-07 19:44:50 +00:00
|
|
|
#include <QMatrix4x4>
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
#include <KStandardDirs>
|
|
|
|
#include <kdebug.h>
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
KWIN_EFFECT(explosion, ExplosionEffect)
|
|
|
|
KWIN_EFFECT_SUPPORTED(explosion, ExplosionEffect::supported())
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
ExplosionEffect::ExplosionEffect() : Effect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
mShader = 0;
|
|
|
|
mStartOffsetTex = 0;
|
|
|
|
mEndOffsetTex = 0;
|
|
|
|
|
|
|
|
mActiveAnimations = 0;
|
|
|
|
mValid = true;
|
|
|
|
mInited = false;
|
2011-02-27 08:25:45 +00:00
|
|
|
connect(effects, SIGNAL(windowClosed(EffectWindow*)), this, SLOT(slotWindowClosed(EffectWindow*)));
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
ExplosionEffect::~ExplosionEffect()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
delete mShader;
|
|
|
|
delete mStartOffsetTex;
|
|
|
|
delete mEndOffsetTex;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool ExplosionEffect::supported()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
2011-02-19 10:08:43 +00:00
|
|
|
return GLPlatform::instance()->supports(GLSL) &&
|
2011-01-30 14:34:42 +00:00
|
|
|
(effects->compositingType() == OpenGLCompositing);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
bool ExplosionEffect::loadData()
|
|
|
|
{
|
|
|
|
mInited = true;
|
|
|
|
QString shadername("explosion");
|
2011-01-07 19:44:50 +00:00
|
|
|
const QString fragmentshader = KGlobal::dirs()->findResource("data", "kwin/explosion.frag");
|
2007-04-29 17:35:43 +00:00
|
|
|
QString starttexture = KGlobal::dirs()->findResource("data", "kwin/explosion-start.png");
|
|
|
|
QString endtexture = KGlobal::dirs()->findResource("data", "kwin/explosion-end.png");
|
2011-01-30 14:34:42 +00:00
|
|
|
if (starttexture.isEmpty() || endtexture.isEmpty()) {
|
2008-11-17 15:04:52 +00:00
|
|
|
kError(1212) << "Couldn't locate texture files" << endl;
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-01-07 19:44:50 +00:00
|
|
|
mShader = ShaderManager::instance()->loadFragmentShader(ShaderManager::GenericShader, fragmentshader);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (!mShader->isValid()) {
|
2008-11-17 15:04:52 +00:00
|
|
|
kError(1212) << "The shader failed to load!" << endl;
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
2011-01-07 19:44:50 +00:00
|
|
|
ShaderManager::instance()->pushShader(mShader);
|
2007-04-29 17:35:43 +00:00
|
|
|
mShader->setUniform("startOffsetTexture", 4);
|
|
|
|
mShader->setUniform("endOffsetTexture", 5);
|
2011-01-07 19:44:50 +00:00
|
|
|
ShaderManager::instance()->popShader();
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mStartOffsetTex = new GLTexture(starttexture);
|
|
|
|
mEndOffsetTex = new GLTexture(endtexture);
|
2011-01-30 14:34:42 +00:00
|
|
|
if (mStartOffsetTex->isNull() || mEndOffsetTex->isNull()) {
|
2008-11-17 15:04:52 +00:00
|
|
|
kError(1212) << "The textures failed to load!" << endl;
|
2007-04-29 17:35:43 +00:00
|
|
|
return false;
|
2011-01-30 14:34:42 +00:00
|
|
|
} else {
|
|
|
|
mStartOffsetTex->setFilter(GL_LINEAR);
|
|
|
|
mEndOffsetTex->setFilter(GL_LINEAR);
|
2007-04-29 17:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ExplosionEffect::prePaintScreen(ScreenPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (mActiveAnimations > 0)
|
2007-04-29 17:35:43 +00:00
|
|
|
// We need to mark the screen as transformed. Otherwise the whole screen
|
|
|
|
// won't be repainted, resulting in artefacts
|
2007-07-07 14:01:32 +00:00
|
|
|
data.mask |= PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
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
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ExplosionEffect::prePaintWindow(EffectWindow* w, WindowPrePaintData& data, int time)
|
|
|
|
{
|
|
|
|
if (mWindows.contains(w)) {
|
|
|
|
if (mValid && !mInited)
|
2007-04-29 17:35:43 +00:00
|
|
|
mValid = loadData();
|
2011-01-30 14:34:42 +00:00
|
|
|
if (mValid) {
|
|
|
|
mWindows[ w ] += time / animationTime(700.0); // complete change in 700ms
|
|
|
|
if (mWindows[ w ] < 1) {
|
2007-07-19 13:32:46 +00:00
|
|
|
data.setTranslucent();
|
2007-07-19 14:05:59 +00:00
|
|
|
data.setTransformed();
|
2011-01-30 14:34:42 +00:00
|
|
|
w->enablePainting(EffectWindow::PAINT_DISABLED_BY_DELETE);
|
|
|
|
} else {
|
|
|
|
mWindows.remove(w);
|
2007-04-29 17:35:43 +00:00
|
|
|
w->unrefWindow();
|
|
|
|
mActiveAnimations--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->prePaintWindow(w, data, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExplosionEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data)
|
|
|
|
{
|
2007-04-29 17:35:43 +00:00
|
|
|
// Make sure we have OpenGL compositing and the window is vidible and not a
|
|
|
|
// special window
|
2011-01-30 14:34:42 +00:00
|
|
|
bool useshader = (mValid && mWindows.contains(w));
|
|
|
|
if (useshader) {
|
2007-09-03 15:00:43 +00:00
|
|
|
double maxscaleadd = 1.5f;
|
2011-01-30 14:34:42 +00:00
|
|
|
double scale = 1 + maxscaleadd * mWindows[w];
|
2007-04-29 17:35:43 +00:00
|
|
|
data.xScale = scale;
|
|
|
|
data.yScale = scale;
|
2011-01-30 14:34:42 +00:00
|
|
|
data.xTranslate += int(w->width() / 2 * (1 - scale));
|
|
|
|
data.yTranslate += int(w->height() / 2 * (1 - scale));
|
2007-04-29 17:35:43 +00:00
|
|
|
data.opacity *= 0.99; // Force blending
|
2011-01-07 19:44:50 +00:00
|
|
|
ShaderManager *manager = ShaderManager::instance();
|
|
|
|
GLShader *shader = manager->pushShader(ShaderManager::GenericShader);
|
|
|
|
QMatrix4x4 screenTransformation = shader->getUniformMatrix4x4("screenTransformation");
|
|
|
|
manager->popShader();
|
|
|
|
ShaderManager::instance()->pushShader(mShader);
|
|
|
|
mShader->setUniform("screenTransformation", screenTransformation);
|
2007-04-29 17:35:43 +00:00
|
|
|
mShader->setUniform("factor", (float)mWindows[w]);
|
2007-09-03 15:00:43 +00:00
|
|
|
mShader->setUniform("scale", (float)scale);
|
2007-04-29 17:35:43 +00:00
|
|
|
glActiveTexture(GL_TEXTURE4);
|
|
|
|
mStartOffsetTex->bind();
|
|
|
|
glActiveTexture(GL_TEXTURE5);
|
|
|
|
mEndOffsetTex->bind();
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
2007-08-10 11:26:58 +00:00
|
|
|
data.shader = mShader;
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
// Call the next effect.
|
2011-01-30 14:34:42 +00:00
|
|
|
effects->paintWindow(w, mask, region, data);
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
if (useshader) {
|
2011-01-07 19:44:50 +00:00
|
|
|
ShaderManager::instance()->popShader();
|
2007-04-29 17:35:43 +00:00
|
|
|
glActiveTexture(GL_TEXTURE4);
|
|
|
|
mStartOffsetTex->unbind();
|
|
|
|
glActiveTexture(GL_TEXTURE5);
|
|
|
|
mEndOffsetTex->unbind();
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
void ExplosionEffect::postPaintScreen()
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
if (mActiveAnimations > 0)
|
2007-04-29 17:35:43 +00:00
|
|
|
effects->addRepaintFull();
|
|
|
|
|
|
|
|
// Call the next effect.
|
|
|
|
effects->postPaintScreen();
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-02-27 08:25:45 +00:00
|
|
|
void ExplosionEffect::slotWindowClosed(EffectWindow* c)
|
2011-01-30 14:34:42 +00:00
|
|
|
{
|
|
|
|
const void* e = c->data(WindowClosedGrabRole).value<void*>();
|
|
|
|
if (e && e != this)
|
2010-01-11 04:52:19 +00:00
|
|
|
return;
|
2011-01-30 14:34:42 +00:00
|
|
|
if (c->isOnCurrentDesktop() && !c->isMinimized()) {
|
2007-04-29 17:35:43 +00:00
|
|
|
mWindows[ c ] = 0; // count up to 1
|
|
|
|
c->addRepaintFull();
|
|
|
|
c->refWindow();
|
|
|
|
mActiveAnimations++;
|
|
|
|
}
|
2011-01-30 14:34:42 +00:00
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
2011-01-30 14:34:42 +00:00
|
|
|
void ExplosionEffect::windowDeleted(EffectWindow* c)
|
|
|
|
{
|
|
|
|
mWindows.remove(c);
|
|
|
|
}
|
2007-04-29 17:35:43 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|