From 81df7a1293516de182f2b86ae289f00aa97d9091 Mon Sep 17 00:00:00 2001 From: Bradley Austin Davis Date: Fri, 4 May 2018 12:41:39 -0700 Subject: [PATCH 1/2] Fix texture leak in QML surface test --- tests/qml/src/main.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/tests/qml/src/main.cpp b/tests/qml/src/main.cpp index 349ac55d88..d983353893 100644 --- a/tests/qml/src/main.cpp +++ b/tests/qml/src/main.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include #include @@ -88,7 +88,7 @@ private: OffscreenGLCanvas _sharedContext; std::array, DIVISIONS_X> _surfaces; - QOpenGLFunctions_4_5_Core _glf; + QOpenGLFunctions_4_1_Core _glf; std::function _discardLamdba; QSize _size; size_t _surfaceCount{ 0 }; @@ -145,7 +145,7 @@ void TestWindow::initGl() { gl::initModuleGl(); _glf.initializeOpenGLFunctions(); - _glf.glCreateFramebuffers(1, &_fbo); + _glf.glGenFramebuffers(1, &_fbo); if (!_sharedContext.create(&_glContext) || !_sharedContext.makeCurrent()) { qFatal("Unable to intialize Shared GL context"); @@ -196,6 +196,12 @@ void TestWindow::buildSurface(QmlInfo& qmlInfo, bool video) { void TestWindow::destroySurface(QmlInfo& qmlInfo) { auto& surface = qmlInfo.surface; + auto& currentTexture = qmlInfo.texture; + if (currentTexture) { + auto readFence = _glf.glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + glFlush(); + _discardLamdba(currentTexture, readFence); + } auto webView = surface->getRootItem(); if (webView) { // stop loading @@ -274,16 +280,19 @@ void TestWindow::draw() { if (!qmlInfo.surface || !qmlInfo.texture) { continue; } - _glf.glNamedFramebufferTexture(_fbo, GL_COLOR_ATTACHMENT0, qmlInfo.texture, 0); - _glf.glBlitNamedFramebuffer(_fbo, 0, - // src coordinates - 0, 0, _qmlSize.width() - 1, _qmlSize.height() - 1, - // dst coordinates - incrementX * x, incrementY * y, incrementX * (x + 1), incrementY * (y + 1), - // blit mask and filter - GL_COLOR_BUFFER_BIT, GL_NEAREST); + _glf.glBindFramebuffer(GL_READ_FRAMEBUFFER, _fbo); + _glf.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, qmlInfo.texture, 0); + _glf.glBlitFramebuffer( + // src coordinates + 0, 0, _qmlSize.width() - 1, _qmlSize.height() - 1, + // dst coordinates + incrementX * x, incrementY * y, incrementX * (x + 1), incrementY * (y + 1), + // blit mask and filter + GL_COLOR_BUFFER_BIT, GL_NEAREST); } } + _glf.glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0); + _glf.glBindFramebuffer(GL_READ_FRAMEBUFFER, 0); _glContext.swapBuffers(this); } From cc4d04aaef8d7e1aae0950c4187e26211d7842f1 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 4 May 2018 14:45:57 -0700 Subject: [PATCH 2/2] experimenting --- tests/qml/src/main.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/qml/src/main.cpp b/tests/qml/src/main.cpp index d983353893..d70bb52dde 100644 --- a/tests/qml/src/main.cpp +++ b/tests/qml/src/main.cpp @@ -109,14 +109,6 @@ TestWindow::TestWindow() { Setting::init(); setSurfaceType(QSurface::OpenGLSurface); - QSurfaceFormat format; - format.setDepthBufferSize(24); - format.setStencilBufferSize(8); - format.setVersion(4, 5); - format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); - format.setOption(QSurfaceFormat::DebugContext); - QSurfaceFormat::setDefaultFormat(format); - setFormat(format); qmlRegisterType("Hifi", 1, 0, "TestItem"); @@ -301,6 +293,16 @@ void TestWindow::resizeEvent(QResizeEvent* ev) { } int main(int argc, char** argv) { + + QSurfaceFormat format; + format.setDepthBufferSize(24); + format.setStencilBufferSize(8); + format.setVersion(4, 1); + format.setProfile(QSurfaceFormat::OpenGLContextProfile::CoreProfile); + format.setOption(QSurfaceFormat::DebugContext); + QSurfaceFormat::setDefaultFormat(format); + // setFormat(format); + QGuiApplication app(argc, argv); TestWindow window; return app.exec();