summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/gui/qopengl/tst_qopengl.cpp72
-rw-r--r--tests/auto/opengl/qgl/tst_qgl.cpp4
-rw-r--r--tests/auto/other/lancelot/paintcommands.cpp2
-rw-r--r--tests/auto/other/lancelot/tst_lancelot.cpp53
4 files changed, 120 insertions, 11 deletions
diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp
index 44921f68aa..7451ef92ee 100644
--- a/tests/auto/gui/qopengl/tst_qopengl.cpp
+++ b/tests/auto/gui/qopengl/tst_qopengl.cpp
@@ -86,6 +86,7 @@ private slots:
void fboMRT_differentFormats();
void openGLPaintDevice_data();
void openGLPaintDevice();
+ void openGLPaintDeviceWithChangingContext();
void aboutToBeDestroyed();
void sizeLessWindow();
void QTBUG15621_triangulatingStrokerDivZero();
@@ -948,6 +949,14 @@ void tst_QOpenGL::openGLPaintDevice_data()
QTest::newRow("Using QOffscreenSurface - RGB16") << int(QSurface::Offscreen) << QImage::Format_RGB16;
}
+static void drawColoredRects(QPainter *p, const QSize &size)
+{
+ p->fillRect(0, 0, size.width() / 2, size.height() / 2, Qt::red);
+ p->fillRect(size.width() / 2, 0, size.width() / 2, size.height() / 2, Qt::green);
+ p->fillRect(size.width() / 2, size.height() / 2, size.width() / 2, size.height() / 2, Qt::blue);
+ p->fillRect(0, size.height() / 2, size.width() / 2, size.height() / 2, Qt::white);
+}
+
void tst_QOpenGL::openGLPaintDevice()
{
#if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(__x86_64__)
@@ -970,10 +979,7 @@ void tst_QOpenGL::openGLPaintDevice()
QImage image(size, imageFormat);
QPainter p(&image);
- p.fillRect(0, 0, image.width() / 2, image.height() / 2, Qt::red);
- p.fillRect(image.width() / 2, 0, image.width() / 2, image.height() / 2, Qt::green);
- p.fillRect(image.width() / 2, image.height() / 2, image.width() / 2, image.height() / 2, Qt::blue);
- p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white);
+ drawColoredRects(&p, image.size());
p.end();
QOpenGLFramebufferObject fbo(size);
@@ -981,10 +987,7 @@ void tst_QOpenGL::openGLPaintDevice()
QOpenGLPaintDevice device(size);
QVERIFY(p.begin(&device));
- p.fillRect(0, 0, image.width() / 2, image.height() / 2, Qt::red);
- p.fillRect(image.width() / 2, 0, image.width() / 2, image.height() / 2, Qt::green);
- p.fillRect(image.width() / 2, image.height() / 2, image.width() / 2, image.height() / 2, Qt::blue);
- p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white);
+ drawColoredRects(&p, image.size());
p.end();
QImage actual = fbo.toImage().convertToFormat(imageFormat);
@@ -1010,6 +1013,59 @@ void tst_QOpenGL::openGLPaintDevice()
QCOMPARE(image, actual);
}
+void tst_QOpenGL::openGLPaintDeviceWithChangingContext()
+{
+ QScopedPointer<QSurface> surface(createSurface(QSurface::Window));
+ const QSize size(512, 512);
+
+ // QOpenGLPaintDevice has a thread-local paint engine. Therefore render
+ // twice, with a different context and device. Under the hood it will
+ // still use the same paint engine!
+
+ QOpenGLContext ctx;
+ QVERIFY(ctx.create());
+ QVERIFY(ctx.makeCurrent(surface.data()));
+
+ QOpenGLFramebufferObject fbo(size);
+ QVERIFY(fbo.bind());
+
+ QOpenGLPaintDevice device(size);
+
+ QPainter p;
+ QVERIFY(p.begin(&device));
+ drawColoredRects(&p, size);
+ p.end();
+
+ QImage img1 = fbo.toImage();
+
+ QOpenGLContext ctx2;
+ // When supported, test the special case, where the second context is
+ // totally incompatible due to being a core profile one.
+ QSurfaceFormat coreFormat;
+ coreFormat.setVersion(3, 2);
+ coreFormat.setProfile(QSurfaceFormat::CoreProfile);
+ ctx2.setFormat(coreFormat);
+ if (!ctx2.create() || !ctx2.makeCurrent(surface.data())) {
+ ctx2.setFormat(QSurfaceFormat());
+ QVERIFY(ctx2.create());
+ }
+
+ QVERIFY(ctx2.makeCurrent(surface.data()));
+
+ QOpenGLFramebufferObject fbo2(size);
+ QVERIFY(fbo2.bind());
+
+ QOpenGLPaintDevice device2(size);
+
+ QVERIFY(p.begin(&device2));
+ drawColoredRects(&p, size);
+ p.end();
+
+ QImage img2 = fbo2.toImage();
+
+ QFUZZY_COMPARE_IMAGES(img1, img2);
+}
+
void tst_QOpenGL::aboutToBeDestroyed()
{
QWindow window;
diff --git a/tests/auto/opengl/qgl/tst_qgl.cpp b/tests/auto/opengl/qgl/tst_qgl.cpp
index af0248b432..cf92c9fab6 100644
--- a/tests/auto/opengl/qgl/tst_qgl.cpp
+++ b/tests/auto/opengl/qgl/tst_qgl.cpp
@@ -1169,6 +1169,10 @@ void tst_QGL::currentFboSync()
QGLWidget glw;
glw.makeCurrent();
+ // For some reason we offer inter-operatibility between QGL and QOpenGL
+ // paint engines. (?!) Let's check if the two engines can be used to perform
+ // drawing in turns on different targets within the same context.
+
{
QGLFramebufferObject fbo1(256, 256, QGLFramebufferObject::CombinedDepthStencil);
diff --git a/tests/auto/other/lancelot/paintcommands.cpp b/tests/auto/other/lancelot/paintcommands.cpp
index 2e6cb09aa5..971b9b5fe7 100644
--- a/tests/auto/other/lancelot/paintcommands.cpp
+++ b/tests/auto/other/lancelot/paintcommands.cpp
@@ -2378,6 +2378,8 @@ void PaintCommands::command_surface_begin(QRegExp re)
#ifndef QT_NO_OPENGL
m_default_glcontext = QOpenGLContext::currentContext();
m_surface_glcontext = new QOpenGLContext();
+ // Pick up the format from the current context; this is especially
+ // important in order to pick the right version/profile to test.
m_surface_glcontext->setFormat(m_default_glcontext->format());
m_surface_glcontext->create();
m_surface_glcontext->makeCurrent(m_default_glcontext->surface());
diff --git a/tests/auto/other/lancelot/tst_lancelot.cpp b/tests/auto/other/lancelot/tst_lancelot.cpp
index 972e5ca967..63c62bab86 100644
--- a/tests/auto/other/lancelot/tst_lancelot.cpp
+++ b/tests/auto/other/lancelot/tst_lancelot.cpp
@@ -53,7 +53,7 @@ private:
};
void setupTestSuite(const QStringList& blacklist = QStringList());
- void runTestSuite(GraphicsEngine engine, QImage::Format format);
+ void runTestSuite(GraphicsEngine engine, QImage::Format format, const QSurfaceFormat &contextFormat = QSurfaceFormat());
void paint(QPaintDevice *device, GraphicsEngine engine, const QStringList &script, const QString &filePath);
QStringList qpsFiles;
@@ -85,8 +85,11 @@ private slots:
#ifndef QT_NO_OPENGL
void testOpenGL_data();
void testOpenGL();
+ void testCoreOpenGL_data();
+ void testCoreOpenGL();
private:
bool checkSystemGLSupport();
+ bool checkSystemCoreGLSupport();
#endif
};
@@ -236,6 +239,32 @@ bool tst_Lancelot::checkSystemGLSupport()
return true;
}
+bool tst_Lancelot::checkSystemCoreGLSupport()
+{
+ if (QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGL)
+ return false;
+
+ QSurfaceFormat coreFormat;
+ coreFormat.setVersion(3, 2);
+ coreFormat.setProfile(QSurfaceFormat::CoreProfile);
+ QWindow win;
+ win.setSurfaceType(QSurface::OpenGLSurface);
+ win.setFormat(coreFormat);
+ win.create();
+ QOpenGLFramebufferObjectFormat fmt;
+ fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
+ fmt.setSamples(4);
+ QOpenGLContext ctx;
+ ctx.setFormat(coreFormat);
+ if (!ctx.create() || !ctx.makeCurrent(&win))
+ return false;
+ QOpenGLFramebufferObject fbo(800, 800, fmt);
+ if (!fbo.isValid() || !fbo.bind())
+ return false;
+
+ return true;
+}
+
void tst_Lancelot::testOpenGL_data()
{
if (!checkSystemGLSupport())
@@ -249,6 +278,22 @@ void tst_Lancelot::testOpenGL()
{
runTestSuite(OpenGL, QImage::Format_RGB32);
}
+
+void tst_Lancelot::testCoreOpenGL_data()
+{
+ if (!checkSystemCoreGLSupport())
+ QSKIP("System under test does not meet preconditions for Core Profile GL testing. Skipping.");
+ QStringList localBlacklist = QStringList() << QLatin1String("rasterops.qps");
+ setupTestSuite(localBlacklist);
+}
+
+void tst_Lancelot::testCoreOpenGL()
+{
+ QSurfaceFormat coreFormat;
+ coreFormat.setVersion(3, 2);
+ coreFormat.setProfile(QSurfaceFormat::CoreProfile);
+ runTestSuite(OpenGL, QImage::Format_RGB32, coreFormat);
+}
#endif
@@ -263,7 +308,7 @@ void tst_Lancelot::setupTestSuite(const QStringList& blacklist)
}
-void tst_Lancelot::runTestSuite(GraphicsEngine engine, QImage::Format format)
+void tst_Lancelot::runTestSuite(GraphicsEngine engine, QImage::Format format, const QSurfaceFormat &contextFormat)
{
QFETCH(QString, qpsFile);
@@ -279,11 +324,13 @@ void tst_Lancelot::runTestSuite(GraphicsEngine engine, QImage::Format format)
} else if (engine == OpenGL) {
QWindow win;
win.setSurfaceType(QSurface::OpenGLSurface);
+ win.setFormat(contextFormat);
win.create();
QOpenGLFramebufferObjectFormat fmt;
fmt.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
fmt.setSamples(4);
QOpenGLContext ctx;
+ ctx.setFormat(contextFormat);
QVERIFY(ctx.create());
QVERIFY(ctx.makeCurrent(&win));
QOpenGLFramebufferObject fbo(800, 800, fmt);
@@ -304,7 +351,7 @@ void tst_Lancelot::paint(QPaintDevice *device, GraphicsEngine engine, const QStr
//pcmd.setShouldDrawText(false);
switch (engine) {
case OpenGL:
- pcmd.setType(OpenGLBufferType);
+ pcmd.setType(OpenGLBufferType); // version/profile is communicated through the context's format()
break;
case Raster: // fallthrough
default: