From 91f795922d3cfcf5afdb5957d9b5d530ab34e945 Mon Sep 17 00:00:00 2001 From: Rivo Laks Date: Sun, 29 Apr 2007 15:53:56 +0000 Subject: [PATCH] Make Liquid effect work without NPOT textures as well. svn path=/branches/work/kwin_composite/; revision=659161 --- effects/data/liquid.frag | 6 +++--- effects/demo_liquid.cpp | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/effects/data/liquid.frag b/effects/data/liquid.frag index 39ee0fce61..f2515fe845 100644 --- a/effects/data/liquid.frag +++ b/effects/data/liquid.frag @@ -1,6 +1,6 @@ uniform sampler2D sceneTex; -uniform float displayWidth; -uniform float displayHeight; +uniform float textureWidth; +uniform float textureHeight; uniform float time; varying vec2 pos; @@ -12,7 +12,7 @@ varying vec2 pos; // 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); } float wave(vec2 pos, vec2 wave_dir, float wave_length, float wave_speed) diff --git a/effects/demo_liquid.cpp b/effects/demo_liquid.cpp index 8cd3110a5c..707c891e26 100644 --- a/effects/demo_liquid.cpp +++ b/effects/demo_liquid.cpp @@ -45,8 +45,19 @@ LiquidEffect::~LiquidEffect() bool LiquidEffect::loadData() { + // If NPOT textures are not supported, use nearest power-of-two sized + // texture. It wastes memory, but it's possible to support systems without + // NPOT textures that way + 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); + } // Create texture and render target - mTexture = new GLTexture(displayWidth(), displayHeight()); + mTexture = new GLTexture(texw, texh); mTexture->setFilter(GL_LINEAR_MIPMAP_LINEAR); mTexture->setWrapMode(GL_CLAMP); @@ -69,8 +80,8 @@ bool LiquidEffect::loadData() } mShader->bind(); mShader->setUniform("sceneTex", 0); - mShader->setUniform("displayWidth", (float)displayWidth()); - mShader->setUniform("displayHeight", (float)displayHeight()); + mShader->setUniform("textureWidth", (float)texw); + mShader->setUniform("textureHeight", (float)texh); mShader->unbind(); return true; @@ -78,7 +89,7 @@ bool LiquidEffect::loadData() bool LiquidEffect::supported() { - return GLRenderTarget::supported() && GLTexture::NPOTTextureSupported() && + return GLRenderTarget::supported() && GLShader::fragmentShaderSupported() && (effects->compositingType() == OpenGLCompositing); }