From bb760d9514ed617ee8e7344152b3fa697b2c4171 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 13 Jun 2014 16:36:27 +0200 Subject: 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 --- tests/auto/gui/qopengl/qopengl.pro | 2 +- tests/auto/gui/qopengl/tst_qopengl.cpp | 68 ++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auto/gui/qopengl/qopengl.pro b/tests/auto/gui/qopengl/qopengl.pro index 85297de1e1..bddccac747 100644 --- a/tests/auto/gui/qopengl/qopengl.pro +++ b/tests/auto/gui/qopengl/qopengl.pro @@ -11,4 +11,4 @@ SOURCES += tst_qopengl.cpp win32-msvc2010:contains(QT_CONFIG, angle):CONFIG += insignificant_test # QTBUG-31611 -linux:contains(QT_CONFIG, xcb-glx):contains(QT_CONFIG, xcb-xlib):!contains(QT_CONFIG, opengles2): DEFINES += USE_GLX +linux:contains(QT_CONFIG, xcb-glx):contains(QT_CONFIG, xcb-xlib):!contains(QT_CONFIG, egl): DEFINES += USE_GLX 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 #include #include +#include #include #include #include @@ -54,6 +55,7 @@ #include #include #include +#include #include #include @@ -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 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 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" -- cgit v1.2.3