From e7056a8969cf9445ff84c7362137f792ef207ae2 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 23 Jun 2014 16:45:11 +0200 Subject: Add context adoption support for WGL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is trickier than the GLX and EGL implementations due to the way pixel formats, windows and contexts work. Apart from some restrictions, it should be fully functional nonetheless. Add also some proper documentation. Change-Id: Ia6e3eb1ab2701e439b8621b9092c2b0934ff2151 Reviewed-by: Jørgen Lind --- tests/auto/gui/qopengl/tst_qopengl.cpp | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'tests/auto/gui') diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 1e8727ca04..972c2a7ea4 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -65,6 +65,10 @@ #include #endif +#if defined(Q_OS_WIN32) && !defined(QT_OPENGL_ES_2) +#include +#endif + Q_DECLARE_METATYPE(QImage::Format) class tst_QOpenGL : public QObject @@ -100,6 +104,10 @@ private slots: void glxContextWrap(); #endif +#if defined(Q_OS_WIN32) && !defined(QT_OPENGL_ES_2) + void wglContextWrap(); +#endif + void vaoCreate(); }; @@ -1033,6 +1041,61 @@ void tst_QOpenGL::glxContextWrap() } #endif // USE_GLX +#if defined(Q_OS_WIN32) && !defined(QT_OPENGL_ES_2) +void tst_QOpenGL::wglContextWrap() +{ + QScopedPointer ctx(new QOpenGLContext); + QVERIFY(ctx->create()); + if (ctx->isOpenGLES()) + QSKIP("Not applicable to EGL"); + + QScopedPointer window(new QWindow); + window->setSurfaceType(QWindow::OpenGLSurface); + window->setGeometry(0, 0, 256, 256); + window->show(); + QTest::qWaitForWindowExposed(window.data()); + + QVariant v = ctx->nativeHandle(); + QVERIFY(!v.isNull()); + QVERIFY(v.canConvert()); + QWGLNativeContext nativeContext = v.value(); + QVERIFY(nativeContext.context()); + + // Now do a makeCurrent() do make sure the pixel format on the native + // window (the HWND we are going to retrieve below) is set. + QVERIFY(ctx->makeCurrent(window.data())); + ctx->doneCurrent(); + + HWND wnd = (HWND) qGuiApp->platformNativeInterface()->nativeResourceForWindow(QByteArrayLiteral("handle"), window.data()); + QVERIFY(wnd); + + QScopedPointer adopted(new QOpenGLContext); + adopted->setNativeHandle(QVariant::fromValue(QWGLNativeContext(nativeContext.context(), wnd))); + QVERIFY(adopted->create()); + + // This tests two things: that a regular, non-adopted QOpenGLContext is + // able to return a QSurfaceFormat containing the real values after + // create(), and that the adopted context got the correct pixel format from + // window and was able to update its format accordingly. + QCOMPARE(adopted->format().version(), ctx->format().version()); + QCOMPARE(adopted->format().profile(), ctx->format().profile()); + QVERIFY(ctx->format().redBufferSize() > 0); + QCOMPARE(adopted->format().redBufferSize(), ctx->format().redBufferSize()); + QVERIFY(ctx->format().greenBufferSize() > 0); + QCOMPARE(adopted->format().greenBufferSize(), ctx->format().greenBufferSize()); + QVERIFY(ctx->format().blueBufferSize() > 0); + QCOMPARE(adopted->format().blueBufferSize(), ctx->format().blueBufferSize()); + QVERIFY(ctx->format().depthBufferSize() > 0); + QCOMPARE(adopted->format().depthBufferSize(), ctx->format().depthBufferSize()); + QVERIFY(ctx->format().stencilBufferSize() > 0); + QCOMPARE(adopted->format().stencilBufferSize(), ctx->format().stencilBufferSize()); + + // This must work since we are using the exact same window. + QVERIFY(adopted->makeCurrent(window.data())); + adopted->doneCurrent(); +} +#endif // Q_OS_WIN32 && !QT_OPENGL_ES_2 + void tst_QOpenGL::vaoCreate() { QScopedPointer surface(createSurface(QSurface::Window)); -- cgit v1.2.3