summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/qopengl/tst_qopengl.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@digia.com>2014-06-13 16:36:27 +0200
committerLaszlo Agocs <laszlo.agocs@digia.com>2014-08-08 07:29:53 +0200
commitbb760d9514ed617ee8e7344152b3fa697b2c4171 (patch)
treeff80c5cff36421c1c17bdc86f5349da6194aefa2 /tests/auto/gui/qopengl/tst_qopengl.cpp
parent22e439141384f49028770d2410fafb18ef8cad1f (diff)
Add support for glMapBufferRange in the wrappers and resolvers
QOpenGLBuffer::map() and related helpers are becoming useless in OpenGL ES 3.0 and up: instead of the old GL_OES_map_buffer, glMapBufferRange, but not glMapBuffer, is now part of the standard. On desktop GL_ARB_map_buffer_range is present by default in OpenGL 3.0 and newer. [ChangeLog][QtGui] Added QOpenGLBuffer::mapBufferRange(). Task-number: QTBUG-38168 Change-Id: I4e9bbe8ced9ee4d535ac32849a8c08c26d79cb49 Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
Diffstat (limited to 'tests/auto/gui/qopengl/tst_qopengl.cpp')
-rw-r--r--tests/auto/gui/qopengl/tst_qopengl.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp
index a5100a57bf..ed72ef8858 100644
--- a/tests/auto/gui/qopengl/tst_qopengl.cpp
+++ b/tests/auto/gui/qopengl/tst_qopengl.cpp
@@ -45,6 +45,7 @@
#include <QtGui/QOpenGLFunctions>
#include <QtGui/QOpenGLFunctions_4_2_Core>
#include <QtGui/QOpenGLVertexArrayObject>
+#include <QtGui/QOpenGLBuffer>
#include <QtGui/QOpenGLPaintDevice>
#include <QtGui/QPainter>
#include <QtGui/QScreen>
@@ -54,6 +55,7 @@
#include <QtGui/QMatrix4x4>
#include <QtGui/private/qopengltextureblitter_p.h>
#include <QtGui/private/qguiapplication_p.h>
+#include <QtGui/private/qopenglextensions_p.h>
#include <qpa/qplatformintegration.h>
#include <qpa/qplatformnativeinterface.h>
@@ -113,6 +115,8 @@ private slots:
#endif
void vaoCreate();
+ void bufferCreate();
+ void bufferMapRange();
};
struct SharedResourceTracker
@@ -1243,6 +1247,70 @@ void tst_QOpenGL::vaoCreate()
ctx->doneCurrent();
}
+void tst_QOpenGL::bufferCreate()
+{
+ QScopedPointer<QSurface> surface(createSurface(QSurface::Window));
+ QOpenGLContext *ctx = new QOpenGLContext;
+ ctx->create();
+ ctx->makeCurrent(surface.data());
+
+ QOpenGLBuffer buf;
+
+ QVERIFY(!buf.isCreated());
+
+ QVERIFY(buf.create());
+ QVERIFY(buf.isCreated());
+
+ QCOMPARE(buf.type(), QOpenGLBuffer::VertexBuffer);
+
+ buf.bind();
+ buf.allocate(128);
+ QCOMPARE(buf.size(), 128);
+
+ buf.release();
+
+ buf.destroy();
+ QVERIFY(!buf.isCreated());
+
+ ctx->doneCurrent();
+}
+
+void tst_QOpenGL::bufferMapRange()
+{
+ QScopedPointer<QSurface> surface(createSurface(QSurface::Window));
+ QOpenGLContext *ctx = new QOpenGLContext;
+ ctx->create();
+ ctx->makeCurrent(surface.data());
+
+ QOpenGLExtensions funcs(ctx);
+ if (!funcs.hasOpenGLExtension(QOpenGLExtensions::MapBufferRange))
+ QSKIP("glMapBufferRange not supported");
+
+ QOpenGLBuffer buf;
+ QVERIFY(buf.create());
+ buf.bind();
+ const char data[] = "some data";
+ buf.allocate(data, sizeof(data));
+
+ char *p = (char *) buf.mapRange(0, sizeof(data), QOpenGLBuffer::RangeRead | QOpenGLBuffer::RangeWrite);
+ QVERIFY(p);
+ QVERIFY(!strcmp(p, data));
+ p[1] = 'O';
+ buf.unmap();
+
+ p = (char *) buf.mapRange(1, 2, QOpenGLBuffer::RangeWrite);
+ QVERIFY(p);
+ p[1] = 'M';
+ buf.unmap();
+
+ p = (char *) buf.mapRange(0, sizeof(data), QOpenGLBuffer::RangeRead);
+ QVERIFY(!strcmp(p, "sOMe data"));
+ buf.unmap();
+
+ buf.destroy();
+ ctx->doneCurrent();
+}
+
QTEST_MAIN(tst_QOpenGL)
#include "tst_qopengl.moc"