diff options
author | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-06-13 16:36:27 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@digia.com> | 2014-08-08 07:29:53 +0200 |
commit | bb760d9514ed617ee8e7344152b3fa697b2c4171 (patch) | |
tree | ff80c5cff36421c1c17bdc86f5349da6194aefa2 /src/gui/opengl/qopenglbuffer.cpp | |
parent | 22e439141384f49028770d2410fafb18ef8cad1f (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 'src/gui/opengl/qopenglbuffer.cpp')
-rw-r--r-- | src/gui/opengl/qopenglbuffer.cpp | 69 |
1 files changed, 63 insertions, 6 deletions
diff --git a/src/gui/opengl/qopenglbuffer.cpp b/src/gui/opengl/qopenglbuffer.cpp index a8a2255104..3ae45abb11 100644 --- a/src/gui/opengl/qopenglbuffer.cpp +++ b/src/gui/opengl/qopenglbuffer.cpp @@ -128,6 +128,18 @@ QT_BEGIN_NAMESPACE \value ReadWrite The buffer will be mapped for reading and writing. */ +/*! + \enum QOpenGLBuffer::RangeAccessFlag + This enum defines the access mode bits for QOpenGLBuffer::mapRange(). + + \value RangeRead The buffer will be mapped for reading. + \value RangeWrite The buffer will be mapped for writing. + \value RangeInvalidate Discard the previous contents of the specified range. + \value RangeInvalidateBuffer Discard the previous contents of the entire buffer. + \value RangeFlushExplicit Indicates that modifications are to be flushed explicitly via \c glFlushMappedBufferRange. + \value RangeUnsynchronized Indicates that pending operations should not be synchronized before returning from mapRange(). +*/ + class QOpenGLBufferPrivate { public: @@ -514,10 +526,14 @@ int QOpenGLBuffer::size() const It is assumed that create() has been called on this buffer and that it has been bound to the current context. - This function is only supported under OpenGL/ES if the - \c{GL_OES_mapbuffer} extension is present. + \note This function is only supported under OpenGL ES 2.0 or + earlier if the \c GL_OES_mapbuffer extension is present. - \sa unmap(), create(), bind() + \note On OpenGL ES 3.0 and newer, or, in case if desktop OpenGL, + if \c GL_ARB_map_buffer_range is supported, this function uses + \c glMapBufferRange instead of \c glMapBuffer. + + \sa unmap(), create(), bind(), mapRange() */ void *QOpenGLBuffer::map(QOpenGLBuffer::Access access) { @@ -528,7 +544,48 @@ void *QOpenGLBuffer::map(QOpenGLBuffer::Access access) #endif if (!d->guard || !d->guard->id()) return 0; - return d->funcs->glMapBuffer(d->type, access); + if (d->funcs->hasOpenGLExtension(QOpenGLExtensions::MapBufferRange)) { + QOpenGLBuffer::RangeAccessFlags rangeAccess = 0; + switch (access) { + case QOpenGLBuffer::ReadOnly: + rangeAccess = QOpenGLBuffer::RangeRead; + break; + case QOpenGLBuffer::WriteOnly: + rangeAccess = QOpenGLBuffer::RangeWrite; + break; + case QOpenGLBuffer::ReadWrite: + rangeAccess = QOpenGLBuffer::RangeRead | QOpenGLBuffer::RangeWrite; + break; + } + return d->funcs->glMapBufferRange(d->type, 0, size(), rangeAccess); + } else { + return d->funcs->glMapBuffer(d->type, access); + } +} + +/*! + Maps the range specified by \a offset and \a count of the contents + of this buffer into the application's memory space and returns a + pointer to it. Returns null if memory mapping is not possible. + The \a access parameter specifies a combination of access flags. + + It is assumed that create() has been called on this buffer and that + it has been bound to the current context. + + \note This function is not available on OpenGL ES 2.0 and earlier. + + \sa unmap(), create(), bind() + */ +void *QOpenGLBuffer::mapRange(int offset, int count, QOpenGLBuffer::RangeAccessFlags access) +{ + Q_D(QOpenGLBuffer); +#ifndef QT_NO_DEBUG + if (!isCreated()) + qWarning("QOpenGLBuffer::mapRange(): buffer not created"); +#endif + if (!d->guard || !d->guard->id()) + return 0; + return d->funcs->glMapBufferRange(d->type, offset, count, access); } /*! @@ -539,8 +596,8 @@ void *QOpenGLBuffer::map(QOpenGLBuffer::Access access) It is assumed that this buffer has been bound to the current context, and that it was previously mapped with map(). - This function is only supported under OpenGL/ES if the - \c{GL_OES_mapbuffer} extension is present. + \note This function is only supported under OpenGL ES 2.0 and + earlier if the \c{GL_OES_mapbuffer} extension is present. \sa map() */ |