diff options
author | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-06-23 16:45:11 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-07-07 12:55:16 +0200 |
commit | e7056a8969cf9445ff84c7362137f792ef207ae2 (patch) | |
tree | f1e5ced5d3d22cd5db9376cd01f362d2b3dad87c /tests/auto/gui/qopengl/tst_qopengl.cpp | |
parent | d8103d0e629f1d8f6c2b9d5b0dcc95b6ff20b99d (diff) |
Add context adoption support for WGL
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 <jorgen.lind@digia.com>
Diffstat (limited to 'tests/auto/gui/qopengl/tst_qopengl.cpp')
-rw-r--r-- | tests/auto/gui/qopengl/tst_qopengl.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
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 <QtPlatformHeaders/QGLXNativeContext> #endif +#if defined(Q_OS_WIN32) && !defined(QT_OPENGL_ES_2) +#include <QtPlatformHeaders/QWGLNativeContext> +#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<QOpenGLContext> ctx(new QOpenGLContext); + QVERIFY(ctx->create()); + if (ctx->isOpenGLES()) + QSKIP("Not applicable to EGL"); + + QScopedPointer<QWindow> 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>()); + QWGLNativeContext nativeContext = v.value<QWGLNativeContext>(); + 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<QOpenGLContext> adopted(new QOpenGLContext); + adopted->setNativeHandle(QVariant::fromValue<QWGLNativeContext>(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<QSurface> surface(createSurface(QSurface::Window)); |