diff options
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qgl/tst_qgl.cpp | 86 |
1 files changed, 47 insertions, 39 deletions
diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp index 1bf7850..2773d08 100644 --- a/tests/auto/qgl/tst_qgl.cpp +++ b/tests/auto/qgl/tst_qgl.cpp @@ -978,6 +978,47 @@ void tst_QGL::glWidgetWithAlpha() delete w; } + +bool qt_opengl_draw_test_pattern(QPainter* painter, int width, int height) +{ + QPainterPath intersectingPath; + intersectingPath.moveTo(0, 0); + intersectingPath.lineTo(100, 0); + intersectingPath.lineTo(0, 100); + intersectingPath.lineTo(100, 100); + intersectingPath.closeSubpath(); + + QPainterPath trianglePath; + trianglePath.moveTo(50, 0); + trianglePath.lineTo(100, 100); + trianglePath.lineTo(0, 100); + trianglePath.closeSubpath(); + + painter->setTransform(QTransform()); // reset xform + painter->fillRect(-1, -1, width+2, height+2, Qt::red); // Background + painter->translate(14, 14); + painter->fillPath(intersectingPath, Qt::blue); // Test stencil buffer works + painter->translate(128, 0); + painter->setClipPath(trianglePath); // Test depth buffer works + painter->setTransform(QTransform()); // reset xform ready for fill + painter->fillRect(-1, -1, width+2, height+2, Qt::green); +} + +void qt_opengl_check_test_pattern(const QImage& img) +{ + // As we're doing more than trivial painting, we can't just compare to + // an image rendered with raster. Instead, we sample at well-defined + // test-points: + QFUZZY_COMPARE_PIXELS(img.pixel(39, 64), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(img.pixel(89, 64), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(img.pixel(64, 39), QColor(Qt::blue).rgb()); + QFUZZY_COMPARE_PIXELS(img.pixel(64, 89), QColor(Qt::blue).rgb()); + + QFUZZY_COMPARE_PIXELS(img.pixel(167, 39), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(img.pixel(217, 39), QColor(Qt::red).rgb()); + QFUZZY_COMPARE_PIXELS(img.pixel(192, 64), QColor(Qt::green).rgb()); +} + class GLWidget : public QGLWidget { public: @@ -992,9 +1033,7 @@ public: QPaintEngine* pe = p.paintEngine(); engineType = pe->type(); - // This test only ensures it's possible to paint onto a QGLWidget. Full - // paint engine feature testing is way out of scope! - p.fillRect(-1, -1, width()+2, height()+2, Qt::red); + qt_opengl_draw_test_pattern(&p, width(), height()); // No p.end() or swap buffers, should be done automatically } @@ -1007,7 +1046,7 @@ void tst_QGL::glWidgetRendering() #ifdef Q_WS_QWS w.setWindowFlags(Qt::FramelessWindowHint); #endif - w.setGeometry(100, 100, 200, 200); + w.resize(256, 128); w.show(); #ifdef Q_WS_X11 @@ -1018,11 +1057,8 @@ void tst_QGL::glWidgetRendering() QVERIFY(w.beginOk); QVERIFY(w.engineType == QPaintEngine::OpenGL || w.engineType == QPaintEngine::OpenGL2); - QImage fb = w.grabFrameBuffer(false).convertToFormat(QImage::Format_RGB32); - QImage reference(fb.size(), QImage::Format_RGB32); - reference.fill(0xffff0000); - - QFUZZY_COMPARE_IMAGES(fb, reference); + QImage fb = w.grabFrameBuffer(false); + qt_opengl_check_test_pattern(fb); } void tst_QGL::glFBOSimpleRendering() @@ -1079,42 +1115,14 @@ void tst_QGL::glFBORendering() bool painterBegun = fboPainter.begin(fbo); QVERIFY(painterBegun); - QPainterPath intersectingPath; - intersectingPath.moveTo(0, 0); - intersectingPath.lineTo(100, 0); - intersectingPath.lineTo(0, 100); - intersectingPath.lineTo(100, 100); - intersectingPath.closeSubpath(); - - QPainterPath trianglePath; - trianglePath.moveTo(50, 0); - trianglePath.lineTo(100, 100); - trianglePath.lineTo(0, 100); - trianglePath.closeSubpath(); + qt_opengl_draw_test_pattern(&fboPainter, fbo->width(), fbo->height()); - fboPainter.fillRect(0, 0, fbo->width(), fbo->height(), Qt::red); // Background - fboPainter.translate(14, 14); - fboPainter.fillPath(intersectingPath, Qt::blue); // Test stencil buffer works - fboPainter.translate(128, 0); - fboPainter.setClipPath(trianglePath); // Test depth buffer works - fboPainter.setTransform(QTransform()); // reset xform - fboPainter.fillRect(0, 0, fbo->width(), fbo->height(), Qt::green); fboPainter.end(); QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32); delete fbo; - // As we're doing more than trivial painting, we can't just compare to - // an image rendered with raster. Instead, we sample at well-defined - // test-points: - QFUZZY_COMPARE_PIXELS(fb.pixel(39, 64), QColor(Qt::red).rgb()); - QFUZZY_COMPARE_PIXELS(fb.pixel(89, 64), QColor(Qt::red).rgb()); - QFUZZY_COMPARE_PIXELS(fb.pixel(64, 39), QColor(Qt::blue).rgb()); - QFUZZY_COMPARE_PIXELS(fb.pixel(64, 89), QColor(Qt::blue).rgb()); - - QFUZZY_COMPARE_PIXELS(fb.pixel(167, 39), QColor(Qt::red).rgb()); - QFUZZY_COMPARE_PIXELS(fb.pixel(217, 39), QColor(Qt::red).rgb()); - QFUZZY_COMPARE_PIXELS(fb.pixel(192, 64), QColor(Qt::green).rgb()); + qt_opengl_check_test_pattern(fb); } |