summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Cooksey <thomas.cooksey@nokia.com>2009-09-01 16:55:05 (GMT)
committerTom Cooksey <thomas.cooksey@nokia.com>2009-09-01 17:13:42 (GMT)
commitd21fc5446c7583e153c1d566aefd7186f9c445cd (patch)
tree5879ff037e7c0bcfa5bc11e1dc7353a68b37ac58
parent400d72d5c4b1556ddcc188d82a24d5439f728bbe (diff)
downloadQt-d21fc5446c7583e153c1d566aefd7186f9c445cd.zip
Qt-d21fc5446c7583e153c1d566aefd7186f9c445cd.tar.gz
Qt-d21fc5446c7583e153c1d566aefd7186f9c445cd.tar.bz2
Autotest which checks you can paint to an fbo in a gl widget's p.e.
The test mimics examples/opengl/framebufferobjects in that it begins a QPainter on a QGLWidget in it's paint event, then begins a second QPainter on a QGLFramebufferObject, leaving 2 painters active at the same time. When the FBO's painter is ended, GL rendering should be re-targetted at the QGLWidget automatically.
-rw-r--r--tests/auto/qgl/tst_qgl.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp
index 1629542..f979174 100644
--- a/tests/auto/qgl/tst_qgl.cpp
+++ b/tests/auto/qgl/tst_qgl.cpp
@@ -73,6 +73,7 @@ private slots:
void partialGLWidgetUpdates();
void glWidgetRendering();
void glFBORendering();
+ void glFBOUseInGLWidget();
void glPBufferRendering();
void glWidgetReparent();
void colormap();
@@ -769,6 +770,60 @@ void tst_QGL::glFBORendering()
QCOMPARE(fb.pixel(192, 64), QColor(Qt::green).rgb());
}
+class FBOUseInGLWidget : public QGLWidget
+{
+public:
+ bool widgetPainterBeginOk;
+ bool fboPainterBeginOk;
+ QImage fboImage;
+protected:
+ void paintEvent(QPaintEvent*)
+ {
+ QPainter widgetPainter;
+ widgetPainterBeginOk = widgetPainter.begin(this);
+ QGLFramebufferObjectFormat fboFormat(0, QGLFramebufferObject::CombinedDepthStencil);
+ QGLFramebufferObject *fbo = new QGLFramebufferObject(128, 128, fboFormat);
+
+ QPainter fboPainter;
+ fboPainterBeginOk = fboPainter.begin(fbo);
+ fboPainter.fillRect(0, 0, 128, 128, Qt::red);
+ fboPainter.end();
+ fboImage = fbo->toImage();
+
+ widgetPainter.fillRect(rect(), Qt::blue);
+
+ delete fbo;
+ }
+
+};
+
+void tst_QGL::glFBOUseInGLWidget()
+{
+ if (!QGLFramebufferObject::hasOpenGLFramebufferObjects())
+ QSKIP("QGLFramebufferObject not supported on this platform", SkipSingle);
+
+ FBOUseInGLWidget w;
+ w.resize(128, 128);
+ w.show();
+
+#ifdef Q_WS_X11
+ qt_x11_wait_for_window_manager(&w);
+#endif
+ QTest::qWait(200);
+
+ QVERIFY(w.widgetPainterBeginOk);
+ QVERIFY(w.fboPainterBeginOk);
+
+ QImage widgetFB = w.grabFrameBuffer(false);
+ QImage widgetReference(widgetFB.size(), widgetFB.format());
+ widgetReference.fill(0xff0000ff);
+ QCOMPARE(widgetFB, widgetReference);
+
+ QImage fboReference(w.fboImage.size(), w.fboImage.format());
+ fboReference.fill(0xffff0000);
+ QCOMPARE(w.fboImage, fboReference);
+}
+
void tst_QGL::glWidgetReparent()
{
// Try it as a top-level first: