Make QSGEngine::initialize backend-independent
Allow calling initialize(nullptr) regardless of which scenegraph backend is in use. Change-Id: Ie5965dcd12d423255d5eb85fed255107cac2acb9 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
parent
7de18e6f52
commit
1569f46bdc
|
@ -122,6 +122,8 @@ public:
|
|||
virtual QSGTexture *createTexture(const QImage &image, uint flags = CreateTexture_Alpha) const = 0;
|
||||
virtual QSGRenderer *createRenderer() = 0;
|
||||
|
||||
virtual void setAttachToGraphicsContext(bool attach) { Q_UNUSED(attach); }
|
||||
|
||||
void registerFontengineForCleanup(QFontEngine *engine);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
|
|
@ -273,7 +273,7 @@ void QSGDefaultRenderContext::initializeShader(QSGMaterialShader *shader)
|
|||
shader->initialize();
|
||||
}
|
||||
|
||||
void QSGDefaultRenderContext::setAttachToGLContext(bool attach)
|
||||
void QSGDefaultRenderContext::setAttachToGraphicsContext(bool attach)
|
||||
{
|
||||
Q_ASSERT(!isValid());
|
||||
m_attachToGLContext = attach;
|
||||
|
|
|
@ -88,7 +88,7 @@ public:
|
|||
virtual void compileShader(QSGMaterialShader *shader, QSGMaterial *material, const char *vertexCode = 0, const char *fragmentCode = 0);
|
||||
virtual void initializeShader(QSGMaterialShader *shader);
|
||||
|
||||
void setAttachToGLContext(bool attach);
|
||||
void setAttachToGraphicsContext(bool attach) override;
|
||||
|
||||
static QSGDefaultRenderContext *from(QOpenGLContext *context);
|
||||
|
||||
|
|
|
@ -115,23 +115,21 @@ QSGEngine::~QSGEngine()
|
|||
*/
|
||||
void QSGEngine::initialize(QOpenGLContext *context)
|
||||
{
|
||||
#ifndef QT_NO_OPENGL
|
||||
Q_D(QSGEngine);
|
||||
if (QOpenGLContext::currentContext() != context) {
|
||||
#ifdef 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
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
Loading…
Reference in New Issue