From dcbb16a45212d263496df1e5875da6205e4f5f53 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 30 Dec 2013 14:37:22 +0100 Subject: Add takeTexture() to QOpenGLFramebufferObject Add an API that allows to retrieve and detach the texture from the framebuffer object. The next bind() call will then create and attach a new texture. [ChangeLog][QtGui][QOpenGLFramebufferObject] Added takeTexture() for retrieving and detaching the texture from the framebuffer object. Task-number: QTBUG-35881 Change-Id: I2cca37f5872c1685b1238047f8b912e6534ab781 Reviewed-by: Gunnar Sletta --- tests/auto/gui/qopengl/tst_qopengl.cpp | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'tests/auto/gui/qopengl') diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 4defbe181f..e39380a095 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -66,6 +66,8 @@ private slots: void multiGroupSharedResourceCleanupCustom(); void fboSimpleRendering_data(); void fboSimpleRendering(); + void fboTextureOwnership_data(); + void fboTextureOwnership(); void fboRendering_data(); void fboRendering(); void fboHandleNulledAfterContextDestroyed(); @@ -429,6 +431,54 @@ void tst_QOpenGL::fboSimpleRendering() delete fbo; } +void tst_QOpenGL::fboTextureOwnership_data() +{ + common_data(); +} + +void tst_QOpenGL::fboTextureOwnership() +{ + QFETCH(int, surfaceClass); + QScopedPointer surface(createSurface(surfaceClass)); + + QOpenGLContext ctx; + QVERIFY(ctx.create()); + + ctx.makeCurrent(surface.data()); + + if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) + QSKIP("QOpenGLFramebufferObject not supported on this platform"); + + QOpenGLFramebufferObjectFormat fboFormat; + fboFormat.setAttachment(QOpenGLFramebufferObject::NoAttachment); + + QOpenGLFramebufferObject *fbo = new QOpenGLFramebufferObject(200, 100, fboFormat); + QVERIFY(fbo->texture() != 0); + fbo->bind(); + + // pull out the texture + GLuint texture = fbo->takeTexture(); + QVERIFY(texture != 0); + QVERIFY(fbo->texture() == 0); + + // verify that the next bind() creates a new texture + fbo->bind(); + QVERIFY(fbo->texture() != 0 && fbo->texture() != texture); + + glClearColor(1.0, 0.0, 0.0, 1.0); + glClear(GL_COLOR_BUFFER_BIT); + glFinish(); + + QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32); + QImage reference(fb.size(), QImage::Format_RGB32); + reference.fill(0xffff0000); + + QFUZZY_COMPARE_IMAGES(fb, reference); + + glDeleteTextures(1, &texture); + delete fbo; +} + void tst_QOpenGL::fboRendering_data() { common_data(); -- cgit v1.2.3