1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
7 ** This file is part of the Qt scene graph research project.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <QtCore/QString>
43 #include <QtTest/QtTest>
45 #include <QtQuick/qsggeometry.h>
47 class GeometryTest : public QObject
55 void testTexturedPoint2D();
56 void testCustomGeometry();
61 void GeometryTest::testPoint2D()
63 QSGGeometry geometry(QSGGeometry::defaultAttributes_Point2D(), 4, 0);
65 QCOMPARE(geometry.attributeCount(), 1);
66 QCOMPARE(geometry.sizeOfVertex(), (int) sizeof(float) * 2);
67 QCOMPARE(geometry.vertexCount(), 4);
68 QCOMPARE(geometry.indexCount(), 0);
69 QVERIFY(geometry.indexData() == 0);
71 QSGGeometry::updateRectGeometry(&geometry, QRectF(1, 2, 3, 4));
73 QSGGeometry::Point2D *pts = geometry.vertexDataAsPoint2D();
76 QCOMPARE(pts[0].x, (float) 1);
77 QCOMPARE(pts[0].y, (float) 2);
78 QCOMPARE(pts[3].x, (float) 4);
79 QCOMPARE(pts[3].y, (float) 6);
81 // Verify that resize gives me enough allocated data without crashing...
82 geometry.allocate(100, 100);
83 pts = geometry.vertexDataAsPoint2D();
84 quint16 *is = geometry.indexDataAsUShort();
85 for (int i=0; i<100; ++i) {
94 void GeometryTest::testTexturedPoint2D()
96 QSGGeometry geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4, 0);
98 QCOMPARE(geometry.attributeCount(), 2);
99 QCOMPARE(geometry.sizeOfVertex(), (int) sizeof(float) * 4);
100 QCOMPARE(geometry.vertexCount(), 4);
101 QCOMPARE(geometry.indexCount(), 0);
102 QVERIFY(geometry.indexData() == 0);
104 QSGGeometry::updateTexturedRectGeometry(&geometry, QRectF(1, 2, 3, 4), QRectF(5, 6, 7, 8));
106 QSGGeometry::TexturedPoint2D *pts = geometry.vertexDataAsTexturedPoint2D();
109 QCOMPARE(pts[0].x, (float) 1);
110 QCOMPARE(pts[0].y, (float) 2);
111 QCOMPARE(pts[0].tx, (float) 5);
112 QCOMPARE(pts[0].ty, (float) 6);
114 QCOMPARE(pts[3].x, (float) 4);
115 QCOMPARE(pts[3].y, (float) 6);
116 QCOMPARE(pts[3].tx, (float) 12);
117 QCOMPARE(pts[3].ty, (float) 14);
119 // Verify that resize gives me enough allocated data without crashing...
120 geometry.allocate(100, 100);
121 pts = geometry.vertexDataAsTexturedPoint2D();
122 quint16 *is = geometry.indexDataAsUShort();
123 for (int i=0; i<100; ++i) {
133 void GeometryTest::testCustomGeometry()
137 unsigned char r, g, b, a;
138 float v1, v2, v3, v4;
141 static QSGGeometry::Attribute attributes[] = {
143 { 1, 4, GL_UNSIGNED_BYTE },
146 static QSGGeometry::AttributeSet set = { 4, 6 * sizeof(float) + 4 * sizeof(unsigned char), attributes };
148 QSGGeometry geometry(set, 1000, 4000);
150 // Verify that space has been allocated.
151 quint16 *ii = geometry.indexDataAsUShort();
152 for (int i=0; i<geometry.indexCount(); ++i) {
156 V *v = (V *) geometry.vertexData();
157 for (int i=0; i<geometry.vertexCount(); ++i) {
170 // Verify the data's integrity
171 for (int i=0; i<4000; ++i)
172 QCOMPARE(ii[i], (quint16) i);
173 for (int i=0; i<1000; ++i)
174 QVERIFY(v[i].v1 == 6);
179 QTEST_MAIN(GeometryTest);
181 #include "tst_geometry.moc"