diff options
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() */ |