diff options
author | Tom Cooksey <thomas.cooksey@nokia.com> | 2009-09-07 08:58:31 (GMT) |
---|---|---|
committer | Tom Cooksey <thomas.cooksey@nokia.com> | 2009-09-08 16:36:15 (GMT) |
commit | 4feed48fdd738ed99cba86a4214e238a3e7275ed (patch) | |
tree | a9b3b41bc838275d56914b7f0d22e739794ae3c4 /src | |
parent | e8b5bfa8a86b2d7c79aabcc4566f740f0a9afe7c (diff) | |
download | Qt-4feed48fdd738ed99cba86a4214e238a3e7275ed.zip Qt-4feed48fdd738ed99cba86a4214e238a3e7275ed.tar.gz Qt-4feed48fdd738ed99cba86a4214e238a3e7275ed.tar.bz2 |
Move buffer clear out of the paint engine and into the QGLPaintDevices
Previously, the paint engine cleared the surface's buffers in begin.
This logic really belongs in QGLPaintDevice::beginPaint as not all paint
devices will want this behaviour (in fact most don't). This also makes
QGLPaintDevice API much simpler as the virtual getters for the clear
color, etc. can be removed. It's much cleaner this way. The only
possible problem is with the GL1 engine, which also cleared the
accumulation & depth buffers in begin. However, the engine will also
clear the depth buffer later as part of it's clipping logic. It also
doesn't use the accumulation buffer, so clearing it seems unnessisary.
Diffstat (limited to 'src')
-rw-r--r-- | src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp | 12 | ||||
-rw-r--r-- | src/opengl/qgl.cpp | 9 | ||||
-rw-r--r-- | src/opengl/qgl_p.h | 4 | ||||
-rw-r--r-- | src/opengl/qglpaintdevice.cpp | 64 | ||||
-rw-r--r-- | src/opengl/qglpaintdevice_p.h | 16 | ||||
-rw-r--r-- | src/opengl/qpaintengine_opengl.cpp | 16 |
6 files changed, 58 insertions, 63 deletions
diff --git a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp index fcfd818..c280803 100644 --- a/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp +++ b/src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp @@ -1359,17 +1359,7 @@ bool QGL2PaintEngineEx::begin(QPaintDevice *pdev) #endif // QGLPixmapData *source = d->drawable.copyOnBegin(); - if (d->ctx->d_func()->clear_on_painter_begin && d->device->autoFillBackground()) { - if (d->device->hasTransparentBackground()) - glClearColor(0.0, 0.0, 0.0, 0.0); - else { - const QColor &c = d->device->backgroundColor(); - float alpha = c.alphaF(); - glClearColor(c.redF() * alpha, c.greenF() * alpha, c.blueF() * alpha, alpha); - } - glClear(GL_COLOR_BUFFER_BIT); - } -// else if (source) { +// if (source) { // QGLContext *ctx = d->ctx; // // d->transferMode(ImageDrawingMode); diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index ad54298..8ad9860 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -1399,7 +1399,6 @@ void QGLContextPrivate::init(QPaintDevice *dev, const QGLFormat &format) crWin = false; initDone = false; sharing = false; - clear_on_painter_begin = true; max_texture_size = -1; version_flags_cached = false; version_flags = QGLFormat::OpenGL_Version_None; @@ -4254,7 +4253,7 @@ void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font, } else { setAutoBufferSwap(false); // disable glClear() as a result of QPainter::begin() - d->glcx->d_func()->clear_on_painter_begin = false; + d->disable_clear_on_painter_begin = true; if (engine->type() == QPaintEngine::OpenGL2) { qt_save_gl_state(); #ifndef QT_OPENGL_ES_2 @@ -4284,7 +4283,7 @@ void QGLWidget::renderText(int x, int y, const QString &str, const QFont &font, p->end(); delete p; setAutoBufferSwap(auto_swap); - d->glcx->d_func()->clear_on_painter_begin = true; + d->disable_clear_on_painter_begin = false; if (engine->type() == QPaintEngine::OpenGL2) qt_restore_gl_state(); } @@ -4427,7 +4426,7 @@ void QGLWidget::renderText(double x, double y, double z, const QString &str, con } else { setAutoBufferSwap(false); // disable glClear() as a result of QPainter::begin() - d->glcx->d_func()->clear_on_painter_begin = false; + d->disable_clear_on_painter_begin = true; if (engine->type() == QPaintEngine::OpenGL2) qt_save_gl_state(); p = new QPainter(this); @@ -4467,7 +4466,7 @@ void QGLWidget::renderText(double x, double y, double z, const QString &str, con if (engine->type() == QPaintEngine::OpenGL2) qt_restore_gl_state(); setAutoBufferSwap(auto_swap); - d->glcx->d_func()->clear_on_painter_begin = true; + d->disable_clear_on_painter_begin = false; } #ifndef QT_OPENGL_ES if (engine->type() == QPaintEngine::OpenGL2) diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index 03532c8..e86b843 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -175,6 +175,7 @@ class QGLWidgetPrivate : public QWidgetPrivate Q_DECLARE_PUBLIC(QGLWidget) public: QGLWidgetPrivate() : QWidgetPrivate() + , disable_clear_on_painter_begin(false) #ifdef Q_WS_QWS , wsurf(0) #endif @@ -197,6 +198,8 @@ public: QGLColormap cmap; QMap<QString, int> displayListCache; + bool disable_clear_on_painter_begin; + #if defined(Q_WS_WIN) void updateColormap(); QGLContext *olcx; @@ -295,7 +298,6 @@ public: uint sharing : 1; uint initDone : 1; uint crWin : 1; - uint clear_on_painter_begin : 1; uint internal_context : 1; uint version_flags_cached : 1; QPaintDevice *paintDevice; diff --git a/src/opengl/qglpaintdevice.cpp b/src/opengl/qglpaintdevice.cpp index 51f9627..4f000ba 100644 --- a/src/opengl/qglpaintdevice.cpp +++ b/src/opengl/qglpaintdevice.cpp @@ -86,20 +86,20 @@ void QGLPaintDevice::endPaint() } } -QColor QGLPaintDevice::backgroundColor() const -{ - return QApplication::palette().brush(QPalette::Background).color(); -} +//QColor QGLPaintDevice::backgroundColor() const +//{ +// return QApplication::palette().brush(QPalette::Background).color(); +//} -bool QGLPaintDevice::autoFillBackground() const -{ - return false; -} +//bool QGLPaintDevice::autoFillBackground() const +//{ +// return false; +//} -bool QGLPaintDevice::hasTransparentBackground() const -{ - return false; -} +//bool QGLPaintDevice::hasTransparentBackground() const +//{ +// return false; +//} QGLFormat QGLPaintDevice::format() const { @@ -112,6 +112,7 @@ QSize QGLPaintDevice::size() const } + QGLWidgetGLPaintDevice::QGLWidgetGLPaintDevice() { } @@ -121,26 +122,41 @@ QPaintEngine* QGLWidgetGLPaintDevice::paintEngine() const return glWidget->paintEngine(); } -QColor QGLWidgetGLPaintDevice::backgroundColor() const -{ - return glWidget->palette().brush(glWidget->backgroundRole()).color(); -} +//QColor QGLWidgetGLPaintDevice::backgroundColor() const +//{ +// return glWidget->palette().brush(glWidget->backgroundRole()).color(); +//} -bool QGLWidgetGLPaintDevice::autoFillBackground() const -{ - return glWidget->autoFillBackground(); -} +//bool QGLWidgetGLPaintDevice::autoFillBackground() const +//{ +// return glWidget->autoFillBackground(); +//} -bool QGLWidgetGLPaintDevice::hasTransparentBackground() const -{ - return glWidget->testAttribute(Qt::WA_TranslucentBackground); -} +//bool QGLWidgetGLPaintDevice::hasTransparentBackground() const +//{ +// return glWidget->testAttribute(Qt::WA_TranslucentBackground); +//} void QGLWidgetGLPaintDevice::setWidget(QGLWidget* w) { glWidget = w; } +void QGLWidgetGLPaintDevice::beginPaint() +{ + QGLPaintDevice::beginPaint(); + if (!glWidget->d_func()->disable_clear_on_painter_begin && glWidget->autoFillBackground()) { + if (glWidget->testAttribute(Qt::WA_TranslucentBackground)) + glClearColor(0.0, 0.0, 0.0, 0.0); + else { + const QColor &c = glWidget->palette().brush(glWidget->backgroundRole()).color(); + float alpha = c.alphaF(); + glClearColor(c.redF() * alpha, c.greenF() * alpha, c.blueF() * alpha, alpha); + } + glClear(GL_COLOR_BUFFER_BIT); + } +} + void QGLWidgetGLPaintDevice::endPaint() { if (glWidget->autoBufferSwap()) diff --git a/src/opengl/qglpaintdevice_p.h b/src/opengl/qglpaintdevice_p.h index c5fa626..6d34b1b 100644 --- a/src/opengl/qglpaintdevice_p.h +++ b/src/opengl/qglpaintdevice_p.h @@ -66,9 +66,11 @@ public: virtual void ensureActiveTarget(); virtual void endPaint(); - virtual QColor backgroundColor() const; - virtual bool autoFillBackground() const; - virtual bool hasTransparentBackground() const; +// virtual void clearOnBegin() const; +// virtual QColor clearColor() const; +// virtual QColor backgroundColor() const; +// virtual bool autoFillBackground() const; +// virtual bool hasTransparentBackground() const; virtual QGLContext* context() const = 0; QGLFormat format() const; @@ -96,11 +98,13 @@ public: virtual QPaintEngine* paintEngine() const; - virtual QColor backgroundColor() const; - virtual bool autoFillBackground() const; - virtual bool hasTransparentBackground() const; +// virtual void clearOnBegin() const; +// virtual QColor clearColor() const; +// virtual bool autoFillBackground() const; +// virtual bool hasTransparentBackground() const; // QGLWidgets need to do swapBufers in endPaint: + virtual void beginPaint(); virtual void endPaint(); virtual QSize size() const; virtual QGLContext* context() const; diff --git a/src/opengl/qpaintengine_opengl.cpp b/src/opengl/qpaintengine_opengl.cpp index 634067d..36a0081 100644 --- a/src/opengl/qpaintengine_opengl.cpp +++ b/src/opengl/qpaintengine_opengl.cpp @@ -1349,22 +1349,6 @@ bool QOpenGLPaintEngine::begin(QPaintDevice *pdev) d->offscreen.begin(); - if (d->device->context()->d_func()->clear_on_painter_begin && d->device->autoFillBackground()) { - - if (d->device->hasTransparentBackground()) - glClearColor(0.0, 0.0, 0.0, 0.0); - else { - const QColor &c = d->device->backgroundColor(); - glClearColor(c.redF(), c.greenF(), c.blueF(), 1.0); - } - - GLbitfield clearBits = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT; -#ifndef QT_OPENGL_ES - clearBits |= GL_ACCUM_BUFFER_BIT; -#endif - glClear(clearBits); - } - QSize sz(d->device->size()); glViewport(0, 0, sz.width(), sz.height()); // XXX (Embedded): We need a solution for GLWidgets that draw in a part or a bigger surface... glMatrixMode(GL_PROJECTION); |