diff options
author | Qt Continuous Integration System <qt-info@nokia.com> | 2010-02-01 17:47:40 (GMT) |
---|---|---|
committer | Qt Continuous Integration System <qt-info@nokia.com> | 2010-02-01 17:47:40 (GMT) |
commit | 364ecfa36d6d4dc0aa917a223e88869028d8219c (patch) | |
tree | 5bcb9a3504340c11213132897a4e59f6384704b9 /tests | |
parent | 5067683704580fcfedef4e68f19acedb133936e8 (diff) | |
parent | 3bc1dc6d3d609166af0532b9f75734aee232cded (diff) | |
download | Qt-364ecfa36d6d4dc0aa917a223e88869028d8219c.zip Qt-364ecfa36d6d4dc0aa917a223e88869028d8219c.tar.gz Qt-364ecfa36d6d4dc0aa917a223e88869028d8219c.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-2 into master-integration
* 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-2:
Placate pedantic compiler warning modes on QGLBuffer
Promote QPixmap::convertFromImage() to public API from Qt3Support
Add the QGLBuffer class to Qt 4.7 for VBO's
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/auto.pro | 2 | ||||
-rw-r--r-- | tests/auto/qglbuffer/qglbuffer.pro | 9 | ||||
-rw-r--r-- | tests/auto/qglbuffer/tst_qglbuffer.cpp | 261 |
3 files changed, 271 insertions, 1 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 3198a65..1abf9b7 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -462,7 +462,7 @@ SUBDIRS += \ rcc \ windowsmobile -contains(QT_CONFIG,opengl):SUBDIRS += qgl +contains(QT_CONFIG,opengl):SUBDIRS += qgl qglbuffer contains(QT_CONFIG,qt3support):!wince*:SUBDIRS += $$Q3SUBDIRS diff --git a/tests/auto/qglbuffer/qglbuffer.pro b/tests/auto/qglbuffer/qglbuffer.pro new file mode 100644 index 0000000..07d05bb --- /dev/null +++ b/tests/auto/qglbuffer/qglbuffer.pro @@ -0,0 +1,9 @@ +############################################################ +# Project file for autotest for file qglbuffer.h +############################################################ + +load(qttest_p4) +requires(contains(QT_CONFIG,opengl)) +QT += opengl + +SOURCES += tst_qglbuffer.cpp diff --git a/tests/auto/qglbuffer/tst_qglbuffer.cpp b/tests/auto/qglbuffer/tst_qglbuffer.cpp new file mode 100644 index 0000000..b7d5821 --- /dev/null +++ b/tests/auto/qglbuffer/tst_qglbuffer.cpp @@ -0,0 +1,261 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenGL module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QtOpenGL/qgl.h> +#include <QtOpenGL/qglbuffer.h> + +class tst_QGLBuffer : public QObject +{ + Q_OBJECT +public: + tst_QGLBuffer() {} + ~tst_QGLBuffer() {} + +private slots: + void vertexBuffer_data(); + void vertexBuffer(); + void indexBuffer_data(); + void indexBuffer(); + void bufferSharing(); + +private: + void testBuffer(QGLBuffer::Type type); +}; + +void tst_QGLBuffer::vertexBuffer_data() +{ + QTest::addColumn<int>("usagePattern"); + + QTest::newRow("StreamDraw") << int(QGLBuffer::StreamDraw); + QTest::newRow("StaticDraw") << int(QGLBuffer::StaticDraw); + QTest::newRow("DynamicDraw") << int(QGLBuffer::DynamicDraw); +} + +void tst_QGLBuffer::vertexBuffer() +{ + testBuffer(QGLBuffer::VertexBuffer); +} + +void tst_QGLBuffer::indexBuffer_data() +{ + vertexBuffer_data(); +} + +void tst_QGLBuffer::indexBuffer() +{ + testBuffer(QGLBuffer::IndexBuffer); +} + +void tst_QGLBuffer::testBuffer(QGLBuffer::Type type) +{ + QFETCH(int, usagePattern); + + QGLWidget w; + w.makeCurrent(); + + // Create the local object, but not the buffer in the server. + QGLBuffer buffer(type); + QVERIFY(buffer.usagePattern() == QGLBuffer::StaticDraw); + buffer.setUsagePattern(QGLBuffer::UsagePattern(usagePattern)); + + // Check the initial state. + QVERIFY(buffer.type() == type); + QVERIFY(!buffer.isCreated()); + QVERIFY(buffer.bufferId() == 0); + QVERIFY(buffer.usagePattern() == QGLBuffer::UsagePattern(usagePattern)); + QCOMPARE(buffer.size(), -1); + + // Should not be able to bind it yet because it isn't created. + QVERIFY(!buffer.bind()); + + // Create the buffer - if this fails, then assume that the + // GL implementation does not support buffers at all. + if (!buffer.create()) + QSKIP("Buffers are not supported on this platform", SkipAll); + + // Should now have a buffer id. + QVERIFY(buffer.bufferId() != 0); + + // Bind the buffer and upload some data. + QVERIFY(buffer.bind()); + static GLfloat const data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + buffer.allocate(data, sizeof(data)); + + // Check the buffer size. + QCOMPARE(buffer.size(), int(sizeof(data))); + + // Map the buffer and read back its contents. + bool haveMap = false; + GLfloat *mapped = reinterpret_cast<GLfloat *> + (buffer.map(QGLBuffer::ReadOnly)); + if (mapped) { + for (int index = 0; index < 9; ++index) + QCOMPARE(mapped[index], data[index]); + buffer.unmap(); + haveMap = true; + } else { + qWarning("QGLBuffer::map() is not supported on this platform"); + } + + // Read back the buffer contents using read(). + bool haveRead = false; + GLfloat readdata[9]; + if (buffer.read(0, readdata, sizeof(readdata))) { + for (int index = 0; index < 9; ++index) + QCOMPARE(readdata[index], data[index]); + haveRead = true; + } else { + qWarning("QGLBuffer::read() is not supported on this platform"); + } + + // Write some different data to a specific location and check it. + static GLfloat const diffdata[] = {11, 12, 13}; + buffer.write(sizeof(GLfloat) * 3, diffdata, sizeof(diffdata)); + if (haveMap) { + mapped = reinterpret_cast<GLfloat *>(buffer.map(QGLBuffer::ReadOnly)); + QVERIFY(mapped != 0); + for (int index = 0; index < 9; ++index) { + if (index >= 3 && index <= 5) + QCOMPARE(mapped[index], diffdata[index - 3]); + else + QCOMPARE(mapped[index], data[index]); + } + buffer.unmap(); + } + if (haveRead) { + QVERIFY(buffer.read(0, readdata, sizeof(readdata))); + for (int index = 0; index < 9; ++index) { + if (index >= 3 && index <= 5) + QCOMPARE(readdata[index], diffdata[index - 3]); + else + QCOMPARE(readdata[index], data[index]); + } + } + + // Write to the buffer using the return value from map. + if (haveMap) { + mapped = reinterpret_cast<GLfloat *>(buffer.map(QGLBuffer::WriteOnly)); + QVERIFY(mapped != 0); + mapped[6] = 14; + buffer.unmap(); + + mapped = reinterpret_cast<GLfloat *>(buffer.map(QGLBuffer::ReadOnly)); + QVERIFY(mapped != 0); + static GLfloat const diff2data[] = {11, 12, 13, 14}; + for (int index = 0; index < 9; ++index) { + if (index >= 3 && index <= 6) + QCOMPARE(mapped[index], diff2data[index - 3]); + else + QCOMPARE(mapped[index], data[index]); + } + buffer.unmap(); + } + + // Resize the buffer. + buffer.allocate(sizeof(GLfloat) * 20); + QCOMPARE(buffer.size(), int(sizeof(GLfloat) * 20)); + buffer.allocate(0, sizeof(GLfloat) * 32); + QCOMPARE(buffer.size(), int(sizeof(GLfloat) * 32)); + + // Release the buffer. + buffer.release(); +} + +void tst_QGLBuffer::bufferSharing() +{ + QGLWidget *w1 = new QGLWidget(); + w1->makeCurrent(); + + QGLWidget *w2 = new QGLWidget(0, w1); + if (!w2->isSharing()) { + delete w2; + delete w1; + QSKIP("Context sharing is not supported on this platform", SkipSingle); + } + + // Bind the buffer in the first context and write some data to it. + QGLBuffer buffer(QGLBuffer::VertexBuffer); + if (!buffer.create()) + QSKIP("Buffers are not supported on this platform", SkipSingle); + QVERIFY(buffer.isCreated()); + QVERIFY(buffer.bind()); + static GLfloat const data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; + buffer.allocate(data, sizeof(data)); + QCOMPARE(buffer.size(), int(sizeof(data))); + buffer.release(); + + // Bind the buffer in the second context and read back the data. + w2->makeCurrent(); + QVERIFY(buffer.bind()); + QCOMPARE(buffer.size(), int(sizeof(data))); + GLfloat readdata[9]; + if (buffer.read(0, readdata, sizeof(readdata))) { + for (int index = 0; index < 9; ++index) + QCOMPARE(readdata[index], data[index]); + } + buffer.release(); + + // Delete the first context. + delete w1; + + // Make the second context current again because deleting the first + // one will call doneCurrent() even though it wasn't current! + w2->makeCurrent(); + + // The buffer should still be valid in the second context. + QVERIFY(buffer.bufferId() != 0); + QVERIFY(buffer.isCreated()); + QVERIFY(buffer.bind()); + QCOMPARE(buffer.size(), int(sizeof(data))); + buffer.release(); + + // Delete the second context. + delete w2; + + // The buffer should now be invalid. + QVERIFY(buffer.bufferId() == 0); + QVERIFY(!buffer.isCreated()); +} + +QTEST_MAIN(tst_QGLBuffer) + +#include "tst_qglbuffer.moc" |