diff options
Diffstat (limited to 'src/quick/scenegraph/util/qsgengine.cpp')
-rw-r--r-- | src/quick/scenegraph/util/qsgengine.cpp | 63 |
1 files changed, 51 insertions, 12 deletions
diff --git a/src/quick/scenegraph/util/qsgengine.cpp b/src/quick/scenegraph/util/qsgengine.cpp index 26a3d66077..ad1fcfa470 100644 --- a/src/quick/scenegraph/util/qsgengine.cpp +++ b/src/quick/scenegraph/util/qsgengine.cpp @@ -115,23 +115,21 @@ QSGEngine::~QSGEngine() */ void QSGEngine::initialize(QOpenGLContext *context) { -#ifndef QT_NO_OPENGL Q_D(QSGEngine); - if (QOpenGLContext::currentContext() != context) { +#ifndef QT_NO_OPENGL + if (context && QOpenGLContext::currentContext() != context) { qWarning("WARNING: The context must be current before calling QSGEngine::initialize."); return; } - - auto openGLRenderContext = static_cast<QSGDefaultRenderContext *>(d->sgRenderContext.data()); - - if (openGLRenderContext != nullptr && !openGLRenderContext->isValid()) { - openGLRenderContext->setAttachToGLContext(false); - openGLRenderContext->initialize(context); - connect(context, &QOpenGLContext::aboutToBeDestroyed, this, &QSGEngine::invalidate); - } -#else - Q_UNUSED(context) #endif + if (d->sgRenderContext && !d->sgRenderContext->isValid()) { + d->sgRenderContext->setAttachToGraphicsContext(false); + d->sgRenderContext->initialize(context); +#ifndef QT_NO_OPENGL + if (context) + connect(context, &QOpenGLContext::aboutToBeDestroyed, this, &QSGEngine::invalidate); +#endif + } } /*! @@ -223,4 +221,45 @@ QSGRendererInterface *QSGEngine::rendererInterface() const : nullptr; } +/*! + Creates a simple rectangle node. When the scenegraph is not initialized, the return value is null. + + This is cross-backend alternative to constructing a QSGSimpleRectNode directly. + + \since 5.8 + \sa QSGRectangleNode + */ +QSGRectangleNode *QSGEngine::createRectangleNode() const +{ + Q_D(const QSGEngine); + return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createRectangleNode() : nullptr; +} + +/*! + Creates a simple image node. When the scenegraph is not initialized, the return value is null. + + This is cross-backend alternative to constructing a QSGSimpleTextureNode directly. + + \since 5.8 + \sa QSGImageNode + */ + +QSGImageNode *QSGEngine::createImageNode() const +{ + Q_D(const QSGEngine); + return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createImageNode() : nullptr; +} + +/*! + Creates a nine patch node. When the scenegraph is not initialized, the return value is null. + + \since 5.8 + */ + +QSGNinePatchNode *QSGEngine::createNinePatchNode() const +{ + Q_D(const QSGEngine); + return d->sgRenderContext->isValid() ? d->sgRenderContext->sceneGraphContext()->createNinePatchNode() : nullptr; +} + QT_END_NAMESPACE |