diff options
author | Tom Cooksey <thomas.cooksey@nokia.com> | 2009-09-01 07:43:09 (GMT) |
---|---|---|
committer | Tom Cooksey <thomas.cooksey@nokia.com> | 2009-09-01 14:59:44 (GMT) |
commit | 8e2213ea0bb3692783c03fe4da2df659c1859136 (patch) | |
tree | 1b444d60a31805ae4e46d5f927f90490586a6231 | |
parent | 2a521d8d26577bfe0487a48c0d723e14e67ee0b5 (diff) | |
download | Qt-8e2213ea0bb3692783c03fe4da2df659c1859136.zip Qt-8e2213ea0bb3692783c03fe4da2df659c1859136.tar.gz Qt-8e2213ea0bb3692783c03fe4da2df659c1859136.tar.bz2 |
An an autotest to check QPainter rendering to an FBO works
The test also checks that when we ask for CombinedDepthStencil, that's
what we get.
Reviewed-by: Samuel
-rw-r--r-- | tests/auto/qgl/tst_qgl.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp index 073afc8..1629542 100644 --- a/tests/auto/qgl/tst_qgl.cpp +++ b/tests/auto/qgl/tst_qgl.cpp @@ -46,6 +46,7 @@ #include <qdebug.h> #include <qgl.h> #include <qglpixelbuffer.h> +#include <qglframebufferobject.h> #include <qglcolormap.h> #include <qpaintengine.h> @@ -71,6 +72,7 @@ private slots: void partialGLWidgetUpdates_data(); void partialGLWidgetUpdates(); void glWidgetRendering(); + void glFBORendering(); void glPBufferRendering(); void glWidgetReparent(); void colormap(); @@ -706,6 +708,67 @@ void tst_QGL::glWidgetRendering() QCOMPARE(fb, reference); } +// NOTE: This tests that CombinedDepthStencil attachment works by assuming the +// GL2 engine is being used and is implemented the same way as it was when +// this autotest was written. If this is not the case, there may be some +// false-positives: I.e. The test passes when either the depth or stencil +// buffer is actually missing. But that's probably ok anyway. +void tst_QGL::glFBORendering() +{ + if (!QGLFramebufferObject::hasOpenGLFramebufferObjects()) + QSKIP("QGLFramebufferObject not supported on this platform", SkipSingle); + + QGLWidget glw; + glw.makeCurrent(); + + // No multisample with combined depth/stencil attachment: + QGLFramebufferObjectFormat fboFormat(0, QGLFramebufferObject::CombinedDepthStencil); + + // Don't complicate things by using NPOT: + QGLFramebufferObject *fbo = new QGLFramebufferObject(256, 128, fboFormat); + + QPainter fboPainter; + 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(); + + 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: + QCOMPARE(fb.pixel(39, 64), QColor(Qt::red).rgb()); + QCOMPARE(fb.pixel(89, 64), QColor(Qt::red).rgb()); + QCOMPARE(fb.pixel(64, 39), QColor(Qt::blue).rgb()); + QCOMPARE(fb.pixel(64, 89), QColor(Qt::blue).rgb()); + + QCOMPARE(fb.pixel(167, 39), QColor(Qt::red).rgb()); + QCOMPARE(fb.pixel(217, 39), QColor(Qt::red).rgb()); + QCOMPARE(fb.pixel(192, 64), QColor(Qt::green).rgb()); +} + void tst_QGL::glWidgetReparent() { // Try it as a top-level first: |