src/opengl/qwindowsurface_gl.cpp
changeset 37 758a864f9613
parent 33 3e2da88830cd
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
   197             initializing = false;
   197             initializing = false;
   198         }
   198         }
   199         return widget;
   199         return widget;
   200     }
   200     }
   201 
   201 
       
   202     // destroys the share widget and prevents recreation
   202     void cleanup() {
   203     void cleanup() {
   203         QGLWidget *w = widget;
   204         QGLWidget *w = widget;
   204         cleanedUp = true;
   205         cleanedUp = true;
   205         widget = 0;
   206         widget = 0;
   206         delete w;
   207         delete w;
   207     }
   208     }
   208 
   209 
       
   210     // destroys the share widget, but allows it to be recreated later on
       
   211     void destroy() {
       
   212         if (cleanedUp)
       
   213             return;
       
   214 
       
   215         QGLWidget *w = widget;
       
   216 
       
   217         // prevent potential recursions
       
   218         cleanedUp = true;
       
   219         widget = 0;
       
   220         delete w;
       
   221         cleanedUp = false;
       
   222     }
       
   223 
   209     static bool cleanedUp;
   224     static bool cleanedUp;
   210 
   225 
   211 private:
   226 private:
   212     QGLWidget *widget;
   227     QGLWidget *widget;
   213     bool initializing;
   228     bool initializing;
   231     if (QGLGlobalShareWidget::cleanedUp)
   246     if (QGLGlobalShareWidget::cleanedUp)
   232         return 0;
   247         return 0;
   233     return _qt_gl_share_widget()->shareWidget();
   248     return _qt_gl_share_widget()->shareWidget();
   234 }
   249 }
   235 
   250 
       
   251 void qt_destroy_gl_share_widget()
       
   252 {
       
   253     _qt_gl_share_widget()->destroy();
       
   254 }
   236 
   255 
   237 struct QGLWindowSurfacePrivate
   256 struct QGLWindowSurfacePrivate
   238 {
   257 {
   239     QGLFramebufferObject *fbo;
   258     QGLFramebufferObject *fbo;
   240     QGLPixelBuffer *pb;
   259     QGLPixelBuffer *pb;
   405 
   424 
   406 static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize, const QRectF &src = QRectF());
   425 static void drawTexture(const QRectF &rect, GLuint tex_id, const QSize &texSize, const QRectF &src = QRectF());
   407 
   426 
   408 void QGLWindowSurface::beginPaint(const QRegion &)
   427 void QGLWindowSurface::beginPaint(const QRegion &)
   409 {
   428 {
       
   429     if (! context())
       
   430         return;
       
   431 
       
   432     int clearFlags = 0;
       
   433 
       
   434     if (context()->d_func()->workaround_needsFullClearOnEveryFrame)
       
   435         clearFlags = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT;
       
   436     else if (context()->format().alpha())
       
   437         clearFlags = GL_COLOR_BUFFER_BIT;
       
   438 
       
   439     if (clearFlags) {
       
   440         glClearColor(0.0, 0.0, 0.0, 0.0);
       
   441         glClear(clearFlags);
       
   442     }
   410 }
   443 }
   411 
   444 
   412 void QGLWindowSurface::endPaint(const QRegion &rgn)
   445 void QGLWindowSurface::endPaint(const QRegion &rgn)
   413 {
   446 {
   414     if (context())
   447     if (context())
   492                         drawTexture(rect, d_ptr->tex_id, window()->size(), rect);
   525                         drawTexture(rect, d_ptr->tex_id, window()->size(), rect);
   493                     }
   526                     }
   494                 }
   527                 }
   495             }
   528             }
   496 #endif
   529 #endif
   497             if (d_ptr->paintedRegion.boundingRect() != geometry()) {
   530             if (d_ptr->paintedRegion.boundingRect() != geometry() && 
   498                 // Emits warning if not supported. Should never happen unless
   531                 hasPartialUpdateSupport()) {
   499                 // setPartialUpdateSupport(true) has been called.
   532                 context()->d_func()->swapRegion(&d_ptr->paintedRegion);             
   500                 context()->d_func()->swapRegion(&d_ptr->paintedRegion);
       
   501             } else
   533             } else
   502                 context()->swapBuffers();
   534                 context()->swapBuffers();
   503 
   535 
   504             d_ptr->paintedRegion = QRegion();
   536             d_ptr->paintedRegion = QRegion();
   505         } else {
   537         } else {