diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-03 06:09:39 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-06-03 06:09:39 (GMT) |
commit | 694b270d78d99e94c8ab7543b7371edbe16ecaab (patch) | |
tree | a94380eb91ba6262d050fef1cdc3bb3995cdb4ad | |
parent | bc45ef6135b6a01d7fa601765647f2607ee047c8 (diff) | |
download | Qt-694b270d78d99e94c8ab7543b7371edbe16ecaab.zip Qt-694b270d78d99e94c8ab7543b7371edbe16ecaab.tar.gz Qt-694b270d78d99e94c8ab7543b7371edbe16ecaab.tar.bz2 |
Render items with z-order, and render opaque objects first.
-rw-r--r-- | src/declarative/canvas/qsimplecanvas.cpp | 4 | ||||
-rw-r--r-- | src/declarative/canvas/qsimplecanvas_opengl.cpp | 55 | ||||
-rw-r--r-- | src/declarative/canvas/qsimplecanvas_p.h | 1 | ||||
-rw-r--r-- | src/declarative/canvas/qsimplecanvasitem.h | 6 | ||||
-rw-r--r-- | src/declarative/canvas/qsimplecanvasitem_p.h | 6 | ||||
-rw-r--r-- | src/declarative/fx/qfximage.cpp | 5 |
6 files changed, 63 insertions, 14 deletions
diff --git a/src/declarative/canvas/qsimplecanvas.cpp b/src/declarative/canvas/qsimplecanvas.cpp index f1ff61b..cb46f94 100644 --- a/src/declarative/canvas/qsimplecanvas.cpp +++ b/src/declarative/canvas/qsimplecanvas.cpp @@ -923,7 +923,9 @@ bool QSimpleCanvas::event(QEvent *e) d->root->d_func()->setupPainting(0, rect(), &zero); #elif defined(QFX_RENDER_OPENGL2) ++d->paintVersion; - d->root->d_func()->setupPainting(0); + d->opaqueList = 0; + int z = 0; + d->root->d_func()->setupPainting(0, z, &d->opaqueList); #else ++d->paintVersion; d->root->d_func()->setupPainting(0, rect()); diff --git a/src/declarative/canvas/qsimplecanvas_opengl.cpp b/src/declarative/canvas/qsimplecanvas_opengl.cpp index dd57c14..659104d 100644 --- a/src/declarative/canvas/qsimplecanvas_opengl.cpp +++ b/src/declarative/canvas/qsimplecanvas_opengl.cpp @@ -53,7 +53,7 @@ QT_BEGIN_NAMESPACE void CanvasEGLWidget::paintGL() { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); _canvas->paintGL(); } @@ -120,8 +120,29 @@ void QSimpleCanvasPrivate::paintGL() p.opacity = 1; p.forceParamRefresh = false; p.painter = &painter; - if (!isSetup) - root->d_func()->setupPainting(0); + if (!isSetup) { + opaqueList = 0; + int z = 0; + root->d_func()->setupPainting(0, z, &opaqueList); + } + + glEnable(GL_DEPTH_TEST); + + glDisable(GL_BLEND); + painter.blendEnabled = false; + painter.activeOpacity = 1; + while (opaqueList) { + painter.item = opaqueList; + painter.activeTransform = opaqueList->d_func()->data()->transformActive; + // ### - I don't think this is right + painter.sceneClipRect = p.clipRect; + + opaqueList->paintGLContents(painter); + opaqueList = opaqueList->d_func()->nextOpaque; + } + glEnable(GL_BLEND); + painter.blendEnabled = true; + root->d_func()->paint(p); lrpTime = lrpTimer.elapsed(); @@ -274,7 +295,7 @@ void QSimpleCanvasItemPrivate::setupChildState(QSimpleCanvasItem *child) } //#define QSIMPLECANVAS_DISABLE_TREE_CLIPPING -QRectF QSimpleCanvasItemPrivate::setupPainting(int version) +QRectF QSimpleCanvasItemPrivate::setupPainting(int version, int &z, QSimpleCanvasItem **opaqueList) { static QRectF scene(-1., -1., 2., 2.); Q_Q(QSimpleCanvasItem); @@ -301,16 +322,31 @@ QRectF QSimpleCanvasItemPrivate::setupPainting(int version) (clip != QSimpleCanvasItem::NoClip); #endif + if (!myData->doNotPaint && + (options & QSimpleCanvasItem::IsOpaque) && + (myData->activeOpacity == 1.) && + (clip == 0)) { + + nextOpaque = *opaqueList; + *opaqueList = q; + myData->doNotPaint = true; + + } + + int myZ = z++; + if (myData->doNotPaintChildren) { rv = QRectF(); } else { + zOrderChildren(); + for (int ii = 0; ii < children.count(); ++ii) { QSimpleCanvasItem *child = children.at(ii); setupChildState(child); QSimpleCanvasItemData *childData = child->d_func()->data(); if (childData->activeOpacity != 0) - rv |= child->d_func()->setupPainting(version); + rv |= child->d_func()->setupPainting(version, z, opaqueList); } #ifndef QSIMPLECANVAS_DISABLE_TREE_CLIPPING @@ -318,11 +354,14 @@ QRectF QSimpleCanvasItemPrivate::setupPainting(int version) #endif } + myData->transformActive.translate(0, 0, myZ); + myData->lastPaintRect = rv; return rv; } + void QSimpleCanvasItemPrivate::paint(GLPaintParameters &oldParams, QSimpleCanvasFilter::Layer layer) { if (!layer) @@ -384,8 +423,6 @@ void QSimpleCanvasItemPrivate::paint(GLPaintParameters &oldParams, QSimpleCanvas params.clipRect = sr; } - zOrderChildren(); - int upto = 0; for (upto = 0; upto < children.count(); ++upto) { QSimpleCanvasItem *c = children.at(upto); @@ -438,12 +475,12 @@ void QSimpleCanvasItemPrivate::paint(GLPaintParameters &oldParams, QSimpleCanvas enum ShaderType { ST_None, ST_SingleTexture, ST_SingleTextureOpacity, ST_Color }; QSimpleCanvasItem::GLPainter::GLPainter() -: item(0), activeOpacity(1), flags(0) +: item(0), activeOpacity(1), blendEnabled(true), flags(0) { } QSimpleCanvasItem::GLPainter::GLPainter(QSimpleCanvasItem *i) -: item(i), activeOpacity(1), flags(0) +: item(i), activeOpacity(1), blendEnabled(true), flags(0) { } diff --git a/src/declarative/canvas/qsimplecanvas_p.h b/src/declarative/canvas/qsimplecanvas_p.h index b284c6c..5fc0c48 100644 --- a/src/declarative/canvas/qsimplecanvas_p.h +++ b/src/declarative/canvas/qsimplecanvas_p.h @@ -129,6 +129,7 @@ public: QRect resetDirty(); void paint(QPainter &p); + QSimpleCanvasItem *opaqueList; int timer; diff --git a/src/declarative/canvas/qsimplecanvasitem.h b/src/declarative/canvas/qsimplecanvasitem.h index 68219de..ee07a21 100644 --- a/src/declarative/canvas/qsimplecanvasitem.h +++ b/src/declarative/canvas/qsimplecanvasitem.h @@ -90,7 +90,8 @@ public: SimpleItem = 0x00000020, IsFocusPanel = 0x00000040, IsFocusRealm = 0x00000080, - AcceptsInputMethods = 0x00000100}; + AcceptsInputMethods = 0x00000100, + IsOpaque = 0x00000200 }; Q_DECLARE_FLAGS(Options, Option) QSimpleCanvasItem(QSimpleCanvasItem *parent=0); @@ -181,6 +182,9 @@ public: void fillRect(const QRectF &, const QColor &); void invalidate(); + + bool blendEnabled; + private: int flags; GLPainter(const GLPainter &); diff --git a/src/declarative/canvas/qsimplecanvasitem_p.h b/src/declarative/canvas/qsimplecanvasitem_p.h index 27ee0a2..6c21d9f 100644 --- a/src/declarative/canvas/qsimplecanvasitem_p.h +++ b/src/declarative/canvas/qsimplecanvasitem_p.h @@ -161,7 +161,7 @@ public: QSimpleCanvasItem::ClipType clip:3; QSimpleCanvasItem::TransformOrigin origin:4; - int options:9; + int options:10; bool focusable:1; bool wantsActiveFocusPanelPendingCanvas:1; bool hasBeenActiveFocusPanel:1; @@ -222,7 +222,7 @@ public: QSimpleCanvasItem::GLPainter *painter; }; #if defined(QFX_RENDER_OPENGL2) - QRectF setupPainting(int version); + QRectF setupPainting(int version, int &z, QSimpleCanvasItem **); #elif defined(QFX_RENDER_OPENGL1) QRectF setupPainting(int version, const QRect &bounding, unsigned int *zero); #endif @@ -241,6 +241,8 @@ public: #endif + QSimpleCanvasItem *nextOpaque; + void zOrderChildren(); bool freshenNeeded() const; void doFreshenTransforms() const; diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index 1fc84eb..d28cf7d 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -254,6 +254,9 @@ void QFxImage::setOpaque(bool o) if (o == d->_opaque) return; d->_opaque = o; + + setOptions(IsOpaque, o); + update(); } @@ -476,7 +479,7 @@ void QFxImage::paintGLContents(GLPainter &p) QGLShaderProgram *shader = p.useTextureShader(); bool restoreBlend = false; - if (isOpaque() && p.activeOpacity == 1) { + if (p.blendEnabled && isOpaque() && p.activeOpacity == 1) { glDisable(GL_BLEND); restoreBlend = true; } |