2007-03-16 13:02:47 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2007 Rivo Laks <rivolaks@hot.ee>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include "explosioneffect.h"
|
|
|
|
|
|
|
|
#include <scene_opengl.h>
|
|
|
|
#include <workspace.h>
|
|
|
|
#include <client.h>
|
|
|
|
#include <glutils.h>
|
|
|
|
#include <deleted.h>
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
#include <KStandardDirs>
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
2007-04-05 12:07:35 +00:00
|
|
|
namespace KWin
|
2007-03-16 13:02:47 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
ExplosionEffect::ExplosionEffect() : Effect()
|
|
|
|
{
|
|
|
|
mActiveAnimations = 0;
|
|
|
|
mValid = true;
|
|
|
|
mInited = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExplosionEffect::loadData()
|
|
|
|
{
|
|
|
|
mInited = true;
|
|
|
|
QString shadername("explosion");
|
|
|
|
QString fragmentshader = KGlobal::dirs()->findResource("data", "kwin/explosion.frag");
|
|
|
|
QString vertexshader = KGlobal::dirs()->findResource("data", "kwin/explosion.vert");
|
Add GLTexture class. This is a convenient wrapper around managing an OpenGL texture, as well as loading an image into it. Includes support for loading from QImage, QPixmap, and a file. Defaults to a GL_TEXTURE_2D target, and will scale image if necessary.
Also add SceneOpenGL::Texture class, based on GLTexture. Optimised for SceneOpenGL::Window, this adds support for loading from an X Pixmap, as well as taking advantage of texture_from_pixmap/shm when available. Automatically detects what texture target should be used, so be sure to enableUnnormalizedTexCoords() before painting.
Make SceneOpenGL::Window, BoxSwitchEffect, and ExplosionEffect use the new classes.
svn path=/branches/work/kwin_composite/; revision=645125
2007-03-21 18:14:09 +00:00
|
|
|
QString starttexture = KGlobal::dirs()->findResource("data", "kwin/explosion-start.png");
|
|
|
|
QString endtexture = KGlobal::dirs()->findResource("data", "kwin/explosion-end.png");
|
2007-03-16 13:02:47 +00:00
|
|
|
if(fragmentshader.isEmpty() || vertexshader.isEmpty())
|
|
|
|
{
|
|
|
|
kError() << k_funcinfo << "Couldn't locate shader files" << endl;
|
|
|
|
return false;
|
|
|
|
}
|
Add GLTexture class. This is a convenient wrapper around managing an OpenGL texture, as well as loading an image into it. Includes support for loading from QImage, QPixmap, and a file. Defaults to a GL_TEXTURE_2D target, and will scale image if necessary.
Also add SceneOpenGL::Texture class, based on GLTexture. Optimised for SceneOpenGL::Window, this adds support for loading from an X Pixmap, as well as taking advantage of texture_from_pixmap/shm when available. Automatically detects what texture target should be used, so be sure to enableUnnormalizedTexCoords() before painting.
Make SceneOpenGL::Window, BoxSwitchEffect, and ExplosionEffect use the new classes.
svn path=/branches/work/kwin_composite/; revision=645125
2007-03-21 18:14:09 +00:00
|
|
|
if(starttexture.isEmpty() || endtexture.isEmpty())
|
|
|
|
{
|
|
|
|
kError() << k_funcinfo << "Couldn't locate texture files" << endl;
|
|
|
|
return false;
|
|
|
|
}
|
2007-03-16 13:02:47 +00:00
|
|
|
|
|
|
|
mShader = new GLShader(vertexshader, fragmentshader);
|
|
|
|
if(!mShader->isValid())
|
|
|
|
{
|
|
|
|
kError() << k_funcinfo << "The shader failed to load!" << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mShader->bind();
|
|
|
|
mShader->setUniform("winTexture", 0);
|
|
|
|
mShader->setUniform("startOffsetTexture", 4);
|
|
|
|
mShader->setUniform("endOffsetTexture", 5);
|
|
|
|
mShader->unbind();
|
|
|
|
}
|
|
|
|
|
Add GLTexture class. This is a convenient wrapper around managing an OpenGL texture, as well as loading an image into it. Includes support for loading from QImage, QPixmap, and a file. Defaults to a GL_TEXTURE_2D target, and will scale image if necessary.
Also add SceneOpenGL::Texture class, based on GLTexture. Optimised for SceneOpenGL::Window, this adds support for loading from an X Pixmap, as well as taking advantage of texture_from_pixmap/shm when available. Automatically detects what texture target should be used, so be sure to enableUnnormalizedTexCoords() before painting.
Make SceneOpenGL::Window, BoxSwitchEffect, and ExplosionEffect use the new classes.
svn path=/branches/work/kwin_composite/; revision=645125
2007-03-21 18:14:09 +00:00
|
|
|
mStartOffsetTex = new GLTexture(starttexture);
|
|
|
|
mEndOffsetTex = new GLTexture(endtexture);
|
|
|
|
if(mStartOffsetTex->isNull() || mEndOffsetTex->isNull())
|
|
|
|
{
|
|
|
|
kError() << k_funcinfo << "The textures failed to load!" << endl;
|
2007-03-16 13:02:47 +00:00
|
|
|
return false;
|
|
|
|
}
|
Add GLTexture class. This is a convenient wrapper around managing an OpenGL texture, as well as loading an image into it. Includes support for loading from QImage, QPixmap, and a file. Defaults to a GL_TEXTURE_2D target, and will scale image if necessary.
Also add SceneOpenGL::Texture class, based on GLTexture. Optimised for SceneOpenGL::Window, this adds support for loading from an X Pixmap, as well as taking advantage of texture_from_pixmap/shm when available. Automatically detects what texture target should be used, so be sure to enableUnnormalizedTexCoords() before painting.
Make SceneOpenGL::Window, BoxSwitchEffect, and ExplosionEffect use the new classes.
svn path=/branches/work/kwin_composite/; revision=645125
2007-03-21 18:14:09 +00:00
|
|
|
else
|
2007-03-16 13:02:47 +00:00
|
|
|
{
|
Add GLTexture class. This is a convenient wrapper around managing an OpenGL texture, as well as loading an image into it. Includes support for loading from QImage, QPixmap, and a file. Defaults to a GL_TEXTURE_2D target, and will scale image if necessary.
Also add SceneOpenGL::Texture class, based on GLTexture. Optimised for SceneOpenGL::Window, this adds support for loading from an X Pixmap, as well as taking advantage of texture_from_pixmap/shm when available. Automatically detects what texture target should be used, so be sure to enableUnnormalizedTexCoords() before painting.
Make SceneOpenGL::Window, BoxSwitchEffect, and ExplosionEffect use the new classes.
svn path=/branches/work/kwin_composite/; revision=645125
2007-03-21 18:14:09 +00:00
|
|
|
mStartOffsetTex->setFilter( GL_LINEAR );
|
|
|
|
mEndOffsetTex->setFilter( GL_LINEAR );
|
2007-03-16 13:02:47 +00:00
|
|
|
}
|
|
|
|
|
Add GLTexture class. This is a convenient wrapper around managing an OpenGL texture, as well as loading an image into it. Includes support for loading from QImage, QPixmap, and a file. Defaults to a GL_TEXTURE_2D target, and will scale image if necessary.
Also add SceneOpenGL::Texture class, based on GLTexture. Optimised for SceneOpenGL::Window, this adds support for loading from an X Pixmap, as well as taking advantage of texture_from_pixmap/shm when available. Automatically detects what texture target should be used, so be sure to enableUnnormalizedTexCoords() before painting.
Make SceneOpenGL::Window, BoxSwitchEffect, and ExplosionEffect use the new classes.
svn path=/branches/work/kwin_composite/; revision=645125
2007-03-21 18:14:09 +00:00
|
|
|
return true;
|
2007-03-16 13:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExplosionEffect::prePaintScreen( int* mask, QRegion* region, int time )
|
|
|
|
{
|
|
|
|
if( mActiveAnimations > 0 )
|
|
|
|
// We need to mark the screen as transformed. Otherwise the whole screen
|
|
|
|
// won't be repainted, resulting in artefacts
|
Add GLTexture class. This is a convenient wrapper around managing an OpenGL texture, as well as loading an image into it. Includes support for loading from QImage, QPixmap, and a file. Defaults to a GL_TEXTURE_2D target, and will scale image if necessary.
Also add SceneOpenGL::Texture class, based on GLTexture. Optimised for SceneOpenGL::Window, this adds support for loading from an X Pixmap, as well as taking advantage of texture_from_pixmap/shm when available. Automatically detects what texture target should be used, so be sure to enableUnnormalizedTexCoords() before painting.
Make SceneOpenGL::Window, BoxSwitchEffect, and ExplosionEffect use the new classes.
svn path=/branches/work/kwin_composite/; revision=645125
2007-03-21 18:14:09 +00:00
|
|
|
*mask |= Scene::PAINT_SCREEN_WITH_TRANSFORMED_WINDOWS;
|
2007-03-16 13:02:47 +00:00
|
|
|
|
|
|
|
effects->prePaintScreen(mask, region, time);
|
|
|
|
}
|
|
|
|
|
2007-03-25 10:48:07 +00:00
|
|
|
void ExplosionEffect::prePaintWindow( EffectWindow* w, int* mask, QRegion* paint, QRegion* clip, int time )
|
2007-03-16 13:02:47 +00:00
|
|
|
{
|
|
|
|
if( mWindows.contains( w ))
|
|
|
|
{
|
2007-03-27 14:15:41 +00:00
|
|
|
SceneOpenGL::Window* glwin = dynamic_cast< SceneOpenGL::Window* >( w->sceneWindow() );
|
|
|
|
if( mValid && glwin && !mInited )
|
|
|
|
mValid = loadData();
|
|
|
|
if( mValid )
|
2007-03-16 13:02:47 +00:00
|
|
|
{
|
2007-03-27 14:15:41 +00:00
|
|
|
mWindows[ w ] += time / 700.0; // complete change in 700ms
|
|
|
|
if( mWindows[ w ] < 1 )
|
|
|
|
{
|
|
|
|
*mask |= Scene::PAINT_WINDOW_TRANSLUCENT | Scene::PAINT_WINDOW_TRANSFORMED;
|
|
|
|
*mask &= ~Scene::PAINT_WINDOW_OPAQUE;
|
|
|
|
w->enablePainting( Scene::Window::PAINT_DISABLED_BY_DELETE );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mWindows.remove( w );
|
|
|
|
static_cast< Deleted* >( w->window())->unrefWindow();
|
|
|
|
mActiveAnimations--;
|
|
|
|
}
|
2007-03-16 13:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-25 10:48:07 +00:00
|
|
|
effects->prePaintWindow( w, mask, paint, clip, time );
|
2007-03-16 13:02:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExplosionEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowPaintData& data )
|
|
|
|
{
|
|
|
|
// Make sure we have OpenGL compositing and the window is vidible and not a
|
|
|
|
// special window
|
|
|
|
SceneOpenGL::Window* glwin = dynamic_cast< SceneOpenGL::Window* >( w->sceneWindow() );
|
|
|
|
bool useshader = ( mValid && glwin && mWindows.contains( w ) );
|
|
|
|
if( useshader )
|
|
|
|
{
|
|
|
|
float maxscaleadd = 1.5f;
|
|
|
|
float scale = 1 + maxscaleadd*mWindows[w];
|
|
|
|
data.xScale = scale;
|
|
|
|
data.yScale = scale;
|
|
|
|
data.xTranslate += int( w->window()->width() / 2 * ( 1 - scale ));
|
|
|
|
data.yTranslate += int( w->window()->height() / 2 * ( 1 - scale ));
|
|
|
|
data.opacity *= 0.99; // Force blending
|
|
|
|
mShader->bind();
|
|
|
|
mShader->setUniform("factor", (float)mWindows[w]);
|
|
|
|
mShader->setUniform("scale", scale);
|
|
|
|
glActiveTexture(GL_TEXTURE4);
|
Add GLTexture class. This is a convenient wrapper around managing an OpenGL texture, as well as loading an image into it. Includes support for loading from QImage, QPixmap, and a file. Defaults to a GL_TEXTURE_2D target, and will scale image if necessary.
Also add SceneOpenGL::Texture class, based on GLTexture. Optimised for SceneOpenGL::Window, this adds support for loading from an X Pixmap, as well as taking advantage of texture_from_pixmap/shm when available. Automatically detects what texture target should be used, so be sure to enableUnnormalizedTexCoords() before painting.
Make SceneOpenGL::Window, BoxSwitchEffect, and ExplosionEffect use the new classes.
svn path=/branches/work/kwin_composite/; revision=645125
2007-03-21 18:14:09 +00:00
|
|
|
mStartOffsetTex->bind();
|
2007-03-16 13:02:47 +00:00
|
|
|
glActiveTexture(GL_TEXTURE5);
|
Add GLTexture class. This is a convenient wrapper around managing an OpenGL texture, as well as loading an image into it. Includes support for loading from QImage, QPixmap, and a file. Defaults to a GL_TEXTURE_2D target, and will scale image if necessary.
Also add SceneOpenGL::Texture class, based on GLTexture. Optimised for SceneOpenGL::Window, this adds support for loading from an X Pixmap, as well as taking advantage of texture_from_pixmap/shm when available. Automatically detects what texture target should be used, so be sure to enableUnnormalizedTexCoords() before painting.
Make SceneOpenGL::Window, BoxSwitchEffect, and ExplosionEffect use the new classes.
svn path=/branches/work/kwin_composite/; revision=645125
2007-03-21 18:14:09 +00:00
|
|
|
mEndOffsetTex->bind();
|
2007-03-16 13:02:47 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
glwin->setShader(mShader);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Call the next effect.
|
|
|
|
effects->paintWindow( w, mask, region, data );
|
|
|
|
|
|
|
|
if( useshader )
|
|
|
|
{
|
|
|
|
mShader->unbind();
|
|
|
|
glActiveTexture(GL_TEXTURE4);
|
Add GLTexture class. This is a convenient wrapper around managing an OpenGL texture, as well as loading an image into it. Includes support for loading from QImage, QPixmap, and a file. Defaults to a GL_TEXTURE_2D target, and will scale image if necessary.
Also add SceneOpenGL::Texture class, based on GLTexture. Optimised for SceneOpenGL::Window, this adds support for loading from an X Pixmap, as well as taking advantage of texture_from_pixmap/shm when available. Automatically detects what texture target should be used, so be sure to enableUnnormalizedTexCoords() before painting.
Make SceneOpenGL::Window, BoxSwitchEffect, and ExplosionEffect use the new classes.
svn path=/branches/work/kwin_composite/; revision=645125
2007-03-21 18:14:09 +00:00
|
|
|
mStartOffsetTex->unbind();
|
2007-03-16 13:02:47 +00:00
|
|
|
glActiveTexture(GL_TEXTURE5);
|
Add GLTexture class. This is a convenient wrapper around managing an OpenGL texture, as well as loading an image into it. Includes support for loading from QImage, QPixmap, and a file. Defaults to a GL_TEXTURE_2D target, and will scale image if necessary.
Also add SceneOpenGL::Texture class, based on GLTexture. Optimised for SceneOpenGL::Window, this adds support for loading from an X Pixmap, as well as taking advantage of texture_from_pixmap/shm when available. Automatically detects what texture target should be used, so be sure to enableUnnormalizedTexCoords() before painting.
Make SceneOpenGL::Window, BoxSwitchEffect, and ExplosionEffect use the new classes.
svn path=/branches/work/kwin_composite/; revision=645125
2007-03-21 18:14:09 +00:00
|
|
|
mEndOffsetTex->unbind();
|
2007-03-16 13:02:47 +00:00
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExplosionEffect::postPaintScreen()
|
|
|
|
{
|
|
|
|
if( mActiveAnimations > 0 )
|
|
|
|
workspace()->addRepaintFull();
|
|
|
|
|
|
|
|
// Call the next effect.
|
|
|
|
effects->postPaintScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExplosionEffect::windowClosed( EffectWindow* c )
|
|
|
|
{
|
|
|
|
Client* cc = dynamic_cast< Client* >( c->window());
|
|
|
|
if( cc == NULL || (cc->isOnCurrentDesktop() && !cc->isMinimized()))
|
|
|
|
{
|
|
|
|
mWindows[ c ] = 0; // count up to 1
|
|
|
|
c->window()->addRepaintFull();
|
|
|
|
static_cast< Deleted* >( c->window())->refWindow();
|
|
|
|
mActiveAnimations++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExplosionEffect::windowDeleted( EffectWindow* c )
|
|
|
|
{
|
|
|
|
mWindows.remove( c );
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|