Fixed QQuickPaintedItem texture binding when using Image render target.
authorYoann Lopes <yoann.lopes@nokia.com>
Fri, 21 Oct 2011 11:32:21 +0000 (13:32 +0200)
committerQt by Nokia <qt-info@nokia.com>
Thu, 27 Oct 2011 11:52:27 +0000 (13:52 +0200)
Change-Id: Ia5c0f8de1109a26471c69267fdd9c9d71325dd39
Reviewed-by: Yoann Lopes <yoann.lopes@nokia.com>
src/declarative/scenegraph/util/qsgpainternode.cpp

index 1f44750..a89dd75 100644 (file)
@@ -75,33 +75,38 @@ QSGPainterTexture::QSGPainterTexture()
 
 void QSGPainterTexture::bind()
 {
-    if (m_dirty_rect.isNull() || m_texture_id == 0) {
+    if (m_dirty_rect.isNull()) {
         QSGPlainTexture::bind();
-    } else {
-        glBindTexture(GL_TEXTURE_2D, m_texture_id);
+        return;
+    }
+
+    bool oldMipmapsGenerated = m_mipmaps_generated;
+    m_mipmaps_generated = true;
+    QSGPlainTexture::bind();
+    m_mipmaps_generated = oldMipmapsGenerated;
 
-        QImage subImage = m_image.copy(m_dirty_rect);
+    QImage subImage = m_image.copy(m_dirty_rect);
 
-        int w = m_dirty_rect.width();
-        int h = m_dirty_rect.height();
+    int w = m_dirty_rect.width();
+    int h = m_dirty_rect.height();
 
 #ifdef QT_OPENGL_ES
-        glTexSubImage2D(GL_TEXTURE_2D, 0, m_dirty_rect.x(), m_dirty_rect.y(), w, h,
-                        GL_RGBA, GL_UNSIGNED_BYTE, subImage.constBits());
+    glTexSubImage2D(GL_TEXTURE_2D, 0, m_dirty_rect.x(), m_dirty_rect.y(), w, h,
+                    GL_RGBA, GL_UNSIGNED_BYTE, subImage.constBits());
 #else
-        glTexSubImage2D(GL_TEXTURE_2D, 0, m_dirty_rect.x(), m_dirty_rect.y(), w, h,
-                        GL_BGRA, GL_UNSIGNED_BYTE, subImage.constBits());
+    glTexSubImage2D(GL_TEXTURE_2D, 0, m_dirty_rect.x(), m_dirty_rect.y(), w, h,
+                    GL_BGRA, GL_UNSIGNED_BYTE, subImage.constBits());
 #endif
 
-        if (m_has_mipmaps && !m_mipmaps_generated) {
-            QOpenGLContext *ctx = QOpenGLContext::currentContext();
-            ctx->functions()->glGenerateMipmap(GL_TEXTURE_2D);
-            m_mipmaps_generated = true;
-        }
-
-        m_dirty_texture = false;
-        m_dirty_bind_options = false;
+    if (m_has_mipmaps && !m_mipmaps_generated) {
+        QOpenGLContext *ctx = QOpenGLContext::currentContext();
+        ctx->functions()->glGenerateMipmap(GL_TEXTURE_2D);
+        m_mipmaps_generated = true;
     }
+
+    m_dirty_texture = false;
+    m_dirty_bind_options = false;
+
     m_dirty_rect = QRect();
 }