GLES 2 spec does not support any mipmap filters for non-power-of-two
textures. To my understanding, the support is added by
GL_OES_texture_npot extension.

Do not generate mipmap levels nor use mipmap filters, if it is not
supported:

- add GL::textureNonPowerOfTwoMipmap flag, which gets enabled only if
  OES_texture_npot is available (EGL / GLES 2), or equals
  GL::textureNonPowerOfTwo flag for desktop OpenGL.

- check GLTexture::mipmap () instead of opencoding something similar in
  GLTexture::enable (). All these tests are moved to GLTexture::setData
  () callers, which are supposed to determine if mipmapping the texture
  is possible.

- all cases, that set PrivateTexture::mipmapSupported via
  GLTexture::setData () now check for all the previous conditions plus
  GL::textureNonPowerOfTwoMipmap (except TfpTexture::bindPixmapToTexture
  () which does not need it).

This patch fixes the window thumbnails in switcher plugin for GLES 2
platforms that do not support mipmapping NPOT textures.

Signed-off-by: Pekka Paalanen <[email protected]>
---
 plugins/opengl/include/opengl/opengl.h |    1 +
 plugins/opengl/src/screen.cpp          |    5 +++++
 plugins/opengl/src/texture.cpp         |   16 +++++++++-------
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/plugins/opengl/include/opengl/opengl.h 
b/plugins/opengl/include/opengl/opengl.h
index 1193042..1e55b87 100644
--- a/plugins/opengl/include/opengl/opengl.h
+++ b/plugins/opengl/include/opengl/opengl.h
@@ -312,6 +312,7 @@ namespace GL {
     extern bool  textureFromPixmap;
     extern bool  textureRectangle;
     extern bool  textureNonPowerOfTwo;
+    extern bool  textureNonPowerOfTwoMipmap;
     extern bool  textureEnvCombine;
     extern bool  textureEnvCrossbar;
     extern bool  textureBorderClamp;
diff --git a/plugins/opengl/src/screen.cpp b/plugins/opengl/src/screen.cpp
index 51300f1..749eddf 100644
--- a/plugins/opengl/src/screen.cpp
+++ b/plugins/opengl/src/screen.cpp
@@ -100,6 +100,7 @@ namespace GL {
     bool  textureFromPixmap = true;
     bool  textureRectangle = false;
     bool  textureNonPowerOfTwo = false;
+    bool  textureNonPowerOfTwoMipmap = false;
     bool  textureEnvCombine = false;
     bool  textureEnvCrossbar = false;
     bool  textureBorderClamp = false;
@@ -265,6 +266,9 @@ GLScreen::GLScreen (CompScreen *s) :
     }
 #endif
 
+    if (strstr (glExtensions, "GL_OES_texture_npot"))
+       GL::textureNonPowerOfTwoMipmap = true;
+
     GL::activeTexture = glActiveTexture;
     GL::genFramebuffers = glGenFramebuffers;
     GL::deleteFramebuffers = glDeleteFramebuffers;
@@ -491,6 +495,7 @@ GLScreen::GLScreen (CompScreen *s) :
 
     if (strstr (glExtensions, "GL_ARB_texture_non_power_of_two"))    
        GL::textureNonPowerOfTwo = true;
+    GL::textureNonPowerOfTwoMipmap = GL::textureNonPowerOfTwo;
 
     glGetIntegerv (GL_MAX_TEXTURE_SIZE, &GL::maxTextureSize);
 
diff --git a/plugins/opengl/src/texture.cpp b/plugins/opengl/src/texture.cpp
index a1e4fe3..4ab3d18 100644
--- a/plugins/opengl/src/texture.cpp
+++ b/plugins/opengl/src/texture.cpp
@@ -157,7 +157,7 @@ GLTexture::matrix () const
 bool
 GLTexture::mipmap () const
 {
-    return priv->mipmap & priv->mipmapSupport;
+    return priv->mipmap && priv->mipmapSupport;
 }
 
 GLenum
@@ -193,7 +193,7 @@ GLTexture::enable (GLTexture::Filter filter)
     {
        if (gs->textureFilter () == GL_LINEAR_MIPMAP_LINEAR)
        {
-           if (GL::textureNonPowerOfTwo && GL::fbo && priv->mipmap)
+           if (mipmap ())
            {
                glTexParameteri (priv->target,
                                 GL_TEXTURE_MIN_FILTER,
@@ -310,23 +310,23 @@ PrivateTexture::loadImageData (const char   *image,
     GLint             internalFormat;
     GLenum            target;
     bool              mipmap;
+    bool              pot = POWER_OF_TWO (width) && POWER_OF_TWO (height);
 
     #ifdef USE_GLES
     target = GL_TEXTURE_2D;
     matrix.xx = 1.0f / width;
     matrix.yy = 1.0f / height;
     matrix.y0 = 0.0f;
-    mipmap = true;
+    mipmap = GL::textureNonPowerOfTwoMipmap || pot;
     #else
 
-    if (GL::textureNonPowerOfTwo ||
-       (POWER_OF_TWO (width) && POWER_OF_TWO (height)))
+    if (GL::textureNonPowerOfTwo || pot)
     {
        target = GL_TEXTURE_2D;
        matrix.xx = 1.0f / width;
        matrix.yy = 1.0f / height;
        matrix.y0 = 0.0f;
-       mipmap = true;
+       mipmap = GL::fbo && (GL::textureNonPowerOfTwoMipmap || pot);
     }
     else
     {
@@ -497,7 +497,9 @@ EglTexture::bindPixmapToTexture (Pixmap pixmap,
     matrix.y0 = 0.0f;
 
     tex = new EglTexture ();
-    tex->setData (GL_TEXTURE_2D, matrix, true);
+    tex->setData (GL_TEXTURE_2D, matrix,
+       GL::textureNonPowerOfTwoMipmap ||
+       (POWER_OF_TWO (width) && POWER_OF_TWO (height)));
     tex->setGeometry (0, 0, width, height);
 
     rv[0] = tex;
-- 
1.7.3.4

_______________________________________________
dev mailing list
[email protected]
http://lists.compiz.org/mailman/listinfo/dev

Reply via email to