diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/items/qquickcanvas.cpp | 182 | ||||
-rw-r--r-- | src/declarative/items/qquickcanvas.h | 23 | ||||
-rw-r--r-- | src/declarative/items/qquickcanvas_p.h | 3 | ||||
-rw-r--r-- | src/declarative/scenegraph/qsgcontext.cpp | 21 | ||||
-rw-r--r-- | src/declarative/scenegraph/qsgcontext_p.h | 1 | ||||
-rw-r--r-- | src/declarative/scenegraph/util/qsgengine.cpp | 174 | ||||
-rw-r--r-- | src/declarative/scenegraph/util/qsgengine.h | 6 |
7 files changed, 230 insertions, 180 deletions
diff --git a/src/declarative/items/qquickcanvas.cpp b/src/declarative/items/qquickcanvas.cpp index 383b5526a4..765f9eca8d 100644 --- a/src/declarative/items/qquickcanvas.cpp +++ b/src/declarative/items/qquickcanvas.cpp @@ -46,7 +46,9 @@ #include "qquickitem_p.h" #include <private/qsgrenderer_p.h> +#include <private/qsgtexture_p.h> #include <private/qsgflashnode_p.h> +#include <qsgengine.h> #include <private/qguiapplication_p.h> #include <QtGui/QInputPanel> @@ -412,6 +414,9 @@ void QQuickCanvasPrivate::initializeSceneGraph() context->rootNode()->appendChildNode(QQuickItemPrivate::get(rootItem)->itemNode()); } + engine = new QSGEngine(); + engine->setCanvas(q); + emit q_func()->sceneGraphInitialized(); } @@ -431,16 +436,26 @@ void QQuickCanvasPrivate::polishItems() void QQuickCanvasPrivate::syncSceneGraph() { updateDirtyNodes(); + + // Copy the current state of clearing from canvas into renderer. + context->renderer()->setClearColor(clearColor); + QSGRenderer::ClearMode mode = QSGRenderer::ClearStencilBuffer | QSGRenderer::ClearDepthBuffer; + if (clearBeforeRendering) + mode |= QSGRenderer::ClearColorBuffer; + context->renderer()->setClearMode(mode); } void QQuickCanvasPrivate::renderSceneGraph(const QSize &size) { + Q_Q(QQuickCanvas); context->renderer()->setDeviceRect(QRect(QPoint(0, 0), size)); context->renderer()->setViewportRect(QRect(QPoint(0, 0), renderTarget ? renderTarget->size() : size)); context->renderer()->setProjectionMatrixToDeviceRect(); + emit q->beforeRendering(); context->renderNextFrame(renderTarget); + emit q->afterRendering(); #ifdef FRAME_TIMING sceneGraphRenderTime = frameTimer.elapsed(); @@ -467,7 +482,9 @@ QQuickCanvasPrivate::QQuickCanvasPrivate() , mouseGrabberItem(0) , dirtyItemList(0) , context(0) + , clearColor(Qt::white) , vsyncAnimations(false) + , clearBeforeRendering(true) , thread(0) , animationDriver(0) , renderTarget(0) @@ -1937,13 +1954,16 @@ void QQuickCanvas::maybeUpdate() The engine will only be available once the scene graph has been initialized. Register for the sceneGraphEngine() signal to get notification about this. + + \deprecated */ QSGEngine *QQuickCanvas::sceneGraphEngine() const { Q_D(const QQuickCanvas); + qWarning("QQuickCanvas::sceneGraphEngine() is deprecated, use members of QQuickCanvas instead"); if (d->context && d->context->isReady()) - return d->context->engine(); + return d->engine; return 0; } @@ -2019,6 +2039,166 @@ QDeclarativeIncubationController *QQuickCanvas::incubationController() const } + +/*! + \enum QQuickCanvas::CreateTextureOption + + The CreateTextureOption enums are used to customize a texture is wrapped. + + \value TextureHasAlphaChannel The texture has an alpha channel and should + be drawn using blending. + + \value TextureHasMipmaps The texture has mipmaps and can be drawn with + mipmapping enabled. + + \value TextureOwnsGLTexture The texture object owns the texture id and + will delete the GL texture when the texture object is deleted. + */ + +/*! + \fn void QQuickCanvas::beforeRendering() + + This signal is emitted before the scene starts rendering. + + Combined with the modes for clearing the background, this option + can be used to paint using raw GL under QML content. + + The GL context used for rendering the scene graph will be bound + at this point. + + Since this signal is emitted from the scene graph rendering thread, the receiver should + be on the scene graph thread or the connection should be Qt::DirectConnection. + +*/ + +/*! + \fn void QQuickCanvas::afterRendering() + + This signal is emitted after the scene has completed rendering, before swapbuffers is called. + + This signal can be used to paint using raw GL on top of QML content, + or to do screen scraping of the current frame buffer. + + The GL context used for rendering the scene graph will be bound at this point. + + Since this signal is emitted from the scene graph rendering thread, the receiver should + be on the scene graph thread or the connection should be Qt::DirectConnection. + */ + + + +/*! + Sets weither the scene graph rendering of QML should clear the color buffer + before it starts rendering to \a enbled. + + By disabling clearing of the color buffer, it is possible to do GL painting + under the scene graph. + + The color buffer is cleared by default. + + \sa beforeRendering() + */ + +void QQuickCanvas::setClearBeforeRendering(bool enabled) +{ + Q_D(QQuickCanvas); + d->clearBeforeRendering = enabled; +} + + + +/*! + Returns weither clearing of the color buffer is done before rendering or not. + */ + +bool QQuickCanvas::clearBeforeRendering() const +{ + Q_D(const QQuickCanvas); + return d->clearBeforeRendering; +} + + + +/*! + Creates a new QSGTexture from the supplied \a image. If the image has an + alpha channel, the corresponding texture will have an alpha channel. + + The caller of the function is responsible for deleting the returned texture. + The actual GL texture will be deleted when the texture object is deleted. + + \warning This function will return 0 if the scene graph has not yet been + initialized. + + This function can be called both from the GUI thread and the rendering thread. + + \sa sceneGraphInitialized() + */ + +QSGTexture *QQuickCanvas::createTextureFromImage(const QImage &image) const +{ + Q_D(const QQuickCanvas); + if (d->context) + return d->context->createTexture(image); + else + return 0; +} + + + +/*! + Creates a new QSGTexture object from an existing GL texture \a id. + + The caller of the function is responsible for deleting the returned texture. + + Use \a options to customize the texture attributes. + + \warning This function will return 0 if the scenegraph has not yet been + initialized. + + \sa sceneGraphInitialized() + */ +QSGTexture *QQuickCanvas::createTextureFromId(uint id, const QSize &size, CreateTextureOptions options) const +{ + Q_D(const QQuickCanvas); + if (d->context) { + QSGPlainTexture *texture = new QSGPlainTexture(); + texture->setTextureId(id); + texture->setHasAlphaChannel(options & TextureHasAlphaChannel); + texture->setHasMipmaps(options & TextureHasMipmaps); + texture->setOwnsTexture(options & TextureOwnsGLTexture); + texture->setTextureSize(size); + return texture; + } + return 0; +} + + +/*! + Sets the color used to clear the opengl context to \a color. + + Setting the clear color has no effect when clearing is disabled. + + \sa setClearBeforeRendering() + */ + +void QQuickCanvas::setClearColor(const QColor &color) +{ + d_func()->clearColor = color; +} + + + +/*! + Returns the color used to clear the opengl context. + */ + +QColor QQuickCanvas::clearColor() const +{ + return d_func()->clearColor; +} + + + void QQuickCanvasRenderLoop::createGLContext() { gl = new QOpenGLContext(); diff --git a/src/declarative/items/qquickcanvas.h b/src/declarative/items/qquickcanvas.h index e9b1b60613..847a6fb059 100644 --- a/src/declarative/items/qquickcanvas.h +++ b/src/declarative/items/qquickcanvas.h @@ -54,6 +54,7 @@ QT_MODULE(Declarative) class QQuickItem; class QSGEngine; +class QSGTexture; class QQuickCanvasPrivate; class QOpenGLFramebufferObject; class QDeclarativeIncubationController; @@ -63,6 +64,14 @@ class Q_DECLARATIVE_EXPORT QQuickCanvas : public QWindow Q_OBJECT Q_DECLARE_PRIVATE(QQuickCanvas) public: + enum CreateTextureOption { + TextureHasAlphaChannel = 0x0001, + TextureHasMipmaps = 0x0002, + TextureOwnsGLTexture = 0x0004 + }; + + Q_DECLARE_FLAGS(CreateTextureOptions, CreateTextureOption) + QQuickCanvas(QWindow *parent = 0); virtual ~QQuickCanvas(); @@ -88,9 +97,23 @@ public: QDeclarativeIncubationController *incubationController() const; + // Scene graph specific functions + QSGTexture *createTextureFromImage(const QImage &image) const; + QSGTexture *createTextureFromId(uint id, const QSize &size, CreateTextureOptions options = CreateTextureOption(0)) const; + + void setClearBeforeRendering(bool enabled); + bool clearBeforeRendering() const; + + void setClearColor(const QColor &color); + QColor clearColor() const; + + QOpenGLContext *openglContext() const; + Q_SIGNALS: void frameSwapped(); void sceneGraphInitialized(); + void beforeRendering(); + void afterRendering(); protected: QQuickCanvas(QQuickCanvasPrivate &dd, QWindow *parent = 0); diff --git a/src/declarative/items/qquickcanvas_p.h b/src/declarative/items/qquickcanvas_p.h index 702234d9e8..fdfe0911f5 100644 --- a/src/declarative/items/qquickcanvas_p.h +++ b/src/declarative/items/qquickcanvas_p.h @@ -157,9 +157,12 @@ public: void updateEffectiveOpacityRoot(QQuickItem *, qreal); void updateDirtyNode(QQuickItem *); + QSGEngine *engine; QSGContext *context; + QColor clearColor; uint vsyncAnimations : 1; + uint clearBeforeRendering : 1; QQuickCanvasRenderLoop *thread; QSize widgetSize; diff --git a/src/declarative/scenegraph/qsgcontext.cpp b/src/declarative/scenegraph/qsgcontext.cpp index 87beb72b5b..50af0dadfa 100644 --- a/src/declarative/scenegraph/qsgcontext.cpp +++ b/src/declarative/scenegraph/qsgcontext.cpp @@ -53,8 +53,6 @@ #include <private/qsgdistancefieldglyphnode_p.h> #include <private/qsgtexture_p.h> -#include <qsgengine.h> - #include <QGuiApplication> #include <QOpenGLContext> @@ -108,8 +106,6 @@ public: QOpenGLContext *gl; - QSGEngine engine; - QHash<QSGMaterialType *, QSGMaterialShader *> materials; QSGDistanceFieldGlyphCacheManager *distanceFieldCacheManager; @@ -138,7 +134,6 @@ QSGContext::QSGContext(QObject *parent) : QObject(*(new QSGContextPrivate), parent) { Q_D(QSGContext); - d->engine.setContext(this); } @@ -153,18 +148,6 @@ QSGContext::~QSGContext() } /*! - Returns the scene graph engine for this context. - - The main purpose of the QSGEngine is to serve as a public API - to the QSGContext. - - */ -QSGEngine *QSGContext::engine() const -{ - return const_cast<QSGEngine *>(&d_func()->engine); -} - -/*! Schedules the texture to be cleaned up on the rendering thread at a later time. @@ -258,8 +241,6 @@ void QSGContext::renderNextFrame(QOpenGLFramebufferObject *fbo) { Q_D(QSGContext); - emit d->engine.beforeRendering(); - cleanupTextures(); if (fbo) { @@ -269,8 +250,6 @@ void QSGContext::renderNextFrame(QOpenGLFramebufferObject *fbo) d->renderer->renderScene(); } - emit d->engine.afterRendering(); - } /*! diff --git a/src/declarative/scenegraph/qsgcontext_p.h b/src/declarative/scenegraph/qsgcontext_p.h index 328b85eb2b..41a9a4a89b 100644 --- a/src/declarative/scenegraph/qsgcontext_p.h +++ b/src/declarative/scenegraph/qsgcontext_p.h @@ -89,7 +89,6 @@ public: void setRootNode(QSGRootNode *node); QSGRootNode *rootNode() const; - QSGEngine *engine() const; QOpenGLContext *glContext() const; bool isReady() const; diff --git a/src/declarative/scenegraph/util/qsgengine.cpp b/src/declarative/scenegraph/util/qsgengine.cpp index 2b7e5bed73..88eeebc472 100644 --- a/src/declarative/scenegraph/util/qsgengine.cpp +++ b/src/declarative/scenegraph/util/qsgengine.cpp @@ -41,8 +41,10 @@ #include "qsgengine.h" -#include <private/qsgtexture_p.h> -#include <private/qsgrenderer_p.h> +#include <qquickcanvas.h> + +#include <private/qobject_p.h> +#include <QtGui/QColor> QT_BEGIN_NAMESPACE @@ -50,33 +52,18 @@ class QSGEnginePrivate : public QObjectPrivate { public: QSGEnginePrivate() - : context(0) - , clearBeforeRender(true) + : canvas(0) { } - QSGContext *context; - - bool clearBeforeRender; + QQuickCanvas *canvas; }; - /*! \class QSGEngine - \brief The QSGEngine class serves as a generic entry point into scene graph specific APIs. - - The QSGEngine class provides factory functions for creating textures. Though the user - can implement any type of texture using the abstract QSGTexture class, the QSGEngine - class provides some convenience for the default usecases. This also allows the scene - graph to apply hardware specific optimzations. - + \deprecated */ - - -/*! - Constructs a new QSGengine - */ QSGEngine::QSGEngine(QObject *parent) : QObject(*(new QSGEnginePrivate), parent) { @@ -87,165 +74,42 @@ QSGEngine::~QSGEngine() { } -/*! - \enum TextureOption - - The TextureOption enums are used to customize a texture is wrapped. - - \value TextureHasAlphaChannel The texture has an alpha channel and should - be drawn using blending. - - \value TextureHasMipmaps The texture has mipmaps and can be drawn with - mipmapping enabled. - - \value TextureOwnsGLTexture The texture object owns the texture id and - will delete the GL texture when the texture object is deleted. - - */ - -/*! - \fn void QSGEngine::beforeRendering() - - This signal is emitted before the scene starts rendering. - - Combined with the modes for clearing the background, this option - can be used to paint using raw GL under QML content. - The GL context used for rendering the scene graph will be bound - at this point. - - Since this signal is emitted from the scene graph rendering thread, the receiver should - be on the scene graph thread or the connection should be Qt::DirectConnection. - -*/ - -/*! - \fn void QSGEngine::afterRendering() - - This signal is emitted after the scene has completed rendering, before swapbuffers is called. - - This signal can be used to paint using raw GL on top of QML content, - or to do screen scraping of the current frame buffer. - - The GL context used for rendering the scene graph will be bound at this point. - - Since this signal is emitted from the scene graph rendering thread, the receiver should - be on the scene graph thread or the connection should be Qt::DirectConnection. - */ - - - -/*! - Sets weither the scene graph rendering of QML should clear the color buffer - before it starts rendering to \a enbled. - - By disabling clearing of the color buffer, it is possible to do GL painting - under the scene graph. - - The color buffer is cleared by default. - */ +void QSGEngine::setCanvas(QQuickCanvas *canvas) +{ + d_func()->canvas = canvas; + connect(canvas, SIGNAL(afterRendering()), this, SIGNAL(afterRendering())); + connect(canvas, SIGNAL(beforeRendering()), this, SIGNAL(beforeRendering())); +} void QSGEngine::setClearBeforeRendering(bool enabled) { - Q_D(QSGEngine); - d->clearBeforeRender = enabled; - if (d->clearBeforeRender) { - d->context->renderer()->setClearMode(QSGRenderer::ClearDepthBuffer - | QSGRenderer::ClearColorBuffer); - } else { - d->context->renderer()->setClearMode(QSGRenderer::ClearDepthBuffer); - } + d_func()->canvas->setClearBeforeRendering(enabled); } - - -/*! - Returns weither clearing of the color buffer is done before rendering or not. - */ - bool QSGEngine::clearBeforeRendering() const { - Q_D(const QSGEngine); - return d->clearBeforeRender; + return d_func()->canvas->clearBeforeRendering(); } - - -/*! - Creates a new QSGTexture from the supplied \a image. If the image has an - alpha channel, the corresponding texture will have an alpha channel. - - The caller of the function is responsible for deleting the returned texture. - - The actual GL texture will be deleted when the texture object is deleted. - */ - QSGTexture *QSGEngine::createTextureFromImage(const QImage &image) const { - Q_D(const QSGEngine); - return d->context->createTexture(image); + return d_func()->canvas->createTextureFromImage(image); } - - -/*! - Creates a new QSGTexture object from an existing GL texture \a id. - - The caller of the function is responsible for deleting the returned texture. - - Use \a options to customize the texture attributes. - */ QSGTexture *QSGEngine::createTextureFromId(uint id, const QSize &size, TextureOptions options) const { - QSGPlainTexture *texture = new QSGPlainTexture(); - texture->setTextureId(id); - texture->setHasAlphaChannel(options & TextureHasAlphaChannel); - texture->setHasMipmaps(options & TextureHasMipmaps); - texture->setOwnsTexture(options & TextureOwnsGLTexture); - texture->setTextureSize(size); - return texture; + return d_func()->canvas->createTextureFromId(id, size, QQuickCanvas::CreateTextureOptions((int) options)); } - - -/*! - \internal - - Sets the scene graph context of this engine to context. - - The context will be set by the QSGcontext::initialize() function, - as part of constructing the engine object. - */ - -void QSGEngine::setContext(QSGContext *context) -{ - Q_D(QSGEngine); - d->context = context; -} - - - -/*! - Sets the background color of the scene graph to \a color. - - Changing the clear color has no effect when clearing before rendering is - disabled. - */ - void QSGEngine::setClearColor(const QColor &color) { - d_func()->context->renderer()->setClearColor(color); + d_func()->canvas->setClearColor(color); } - - -/*! - Returns the background color of the scene graph - */ - QColor QSGEngine::clearColor() const { - return d_func()->context->renderer()->clearColor(); + return d_func()->canvas->clearColor(); } QT_END_NAMESPACE diff --git a/src/declarative/scenegraph/util/qsgengine.h b/src/declarative/scenegraph/util/qsgengine.h index f9a0ea1da6..0cbbcddfec 100644 --- a/src/declarative/scenegraph/util/qsgengine.h +++ b/src/declarative/scenegraph/util/qsgengine.h @@ -54,7 +54,8 @@ QT_MODULE(Declarative) class QSGEnginePrivate; -class QSGContext; +class QQuickCanvas; + class Q_DECLARATIVE_EXPORT QSGEngine : public QObject { Q_OBJECT @@ -89,7 +90,8 @@ private: friend class QSGContext; friend class QSGContextPrivate; - void setContext(QSGContext *context); + friend class QQuickCanvasPrivate; + void setCanvas(QQuickCanvas *canvas); }; |