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=659159icc-effect-5.14.5
parent
a94aa904b0
commit
49a56dc905
|
@ -58,11 +58,19 @@ BlurEffect::~BlurEffect()
|
||||||
bool BlurEffect::loadData()
|
bool BlurEffect::loadData()
|
||||||
{
|
{
|
||||||
// Create texture and render target
|
// 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);
|
mSceneTexture->setFilter(GL_LINEAR);
|
||||||
mTmpTexture = new GLTexture(displayWidth(), displayHeight());
|
mTmpTexture = new GLTexture(texw, texh);
|
||||||
mTmpTexture->setFilter(GL_LINEAR);
|
mTmpTexture->setFilter(GL_LINEAR);
|
||||||
mBlurTexture = new GLTexture(displayWidth(), displayHeight());
|
mBlurTexture = new GLTexture(texw, texh);
|
||||||
|
|
||||||
mSceneTarget = new GLRenderTarget(mSceneTexture);
|
mSceneTarget = new GLRenderTarget(mSceneTexture);
|
||||||
if( !mSceneTarget->valid() )
|
if( !mSceneTarget->valid() )
|
||||||
|
@ -83,15 +91,15 @@ bool BlurEffect::loadData()
|
||||||
|
|
||||||
mBlurShader->bind();
|
mBlurShader->bind();
|
||||||
mBlurShader->setUniform("inputTex", 0);
|
mBlurShader->setUniform("inputTex", 0);
|
||||||
mBlurShader->setUniform("displayWidth", (float)displayWidth());
|
mBlurShader->setUniform("textureWidth", (float)texw);
|
||||||
mBlurShader->setUniform("displayHeight", (float)displayHeight());
|
mBlurShader->setUniform("textureHeight", (float)texh);
|
||||||
mBlurShader->unbind();
|
mBlurShader->unbind();
|
||||||
|
|
||||||
mWindowShader->bind();
|
mWindowShader->bind();
|
||||||
mWindowShader->setUniform("windowTex", 0);
|
mWindowShader->setUniform("windowTex", 0);
|
||||||
mWindowShader->setUniform("backgroundTex", 4);
|
mWindowShader->setUniform("backgroundTex", 4);
|
||||||
mWindowShader->setUniform("displayWidth", (float)displayWidth());
|
mWindowShader->setUniform("textureWidth", (float)texw);
|
||||||
mWindowShader->setUniform("displayHeight", (float)displayHeight());
|
mWindowShader->setUniform("textureHeight", (float)texh);
|
||||||
mWindowShader->unbind();
|
mWindowShader->unbind();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -171,7 +179,6 @@ void BlurEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowP
|
||||||
// Put the blur texture to tex unit 4
|
// Put the blur texture to tex unit 4
|
||||||
glActiveTexture(GL_TEXTURE4);
|
glActiveTexture(GL_TEXTURE4);
|
||||||
mBlurTexture->bind();
|
mBlurTexture->bind();
|
||||||
mBlurTexture->enableUnnormalizedTexCoords();
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|
||||||
// Paint
|
// Paint
|
||||||
|
@ -188,7 +195,6 @@ void BlurEffect::paintWindow( EffectWindow* w, int mask, QRegion region, WindowP
|
||||||
|
|
||||||
// Disable blur texture and shader
|
// Disable blur texture and shader
|
||||||
glActiveTexture(GL_TEXTURE4);
|
glActiveTexture(GL_TEXTURE4);
|
||||||
mBlurTexture->disableUnnormalizedTexCoords();
|
|
||||||
mBlurTexture->unbind();
|
mBlurTexture->unbind();
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
mWindowShader->unbind();
|
mWindowShader->unbind();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
uniform sampler2D windowTex;
|
uniform sampler2D windowTex;
|
||||||
uniform sampler2D backgroundTex;
|
uniform sampler2D backgroundTex;
|
||||||
uniform float displayWidth;
|
uniform float textureWidth;
|
||||||
uniform float displayHeight;
|
uniform float textureHeight;
|
||||||
uniform float opacity;
|
uniform float opacity;
|
||||||
uniform float saturation;
|
uniform float saturation;
|
||||||
uniform float brightness;
|
uniform float brightness;
|
||||||
|
@ -10,7 +10,7 @@ uniform float brightness;
|
||||||
// Converts pixel coordinates to texture coordinates
|
// Converts pixel coordinates to texture coordinates
|
||||||
vec2 pix2tex(vec2 pix)
|
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
|
// Returns color of the window at given texture coordinate, taking into
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
uniform sampler2D inputTex;
|
uniform sampler2D inputTex;
|
||||||
uniform float displayWidth;
|
uniform float textureWidth;
|
||||||
uniform float displayHeight;
|
uniform float textureHeight;
|
||||||
|
|
||||||
varying vec2 pos;
|
varying vec2 pos;
|
||||||
varying vec2 blurDirection;
|
varying vec2 blurDirection;
|
||||||
|
@ -9,7 +9,7 @@ varying vec2 blurDirection;
|
||||||
// Converts pixel coordinates to texture coordinates
|
// Converts pixel coordinates to texture coordinates
|
||||||
vec2 pix2tex(vec2 pix)
|
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)
|
vec3 blurTex(float offset, float strength)
|
||||||
|
|
Loading…
Reference in New Issue