From 49a56dc905e5de88a75deed95d5f9ad4f8348349 Mon Sep 17 00:00:00 2001 From: Rivo Laks Date: Sun, 29 Apr 2007 15:42:19 +0000 Subject: [PATCH] Make blur effect work even when NPOT textures are not supported by using a larger power-of-two texture. It wastes some memory but at least it works. svn path=/branches/work/kwin_composite/; revision=659159 --- effects/blur.cpp | 24 +++++++++++++++--------- effects/data/blur-render.frag | 6 +++--- effects/data/blur.frag | 6 +++--- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/effects/blur.cpp b/effects/blur.cpp index 3edf992f0b..74fc193748 100644 --- a/effects/blur.cpp +++ b/effects/blur.cpp @@ -58,11 +58,19 @@ BlurEffect::~BlurEffect() bool BlurEffect::loadData() { // Create texture and render target - mSceneTexture = new GLTexture(displayWidth(), displayHeight()); + int texw = displayWidth(); + int texh = displayHeight(); + if( !GLTexture::NPOTTextureSupported() ) + { + kWarning( 1212 ) << k_funcinfo << "NPOT textures not supported, wasting some memory" << endl; + texw = nearestPowerOfTwo(texw); + texh = nearestPowerOfTwo(texh); + } + mSceneTexture = new GLTexture(texw, texh); mSceneTexture->setFilter(GL_LINEAR); - mTmpTexture = new GLTexture(displayWidth(), displayHeight()); + mTmpTexture = new GLTexture(texw, texh); mTmpTexture->setFilter(GL_LINEAR); - mBlurTexture = new GLTexture(displayWidth(), displayHeight()); + mBlurTexture = new GLTexture(texw, texh); mSceneTarget = new GLRenderTarget(mSceneTexture); if( !mSceneTarget->valid() ) @@ -83,15 +91,15 @@ bool BlurEffect::loadData() mBlurShader->bind(); mBlurShader->setUniform("inputTex", 0); - mBlurShader->setUniform("displayWidth", (float)displayWidth()); - mBlurShader->setUniform("displayHeight", (float)displayHeight()); + mBlurShader->setUniform("textureWidth", (float)texw); + mBlurShader->setUniform("textureHeight", (float)texh); mBlurShader->unbind(); mWindowShader->bind(); mWindowShader->setUniform("windowTex", 0); mWindowShader->setUniform("backgroundTex", 4); - mWindowShader->setUniform("displayWidth", (float)displayWidth()); - mWindowShader->setUniform("displayHeight", (float)displayHeight()); + mWindowShader->setUniform("textureWidth", (float)texw); + mWindowShader->setUniform("textureHeight", (float)texh); mWindowShader->unbind(); return true; @@ -171,7 +179,6 @@ void BlurEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowP // Put the blur texture to tex unit 4 glActiveTexture(GL_TEXTURE4); mBlurTexture->bind(); - mBlurTexture->enableUnnormalizedTexCoords(); glActiveTexture(GL_TEXTURE0); // Paint @@ -188,7 +195,6 @@ void BlurEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowP // Disable blur texture and shader glActiveTexture(GL_TEXTURE4); - mBlurTexture->disableUnnormalizedTexCoords(); mBlurTexture->unbind(); glActiveTexture(GL_TEXTURE0); mWindowShader->unbind(); diff --git a/effects/data/blur-render.frag b/effects/data/blur-render.frag index 55f3f07ad2..7cda37191e 100644 --- a/effects/data/blur-render.frag +++ b/effects/data/blur-render.frag @@ -1,7 +1,7 @@ uniform sampler2D windowTex; uniform sampler2D backgroundTex; -uniform float displayWidth; -uniform float displayHeight; +uniform float textureWidth; +uniform float textureHeight; uniform float opacity; uniform float saturation; uniform float brightness; @@ -10,7 +10,7 @@ uniform float brightness; // Converts pixel coordinates to texture coordinates vec2 pix2tex(vec2 pix) { - return vec2(pix.x / displayWidth, pix.y / displayHeight); + return vec2(pix.x / textureWidth, pix.y / textureHeight); } // Returns color of the window at given texture coordinate, taking into diff --git a/effects/data/blur.frag b/effects/data/blur.frag index a8d751ff1f..a37521936d 100644 --- a/effects/data/blur.frag +++ b/effects/data/blur.frag @@ -1,6 +1,6 @@ uniform sampler2D inputTex; -uniform float displayWidth; -uniform float displayHeight; +uniform float textureWidth; +uniform float textureHeight; varying vec2 pos; varying vec2 blurDirection; @@ -9,7 +9,7 @@ varying vec2 blurDirection; // Converts pixel coordinates to texture coordinates vec2 pix2tex(vec2 pix) { - return vec2(pix.x / displayWidth, 1.0 - pix.y / displayHeight); + return vec2(pix.x / textureWidth, 1.0 - pix.y / textureHeight); } vec3 blurTex(float offset, float strength)