From 0f7ebac00e4b14bf179fd6eea8deaa1222885105 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 7 Jan 2011 20:44:50 +0100 Subject: [PATCH] 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. --- effects/CMakeLists.txt | 2 +- effects/explosion/CMakeLists.txt | 1 - effects/explosion/data/explosion.frag | 20 +++++++++++++++----- effects/explosion/data/explosion.vert | 5 ----- effects/explosion/explosion.cpp | 25 ++++++++++++------------- 5 files changed, 28 insertions(+), 25 deletions(-) delete mode 100644 effects/explosion/data/explosion.vert diff --git a/effects/CMakeLists.txt b/effects/CMakeLists.txt index e316d621d2..7985c4adae 100644 --- a/effects/CMakeLists.txt +++ b/effects/CMakeLists.txt @@ -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 ) diff --git a/effects/explosion/CMakeLists.txt b/effects/explosion/CMakeLists.txt index ba83e60d79..0dce41f899 100644 --- a/effects/explosion/CMakeLists.txt +++ b/effects/explosion/CMakeLists.txt @@ -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 ) diff --git a/effects/explosion/data/explosion.frag b/effects/explosion/data/explosion.frag index 9a669d168d..f58caefb8d 100644 --- a/effects/explosion/data/explosion.frag +++ b/effects/explosion/data/explosion.frag @@ -1,21 +1,29 @@ -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 diff --git a/effects/explosion/data/explosion.vert b/effects/explosion/data/explosion.vert deleted file mode 100644 index f1bef4e5ed..0000000000 --- a/effects/explosion/data/explosion.vert +++ /dev/null @@ -1,5 +0,0 @@ -void main() -{ - gl_TexCoord[0] = gl_MultiTexCoord0; - gl_Position = ftransform(); -} diff --git a/effects/explosion/explosion.cpp b/effects/explosion/explosion.cpp index 8206fd12c2..90cddb0a67 100644 --- a/effects/explosion/explosion.cpp +++ b/effects/explosion/explosion.cpp @@ -22,6 +22,7 @@ along with this program. If not, see . #include +#include #include #include @@ -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);