src/opengl/qwindowsurface_gl.cpp
changeset 37 758a864f9613
parent 33 3e2da88830cd
--- a/src/opengl/qwindowsurface_gl.cpp	Fri Sep 17 08:34:18 2010 +0300
+++ b/src/opengl/qwindowsurface_gl.cpp	Mon Oct 04 01:19:32 2010 +0300
@@ -199,6 +199,7 @@
         return widget;
     }
 
+    // destroys the share widget and prevents recreation
     void cleanup() {
         QGLWidget *w = widget;
         cleanedUp = true;
@@ -206,6 +207,20 @@
         delete w;
     }
 
+    // destroys the share widget, but allows it to be recreated later on
+    void destroy() {
+        if (cleanedUp)
+            return;
+
+        QGLWidget *w = widget;
+
+        // prevent potential recursions
+        cleanedUp = true;
+        widget = 0;
+        delete w;
+        cleanedUp = false;
+    }
+
     static bool cleanedUp;
 
 private:
@@ -233,6 +248,10 @@
     return _qt_gl_share_widget()->shareWidget();
 }
 
+void qt_destroy_gl_share_widget()
+{
+    _qt_gl_share_widget()->destroy();
+}
 
 struct QGLWindowSurfacePrivate
 {
@@ -407,6 +426,20 @@
 
 void QGLWindowSurface::beginPaint(const QRegion &)
 {
+    if (! context())
+        return;
+
+    int clearFlags = 0;
+
+    if (context()->d_func()->workaround_needsFullClearOnEveryFrame)
+        clearFlags = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
+    else if (context()->format().alpha())
+        clearFlags = GL_COLOR_BUFFER_BIT;
+
+    if (clearFlags) {
+        glClearColor(0.0, 0.0, 0.0, 0.0);
+        glClear(clearFlags);
+    }
 }
 
 void QGLWindowSurface::endPaint(const QRegion &rgn)
@@ -494,10 +527,9 @@
                 }
             }
 #endif
-            if (d_ptr->paintedRegion.boundingRect() != geometry()) {
-                // Emits warning if not supported. Should never happen unless
-                // setPartialUpdateSupport(true) has been called.
-                context()->d_func()->swapRegion(&d_ptr->paintedRegion);
+            if (d_ptr->paintedRegion.boundingRect() != geometry() && 
+                hasPartialUpdateSupport()) {
+                context()->d_func()->swapRegion(&d_ptr->paintedRegion);             
             } else
                 context()->swapBuffers();