summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJørgen Lind <jorgen.lind@digia.com>2014-02-13 22:13:02 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-16 11:06:00 +0100
commit6fbef080a07f5b9b5a3bda985fd020a0bf064973 (patch)
tree3b11ce22016993e59b0da79a7d96a9b376c1706e /tests
parent579526cfec082679241548a0fca1ff9ba2c350a7 (diff)
QOpenGLTextureBlitter: add some autotests
Change-Id: I07a4847a19908c1a6d7fb02649b306dfa0148f49 Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/qopengl/tst_qopengl.cpp191
1 files changed, 191 insertions, 0 deletions
diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp
index e39380a095..975c2acefd 100644
--- a/tests/auto/gui/qopengl/tst_qopengl.cpp
+++ b/tests/auto/gui/qopengl/tst_qopengl.cpp
@@ -48,6 +48,10 @@
#include <QtGui/QScreen>
#include <QtGui/QWindow>
#include <QtGui/QOffscreenSurface>
+#include <QtGui/QGenericMatrix>
+#include <QtGui/QMatrix4x4>
+#include <QtGui/private/qopengltextureblitter_p.h>
+
#include <QtTest/QtTest>
@@ -75,6 +79,11 @@ private slots:
void openGLPaintDevice();
void aboutToBeDestroyed();
void QTBUG15621_triangulatingStrokerDivZero();
+ void textureblitterFullSourceRectTransform();
+ void textureblitterPartOriginBottomLeftSourceRectTransform();
+ void textureblitterPartOriginTopLeftSourceRectTransform();
+ void textureblitterFullTargetRectTransform();
+ void textureblitterPartTargetRectTransform();
};
struct SharedResourceTracker
@@ -708,6 +717,188 @@ void tst_QOpenGL::QTBUG15621_triangulatingStrokerDivZero()
QCOMPARE(image.pixel(95, 95), blue);
}
+typedef QGenericMatrix<1, 3, float> TestVertex3D;
+static const float uv_top_left[] = {0.f, 1.f, 1.f};
+static const float uv_bottom_left[] = {0.f, 0.f, 1.f};
+static const float uv_top_right[] = {1.f, 1.f, 1.f};
+static const float uv_bottom_right[] = {1.f, 0.f, 1.f};
+
+bool q_fuzzy_compare(const TestVertex3D &left, const TestVertex3D &right) {
+ return qFuzzyCompare(left(0,0), right(0,0)) &&
+ qFuzzyCompare(left(1,0), right(1,0)) &&
+ qFuzzyCompare(left(2,0), right(2,0));
+}
+
+void tst_QOpenGL::textureblitterFullSourceRectTransform()
+{
+ TestVertex3D topLeft(uv_top_left);
+ TestVertex3D bottomLeft(uv_bottom_left);
+ TestVertex3D topRight(uv_top_right);
+ TestVertex3D bottomRight(uv_bottom_right);
+
+ QRectF rect(0,0,1,1);
+ QMatrix3x3 flippedMatrix = QOpenGLTextureBlitter::sourceTransform(rect, rect.size().toSize(), QOpenGLTextureBlitter::OriginTopLeft);
+
+ TestVertex3D flippedTopLeft = flippedMatrix * topLeft;
+ QCOMPARE(flippedTopLeft, bottomLeft);
+
+ TestVertex3D flippedBottomLeft = flippedMatrix * bottomLeft;
+ QCOMPARE(flippedBottomLeft, topLeft);
+
+ TestVertex3D flippedTopRight = flippedMatrix * topRight;
+ QCOMPARE(flippedTopRight, bottomRight);
+
+ TestVertex3D flippedBottomRight = flippedMatrix * bottomRight;
+ QCOMPARE(flippedBottomRight, topRight);
+
+ QMatrix3x3 identityMatrix = QOpenGLTextureBlitter::sourceTransform(rect, rect.size().toSize(), QOpenGLTextureBlitter::OriginBottomLeft);
+
+ TestVertex3D notFlippedTopLeft = identityMatrix * topLeft;
+ QCOMPARE(notFlippedTopLeft, topLeft);
+
+ TestVertex3D notFlippedBottomLeft = identityMatrix * bottomLeft;
+ QCOMPARE(notFlippedBottomLeft, bottomLeft);
+
+ TestVertex3D notFlippedTopRight = identityMatrix * topRight;
+ QCOMPARE(notFlippedTopRight, topRight);
+
+ TestVertex3D notFlippedBottomRight = identityMatrix * bottomRight;
+ QCOMPARE(notFlippedBottomRight, bottomRight);
+}
+
+void tst_QOpenGL::textureblitterPartOriginBottomLeftSourceRectTransform()
+{
+ TestVertex3D topLeft(uv_top_left);
+ TestVertex3D bottomLeft(uv_bottom_left);
+ TestVertex3D topRight(uv_top_right);
+ TestVertex3D bottomRight(uv_bottom_right);
+
+ QRectF sourceRect(50,200,200,200);
+ QSize textureSize(400,400);
+
+ QMatrix3x3 sourceMatrix = QOpenGLTextureBlitter::sourceTransform(sourceRect, textureSize, QOpenGLTextureBlitter::OriginBottomLeft);
+
+ const float x_point_ratio = sourceRect.topLeft().x() / textureSize.width();
+ const float y_point_ratio = sourceRect.topLeft().y() / textureSize.height();
+ const float width_ratio = sourceRect.width() / textureSize.width();
+ const float height_ratio = sourceRect.height() / textureSize.height();
+
+ TestVertex3D uvTopLeft = sourceMatrix * topLeft;
+ const float expected_top_left[] = { x_point_ratio, y_point_ratio + height_ratio, 1 };
+ TestVertex3D expectedTopLeft(expected_top_left);
+ QCOMPARE(uvTopLeft, expectedTopLeft);
+
+ TestVertex3D uvBottomLeft = sourceMatrix * bottomLeft;
+ const float expected_bottom_left[] = { x_point_ratio, y_point_ratio, 1 };
+ TestVertex3D expectedBottomLeft(expected_bottom_left);
+ QCOMPARE(uvBottomLeft, expectedBottomLeft);
+
+ TestVertex3D uvTopRight = sourceMatrix * topRight;
+ const float expected_top_right[] = { x_point_ratio + width_ratio, y_point_ratio + height_ratio, 1 };
+ TestVertex3D expectedTopRight(expected_top_right);
+ QCOMPARE(uvTopRight, expectedTopRight);
+
+ TestVertex3D uvBottomRight = sourceMatrix * bottomRight;
+ const float expected_bottom_right[] = { x_point_ratio + width_ratio, y_point_ratio, 1 };
+ TestVertex3D expectedBottomRight(expected_bottom_right);
+ QCOMPARE(uvBottomRight, expectedBottomRight);
+}
+
+void tst_QOpenGL::textureblitterPartOriginTopLeftSourceRectTransform()
+{
+ TestVertex3D topLeft(uv_top_left);
+ TestVertex3D bottomLeft(uv_bottom_left);
+ TestVertex3D topRight(uv_top_right);
+ TestVertex3D bottomRight(uv_bottom_right);
+
+ QRectF sourceRect(50,190,170,170);
+ QSize textureSize(400,400);
+
+ QMatrix3x3 sourceMatrix = QOpenGLTextureBlitter::sourceTransform(sourceRect, textureSize, QOpenGLTextureBlitter::OriginTopLeft);
+
+ const float x_point_ratio = sourceRect.topLeft().x() / textureSize.width();
+ const float y_point_ratio = sourceRect.topLeft().y() / textureSize.height();
+ const float width_ratio = sourceRect.width() / textureSize.width();
+ const float height_ratio = sourceRect.height() / textureSize.height();
+
+ TestVertex3D uvTopLeft = sourceMatrix * topLeft;
+ const float expected_top_left[] = { x_point_ratio, 1 - y_point_ratio - height_ratio, 1 };
+ TestVertex3D expectedTopLeft(expected_top_left);
+ QVERIFY(q_fuzzy_compare(uvTopLeft, expectedTopLeft));
+
+ TestVertex3D uvBottomLeft = sourceMatrix * bottomLeft;
+ const float expected_bottom_left[] = { x_point_ratio, 1 - y_point_ratio, 1 };
+ TestVertex3D expectedBottomLeft(expected_bottom_left);
+ QVERIFY(q_fuzzy_compare(uvBottomLeft, expectedBottomLeft));
+
+ TestVertex3D uvTopRight = sourceMatrix * topRight;
+ const float expected_top_right[] = { x_point_ratio + width_ratio, 1 - y_point_ratio - height_ratio, 1 };
+ TestVertex3D expectedTopRight(expected_top_right);
+ QVERIFY(q_fuzzy_compare(uvTopRight, expectedTopRight));
+
+ TestVertex3D uvBottomRight = sourceMatrix * bottomRight;
+ const float expected_bottom_right[] = { x_point_ratio + width_ratio, 1 - y_point_ratio, 1 };
+ TestVertex3D expectedBottomRight(expected_bottom_right);
+ QVERIFY(q_fuzzy_compare(uvBottomRight, expectedBottomRight));
+}
+
+void tst_QOpenGL::textureblitterFullTargetRectTransform()
+{
+ QVector4D topLeft(-1.f, 1.f, 0.f, 1.f);
+ QVector4D bottomLeft(-1.f, -1.f, 0.f, 1.f);
+ QVector4D topRight(1.f, 1.f, 0.f, 1.f);
+ QVector4D bottomRight(1.f, -1.f, 0.f, 1.f);
+
+ QRectF rect(0,0,200,200);
+ QMatrix4x4 targetMatrix = QOpenGLTextureBlitter::targetTransform(rect,rect.toRect());
+
+ QVector4D translatedTopLeft = targetMatrix * topLeft;
+ QCOMPARE(translatedTopLeft, topLeft);
+
+ QVector4D translatedBottomLeft = targetMatrix * bottomLeft;
+ QCOMPARE(translatedBottomLeft, bottomLeft);
+
+ QVector4D translatedTopRight = targetMatrix * topRight;
+ QCOMPARE(translatedTopRight, topRight);
+
+ QVector4D translatedBottomRight = targetMatrix * bottomRight;
+ QCOMPARE(translatedBottomRight, bottomRight);
+}
+
+void tst_QOpenGL::textureblitterPartTargetRectTransform()
+{
+ QVector4D topLeft(-1.f, 1.f, 0.f, 1.f);
+ QVector4D bottomLeft(-1.f, -1.f, 0.f, 1.f);
+ QVector4D topRight(1.f, 1.f, 0.f, 1.f);
+ QVector4D bottomRight(1.f, -1.f, 0.f, 1.f);
+
+ QRectF targetRect(50,50,200,200);
+ QRect viewport(0,0,400,400);
+
+ //multiply by 2 since coordinate system goes from -1 -> 1;
+ qreal x_point_ratio = (50. / 400.) * 2;
+ qreal y_point_ratio = (50. / 400.) * 2;
+ qreal width_ratio = (200. / 400.) * 2;
+ qreal height_ratio = (200. / 400.) * 2;
+
+ QMatrix4x4 targetMatrix = QOpenGLTextureBlitter::targetTransform(targetRect, viewport);
+
+ QVector4D targetTopLeft = targetMatrix * topLeft;
+ QVector4D expectedTopLeft(-1 + x_point_ratio, 1 - y_point_ratio, .0, 1.0);
+ QCOMPARE(targetTopLeft, expectedTopLeft);
+
+ QVector4D targetBottomLeft = targetMatrix * bottomLeft;
+ QVector4D expectedBottomLeft(-1 + x_point_ratio, 1 - y_point_ratio - height_ratio, 0.0, 1.0);
+ QCOMPARE(targetBottomLeft, expectedBottomLeft);
+
+ QVector4D targetTopRight = targetMatrix * topRight;
+ QVector4D expectedTopRight(-1 + x_point_ratio + width_ratio, 1 - y_point_ratio, 0.0, 1.0);
+ QCOMPARE(targetTopRight, expectedTopRight);
+
+ QVector4D targetBottomRight = targetMatrix * bottomRight;
+ QVector4D expectedBottomRight(-1 + x_point_ratio + width_ratio, 1 - y_point_ratio - height_ratio, 0.0, 1.0);
+ QCOMPARE(targetBottomRight, expectedBottomRight);
+}
QTEST_MAIN(tst_QOpenGL)