Commit efbb6d60 authored by Martin Flöser's avatar Martin Flöser

Explosion portet to GLES.

I'm not completely sure if this is how the effect should look like.
But I cannot verify, it fails on fglrx and cannot find a video on Youtube.
parent 016ab923
......@@ -91,6 +91,7 @@ endif( NOT KWIN_HAVE_OPENGLES_COMPOSITING )
if( KWIN_HAVE_OPENGL_COMPOSITING )
include( coverswitch/CMakeLists.txt )
include( cube/CMakeLists.txt )
include( explosion/CMakeLists.txt )
include( flipswitch/CMakeLists.txt )
include( glide/CMakeLists.txt )
include( invert/CMakeLists.txt )
......@@ -106,7 +107,6 @@ if( KWIN_HAVE_OPENGL_COMPOSITING )
endif( KWIN_HAVE_OPENGL_COMPOSITING )
if( KWIN_HAVE_OPENGL_COMPOSITING AND NOT KWIN_HAVE_OPENGLES_COMPOSITING )
include( blur/CMakeLists.txt )
include( explosion/CMakeLists.txt )
include( sharpen/CMakeLists.txt )
include( snow/CMakeLists.txt )
endif( KWIN_HAVE_OPENGL_COMPOSITING AND NOT KWIN_HAVE_OPENGLES_COMPOSITING )
......
......@@ -16,5 +16,4 @@ install( FILES
explosion/data/explosion-end.png
explosion/data/explosion-start.png
explosion/data/explosion.frag
explosion/data/explosion.vert
DESTINATION ${DATA_INSTALL_DIR}/kwin )
uniform sampler2D winTexture;
uniform sampler2D sample;
uniform sampler2D startOffsetTexture;
uniform sampler2D endOffsetTexture;
uniform float factor;
uniform float scale;
uniform float textureWidth;
uniform float textureHeight;
const float regionTexSize = 512.0;
varying vec2 varyingTexCoords;
vec2 getOffset(sampler2D texture, vec2 pos)
{
return (texture2D(texture, pos / regionTexSize).xy - 0.5) / (5.0 / 256.0);
}
vec2 pix2tex( vec2 pix )
{
return vec2( pix.s / textureWidth, pix.t / textureHeight );
}
void main()
{
// Original (unscaled) position in pixels
vec2 origpos = gl_TexCoord[0].xy;
vec2 origpos = varyingTexCoords;
// Position in pixels on the scaled window
vec2 pos = origpos * scale;
// Start/end position of current region
......@@ -24,12 +32,14 @@ void main()
float alpha = texture2D(startOffsetTexture, origpos / regionTexSize).b;
// Distance from the start of the region
vec2 dist = pos - rstart*scale;
#if 0
// crashes kwin on nouveau
if(any(greaterThan(dist, rend-rstart)))
discard;//alpha = 0.0;
#endif
vec2 const_1 = vec2(1.0); // Needed to work around a bug in the GLSL compiler in mesa 7.9
vec4 transformedtexcoord = vec4(rstart + dist, const_1) * gl_TextureMatrix[0];
vec3 tex = texture2D(winTexture, transformedtexcoord.xy).rgb;
vec2 transformedtexcoord = pix2tex(rstart + dist);
vec3 tex = texture2D(sample, transformedtexcoord).rgb;
#if 0
// ATM we ignore custom opacity values because Fade effect fades out the
// window which results in the explosion being way too quick. Once there's
......
void main()
{
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}
......@@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <kwinglutils.h>
#include <QMatrix4x4>
#include <KStandardDirs>
#include <kdebug.h>
......@@ -63,22 +64,16 @@ 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");
const QString fragmentshader = KGlobal::dirs()->findResource("data", "kwin/explosion.frag");
QString starttexture = KGlobal::dirs()->findResource("data", "kwin/explosion-start.png");
QString endtexture = KGlobal::dirs()->findResource("data", "kwin/explosion-end.png");
if(fragmentshader.isEmpty() || vertexshader.isEmpty())
{
kError(1212) << "Couldn't locate shader files" << endl;
return false;
}
if(starttexture.isEmpty() || endtexture.isEmpty())
{
kError(1212) << "Couldn't locate texture files" << endl;
return false;
}
mShader = new GLShader(vertexshader, fragmentshader);
mShader = ShaderManager::instance()->loadFragmentShader(ShaderManager::GenericShader, fragmentshader);
if(!mShader->isValid())
{
kError(1212) << "The shader failed to load!" << endl;
......@@ -86,11 +81,10 @@ bool ExplosionEffect::loadData()
}
else
{
mShader->bind();
mShader->setUniform("winTexture", 0);
ShaderManager::instance()->pushShader(mShader);
mShader->setUniform("startOffsetTexture", 4);
mShader->setUniform("endOffsetTexture", 5);
mShader->unbind();
ShaderManager::instance()->popShader();
}
mStartOffsetTex = new GLTexture(starttexture);
......@@ -160,7 +154,12 @@ void ExplosionEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Wi
data.xTranslate += int( w->width() / 2 * ( 1 - scale ));
data.yTranslate += int( w->height() / 2 * ( 1 - scale ));
data.opacity *= 0.99; // Force blending
mShader->bind();
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);
mShader->setUniform("factor", (float)mWindows[w]);
mShader->setUniform("scale", (float)scale);
glActiveTexture(GL_TEXTURE4);
......@@ -176,7 +175,7 @@ void ExplosionEffect::paintWindow( EffectWindow* w, int mask, QRegion region, Wi
if( useshader )
{
mShader->unbind();
ShaderManager::instance()->popShader();
glActiveTexture(GL_TEXTURE4);
mStartOffsetTex->unbind();
glActiveTexture(GL_TEXTURE5);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment