diff options
Diffstat (limited to 'tests/auto/gui/qopengl/tst_qopengl.cpp')
-rw-r--r-- | tests/auto/gui/qopengl/tst_qopengl.cpp | 90 |
1 files changed, 82 insertions, 8 deletions
diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 63fe8b9693..7de1989ada 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -43,6 +43,7 @@ #include <QtGui/private/qopenglcontext_p.h> #include <QtGui/QOpenGLFramebufferObject> #include <QtGui/QOpenGLFunctions> +#include <QtGui/QOpenGLVertexArrayObject> #include <QtGui/QOpenGLPaintDevice> #include <QtGui/QPainter> #include <QtGui/QScreen> @@ -51,12 +52,19 @@ #include <QtGui/QGenericMatrix> #include <QtGui/QMatrix4x4> #include <QtGui/private/qopengltextureblitter_p.h> - +#include <QtGui/private/qguiapplication_p.h> +#include <qpa/qplatformintegration.h> +#include <qpa/qplatformnativeinterface.h> #include <QtTest/QtTest> #include <QSignalSpy> +#ifdef USE_GLX +// Must be included last due to the X11 types +#include <QtPlatformHeaders/QGLXNativeContext> +#endif + class tst_QOpenGL : public QObject { Q_OBJECT @@ -85,6 +93,12 @@ private slots: void textureblitterPartOriginTopLeftSourceRectTransform(); void textureblitterFullTargetRectTransform(); void textureblitterPartTargetRectTransform(); + +#ifdef USE_GLX + void glxContextWrap(); +#endif + + void vaoCreate(); }; struct SharedResourceTracker @@ -448,9 +462,9 @@ void tst_QOpenGL::fboSimpleRendering() QVERIFY(fbo->bind()); - glClearColor(1.0, 0.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - glFinish(); + ctx.functions()->glClearColor(1.0, 0.0, 0.0, 1.0); + ctx.functions()->glClear(GL_COLOR_BUFFER_BIT); + ctx.functions()->glFinish(); const QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32); QCOMPARE(fb.size(), size); @@ -494,9 +508,9 @@ void tst_QOpenGL::fboTextureOwnership() fbo->bind(); QVERIFY(fbo->texture() != 0 && fbo->texture() != texture); - glClearColor(1.0, 0.0, 0.0, 1.0); - glClear(GL_COLOR_BUFFER_BIT); - glFinish(); + ctx.functions()->glClearColor(1.0, 0.0, 0.0, 1.0); + ctx.functions()->glClear(GL_COLOR_BUFFER_BIT); + ctx.functions()->glFinish(); QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32); QImage reference(fb.size(), QImage::Format_RGB32); @@ -504,7 +518,7 @@ void tst_QOpenGL::fboTextureOwnership() QFUZZY_COMPARE_IMAGES(fb, reference); - glDeleteTextures(1, &texture); + ctx.functions()->glDeleteTextures(1, &texture); delete fbo; } @@ -970,6 +984,66 @@ void tst_QOpenGL::textureblitterPartTargetRectTransform() QCOMPARE(targetBottomRight, expectedBottomRight); } +#ifdef USE_GLX +void tst_QOpenGL::glxContextWrap() +{ + QWindow *window = new QWindow; + window->setSurfaceType(QWindow::OpenGLSurface); + window->setGeometry(0, 0, 10, 10); + window->show(); + QTest::qWaitForWindowExposed(window); + + QPlatformNativeInterface *nativeIf = QGuiApplicationPrivate::instance()->platformIntegration()->nativeInterface(); + QVERIFY(nativeIf); + + // Fetch a GLXContext. + QOpenGLContext *ctx0 = new QOpenGLContext; + ctx0->setFormat(window->format()); + QVERIFY(ctx0->create()); + QVariant v = ctx0->nativeHandle(); + QVERIFY(!v.isNull()); + QVERIFY(v.canConvert<QGLXNativeContext>()); + GLXContext context = v.value<QGLXNativeContext>().context(); + QVERIFY(context); + + // Then create another QOpenGLContext wrapping it. + QOpenGLContext *ctx = new QOpenGLContext; + ctx->setNativeHandle(QVariant::fromValue<QGLXNativeContext>(QGLXNativeContext(context))); + QVERIFY(ctx->create()); + QVERIFY(ctx->nativeHandle().value<QGLXNativeContext>().context() == context); + QVERIFY(nativeIf->nativeResourceForContext(QByteArrayLiteral("glxcontext"), ctx) == (void *) context); + + QVERIFY(ctx->makeCurrent(window)); + ctx->doneCurrent(); + + delete ctx; + delete ctx0; + + delete window; +} +#endif // USE_GLX + +void tst_QOpenGL::vaoCreate() +{ + QScopedPointer<QSurface> surface(createSurface(QSurface::Window)); + QOpenGLContext *ctx = new QOpenGLContext; + ctx->create(); + ctx->makeCurrent(surface.data()); + + QOpenGLVertexArrayObject vao; + bool success = vao.create(); + if (ctx->isOpenGLES()) { + if (ctx->format().majorVersion() >= 3 || ctx->hasExtension(QByteArrayLiteral("GL_OES_vertex_array_object"))) + QVERIFY(success); + } else { + if (ctx->format().majorVersion() >= 3 || ctx->hasExtension(QByteArrayLiteral("GL_ARB_vertex_array_object"))) + QVERIFY(success); + } + + vao.destroy(); + ctx->doneCurrent(); +} + QTEST_MAIN(tst_QOpenGL) #include "tst_qopengl.moc" |