Allocate mipmaps in FBOs with glTexImage2D, not glGenerateMipmap.
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>
Fri, 20 Jan 2012 12:40:33 +0000 (13:40 +0100)
committerQt by Nokia <qt-info@nokia.com>
Tue, 24 Jan 2012 01:45:13 +0000 (02:45 +0100)
Change-Id: I7b7d26da97f82f354d81913eccab46d79ec9e8f0
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
src/gui/opengl/qopenglframebufferobject.cpp
src/opengl/qglframebufferobject.cpp

index df0e635..bb723b7 100644 (file)
@@ -412,8 +412,18 @@ void QOpenGLFramebufferObjectPrivate::init(QOpenGLFramebufferObject *, const QSi
         glBindTexture(target, texture);
         glTexImage2D(target, 0, internal_format, size.width(), size.height(), 0,
                 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-        if (mipmap)
-            funcs.glGenerateMipmap(GL_TEXTURE_2D);
+        if (mipmap) {
+            int width = size.width();
+            int height = size.height();
+            int level = 0;
+            while (width > 1 || height > 1) {
+                width = (width + 1) >> 1;
+                height = (height + 1) >> 1;
+                ++level;
+                glTexImage2D(target, level, internal_format, width, height, 0,
+                        GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+            }
+        }
         glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
         glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
         glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
index f226861..84bce7e 100644 (file)
@@ -454,8 +454,18 @@ void QGLFramebufferObjectPrivate::init(QGLFramebufferObject *q, const QSize &sz,
         glBindTexture(target, texture);
         glTexImage2D(target, 0, internal_format, size.width(), size.height(), 0,
                 GL_RGBA, GL_UNSIGNED_BYTE, NULL);
-        if (mipmap)
-            glGenerateMipmap(GL_TEXTURE_2D);
+        if (mipmap) {
+            int width = size.width();
+            int height = size.height();
+            int level = 0;
+            while (width > 1 || height > 1) {
+                width = (width + 1) >> 1;
+                height = (height + 1) >> 1;
+                ++level;
+                glTexImage2D(target, level, internal_format, width, height, 0,
+                        GL_RGBA, GL_UNSIGNED_BYTE, NULL);
+            }
+        }
         glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
         glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
         glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);