From 786747c2d7311851ae80387a0684a8d0a0a8576c Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Sat, 20 Feb 2016 12:01:34 -0800 Subject: [PATCH] Properly preserve and restore the GL context after building a web entity --- .../entities-renderer/src/RenderableWebEntityItem.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index ade44f94a0..b0aeaffd4e 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -58,7 +58,9 @@ bool RenderableWebEntityItem::buildWebSurface(EntityTreeRenderer* renderer) { qDebug() << "Building web surface"; ++_currentWebCount; + // Save the original GL context, because creating a QML surface will create a new context QOpenGLContext * currentContext = QOpenGLContext::currentContext(); + QSurface * currentSurface = currentContext->surface(); _webSurface = new OffscreenQmlSurface(); _webSurface->create(currentContext); _webSurface->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/")); @@ -68,6 +70,8 @@ bool RenderableWebEntityItem::buildWebSurface(EntityTreeRenderer* renderer) { _connection = QObject::connect(_webSurface, &OffscreenQmlSurface::textureUpdated, [&](GLuint textureId) { _texture = textureId; }); + // Restore the original GL context + currentContext->makeCurrent(currentSurface); auto forwardMouseEvent = [=](const RayToEntityIntersectionResult& intersection, const QMouseEvent* event, unsigned int deviceId) { // Ignore mouse interaction if we're locked @@ -142,7 +146,6 @@ bool RenderableWebEntityItem::buildWebSurface(EntityTreeRenderer* renderer) { QCoreApplication::sendEvent(_webSurface->getWindow(), &mappedEvent); } }; - _mousePressConnection = QObject::connect(renderer, &EntityTreeRenderer::mousePressOnEntity, forwardMouseEvent); _mouseReleaseConnection = QObject::connect(renderer, &EntityTreeRenderer::mouseReleaseOnEntity, forwardMouseEvent); _mouseMoveConnection = QObject::connect(renderer, &EntityTreeRenderer::mouseMoveOnEntity, forwardMouseEvent); @@ -176,16 +179,12 @@ void RenderableWebEntityItem::render(RenderArgs* args) { } _lastRenderTime = usecTimestampNow(); - QOpenGLContext * currentContext = QOpenGLContext::currentContext(); - QSurface * currentSurface = currentContext->surface(); - glm::vec2 dims = glm::vec2(getDimensions()); dims *= METERS_TO_INCHES * DPI; // The offscreen surface is idempotent for resizes (bails early // if it's a no-op), so it's safe to just call resize every frame // without worrying about excessive overhead. _webSurface->resize(QSize(dims.x, dims.y)); - currentContext->makeCurrent(currentSurface); PerformanceTimer perfTimer("RenderableWebEntityItem::render"); Q_ASSERT(getType() == EntityTypes::Web);