diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-04-17 17:11:42 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-04-17 19:32:00 +0200 |
commit | e05fcf6b604dae0c060729eaf4e75542c0973caf (patch) | |
tree | 0d7157a3cd9742ce00641bbd9ffd5a90584c8acd /src/quick/scenegraph/qsgdefaultrendercontext.cpp | |
parent | 51e610183fe6bf4a7e38a67219041d406ad6e9d5 (diff) |
rhi: Make rendercontext query safe in slots connected to invalidated
separateIndexBuffers() returns an incorrect value when called from a
slot connected to the invalidated() signal. This is because members like
m_rhi are nulled out before emitting the signal (thus making isValid()
return false), and this follows the existing QOpenGLContext (m_gl) behavior.
Instead of altering the logic, just decide the value of separateIndexBuffers
in initialize() and keep returning that from the query from then on.
This is relevant for Qt Quick 3D at least, which happens to destroy manually
created QSGLayer instances (which in turn own renderer objects) in a slot
connected to invalidated().
Task-number: QTBUG-83469
Change-Id: I81b34b57921242367c80f7d04331cb6bd3318ec8
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/quick/scenegraph/qsgdefaultrendercontext.cpp')
-rw-r--r-- | src/quick/scenegraph/qsgdefaultrendercontext.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/quick/scenegraph/qsgdefaultrendercontext.cpp b/src/quick/scenegraph/qsgdefaultrendercontext.cpp index ed2f8c313f..696801cc88 100644 --- a/src/quick/scenegraph/qsgdefaultrendercontext.cpp +++ b/src/quick/scenegraph/qsgdefaultrendercontext.cpp @@ -69,6 +69,7 @@ QSGDefaultRenderContext::QSGDefaultRenderContext(QSGContext *context) , m_rhiAtlasManager(nullptr) , m_currentFrameCommandBuffer(nullptr) , m_currentFrameRenderPass(nullptr) + , m_separateIndexBuffer(false) { } @@ -92,6 +93,8 @@ void QSGDefaultRenderContext::initialize(const QSGRenderContext::InitParams *par m_maxTextureSize = m_rhi->resourceLimit(QRhi::TextureSizeMax); if (!m_rhiAtlasManager) m_rhiAtlasManager = new QSGRhiAtlasTexture::Manager(this, m_initParams.initialSurfacePixelSize, m_initParams.maybeSurface); + // unlike OpenGL (and like WebGL), QRhi does not guarantee buffer usage types can be mixed + m_separateIndexBuffer = true; } else { QOpenGLFunctions *funcs = m_rhi ? nullptr : QOpenGLContext::currentContext()->functions(); funcs->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_maxTextureSize); @@ -124,6 +127,15 @@ void QSGDefaultRenderContext::initialize(const QSGRenderContext::InitParams *par if (!m_glAtlasManager) m_glAtlasManager = new QSGOpenGLAtlasTexture::Manager(m_initParams.initialSurfacePixelSize); + + // WebGL: A given WebGLBuffer object may only be bound to one of + // the ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER target in its + // lifetime. An attempt to bind a buffer object to the other + // target will generate an INVALID_OPERATION error, and the + // current binding will remain untouched. + const bool isWebGL = (qGuiApp->platformName().compare(QLatin1String("webgl")) == 0 + || qGuiApp->platformName().compare(QLatin1String("wasm")) == 0); + m_separateIndexBuffer = isWebGL; } m_sg->renderContextInitialized(this); @@ -417,17 +429,7 @@ QSGDefaultRenderContext *QSGDefaultRenderContext::from(QOpenGLContext *context) bool QSGDefaultRenderContext::separateIndexBuffer() const { - if (m_rhi) - return true; - - // WebGL: A given WebGLBuffer object may only be bound to one of - // the ARRAY_BUFFER or ELEMENT_ARRAY_BUFFER target in its - // lifetime. An attempt to bind a buffer object to the other - // target will generate an INVALID_OPERATION error, and the - // current binding will remain untouched. - static const bool isWebGL = (qGuiApp->platformName().compare(QLatin1String("webgl")) == 0 - || qGuiApp->platformName().compare(QLatin1String("wasm")) == 0); - return isWebGL; + return m_separateIndexBuffer; } QSGDistanceFieldGlyphCache *QSGDefaultRenderContext::distanceFieldGlyphCache(const QRawFont &font) |