Browse Source

Added Buffer::mapRead() APIs.

pull/217/head
Vladimír Vondruš 9 years ago
parent
commit
c576644c9f
  1. 2
      doc/changelog.dox
  2. 63
      src/Magnum/Buffer.h

2
doc/changelog.dox

@ -117,6 +117,8 @@ namespace Magnum {
- Added @ref BufferImage::release() "{Compressed,}BufferImage::release()" and - Added @ref BufferImage::release() "{Compressed,}BufferImage::release()" and
an ability to create @ref BufferImage "{Compressed,}BufferImage" from an an ability to create @ref BufferImage "{Compressed,}BufferImage" from an
existing @ref Buffer existing @ref Buffer
- New @ref Buffer::mapRead() convenience alternatives to @ref Buffer::map()
that return `const` pointer and implicitly map as read-only
- Implemented @ref Renderer::setMemoryBarrier() and - Implemented @ref Renderer::setMemoryBarrier() and
@ref Renderer::setMemoryBarrierByRegion() @ref Renderer::setMemoryBarrierByRegion()
- Added @ref isVersionES() utility - Added @ref isVersionES() utility

63
src/Magnum/Buffer.h

@ -209,20 +209,20 @@ vertex and index buffers in both WebGL and NaCl.
The engine tracks currently bound buffers to avoid unnecessary calls to The engine tracks currently bound buffers to avoid unnecessary calls to
@fn_gl{BindBuffer}. If the buffer is already bound to some target, functions @fn_gl{BindBuffer}. If the buffer is already bound to some target, functions
@ref copy(), @ref setData(), @ref setSubData(), @ref map(), @ref flushMappedRange() @ref copy(), @ref setData(), @ref setSubData(), @ref map(), @ref mapRead(),
and @ref unmap() use that target instead of binding the buffer to some specific @ref flushMappedRange() and @ref unmap() use that target instead of binding the
target. You can also use @ref setTargetHint() to possibly reduce unnecessary buffer to some specific target. You can also use @ref setTargetHint() to
rebinding. Buffer limits and implementation-defined values (such as possibly reduce unnecessary rebinding. Buffer limits and implementation-defined
@ref maxUniformBindings()) are cached, so repeated queries don't result in values (such as @ref maxUniformBindings()) are cached, so repeated queries
repeated @fn_gl{Get} calls. See also @ref Context::resetState() and don't result in repeated @fn_gl{Get} calls. See also @ref Context::resetState()
@ref Context::State::Buffers. and @ref Context::State::Buffers.
If either @extension{ARB,direct_state_access} (part of OpenGL 4.5) or If either @extension{ARB,direct_state_access} (part of OpenGL 4.5) or
@extension{EXT,direct_state_access} desktop extension is available, functions @extension{EXT,direct_state_access} desktop extension is available, functions
@ref copy(), @ref size(), @ref data(), @ref subData(), @ref setData(), @ref copy(), @ref size(), @ref data(), @ref subData(), @ref setData(),
@ref setSubData(), @ref map(), @ref flushMappedRange() and @ref unmap() use DSA @ref setSubData(), @ref map(), @ref mapRead(), @ref flushMappedRange() and
functions to avoid unnecessary calls to @fn_gl{BindBuffer}. See their @ref unmap() use DSA functions to avoid unnecessary calls to @fn_gl{BindBuffer}.
respective documentation for more information. See their respective documentation for more information.
You can use functions @ref invalidateData() and @ref invalidateSubData() if you You can use functions @ref invalidateData() and @ref invalidateSubData() if you
don't need buffer data anymore to avoid unnecessary memory operations performed don't need buffer data anymore to avoid unnecessary memory operations performed
@ -619,7 +619,8 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
* The result is cached, repeated queries don't result in repeated * The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,map_buffer_alignment} * OpenGL calls. If extension @extension{ARB,map_buffer_alignment}
* (part of OpenGL 4.2) is not available, returns `1`. * (part of OpenGL 4.2) is not available, returns `1`.
* @see @ref map(), @fn_gl{Get} with @def_gl{MIN_MAP_BUFFER_ALIGNMENT} * @see @ref map(), @ref mapRead(), @fn_gl{Get} with
* @def_gl{MIN_MAP_BUFFER_ALIGNMENT}
* @requires_gl No minimal value is specified for OpenGL ES. Buffer * @requires_gl No minimal value is specified for OpenGL ES. Buffer
* mapping is not available in WebGL. * mapping is not available in WebGL.
*/ */
@ -1073,8 +1074,8 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
* @fn_gl_extension{GetNamedBufferSubData,EXT,direct_state_access}, * @fn_gl_extension{GetNamedBufferSubData,EXT,direct_state_access},
* eventually @fn_gl{GetBufferSubData} * eventually @fn_gl{GetBufferSubData}
* @requires_gl Buffer data queries are not available in OpenGL ES and * @requires_gl Buffer data queries are not available in OpenGL ES and
* WebGL. Use @ref map() or @ref DebugTools::bufferData() in * WebGL. Use @ref map(), @ref mapRead() or @ref DebugTools::bufferData()
* OpenGL ES instead. * in OpenGL ES instead.
*/ */
Containers::Array<char> data(); Containers::Array<char> data();
@ -1101,8 +1102,8 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
* @fn_gl_extension{GetNamedBufferSubData,EXT,direct_state_access}, * @fn_gl_extension{GetNamedBufferSubData,EXT,direct_state_access},
* eventually @fn_gl{BindBuffer} and @fn_gl{GetBufferSubData} * eventually @fn_gl{BindBuffer} and @fn_gl{GetBufferSubData}
* @requires_gl Buffer data queries are not available in OpenGL ES and * @requires_gl Buffer data queries are not available in OpenGL ES and
* WebGL. Use @ref map() or @ref DebugTools::bufferData() in * WebGL. Use @ref map(), @ref mapRead() or @ref DebugTools::bufferData()
* OpenGL ES instead. * in OpenGL ES instead.
*/ */
Containers::Array<char> subData(GLintptr offset, GLsizeiptr size); Containers::Array<char> subData(GLintptr offset, GLsizeiptr size);
@ -1203,8 +1204,8 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
* nor @extension{EXT,direct_state_access} desktop extension is * nor @extension{EXT,direct_state_access} desktop extension is
* available, the buffer is bound to hinted target before the operation * available, the buffer is bound to hinted target before the operation
* (if not already). * (if not already).
* @see @ref minMapAlignment(), @ref unmap(), @ref setTargetHint(), * @see @ref mapRead(), @ref minMapAlignment(), @ref unmap(),
* @fn_gl2{MapNamedBuffer,MapBuffer}, * @ref setTargetHint(), @fn_gl2{MapNamedBuffer,MapBuffer},
* @fn_gl_extension{MapNamedBuffer,EXT,direct_state_access}, * @fn_gl_extension{MapNamedBuffer,EXT,direct_state_access},
* eventually @fn_gl{BindBuffer} and @fn_gl{MapBuffer} * eventually @fn_gl{BindBuffer} and @fn_gl{MapBuffer}
* @requires_es_extension Extension @extension{OES,mapbuffer} in * @requires_es_extension Extension @extension{OES,mapbuffer} in
@ -1216,6 +1217,17 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
*/ */
char* map(MapAccess access); char* map(MapAccess access);
#ifndef MAGNUM_TARGET_GLES
/**
* @brief Map buffer read-only to client memory
*
* Equivalent to @ref map() with @ref MapAccess::ReadOnly.
* @requires_gl @ref MapAccess::ReadOnly is not available in OpenGL ES;
* buffer mapping is not available in WebGL.
*/
const char* mapRead() { return map(MapAccess::ReadOnly); }
#endif
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
/** @overload /** @overload
* @deprecated Use non-templated @ref map() and cast the result * @deprecated Use non-templated @ref map() and cast the result
@ -1265,8 +1277,8 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
* nor @extension{EXT,direct_state_access} desktop extension is * nor @extension{EXT,direct_state_access} desktop extension is
* available, the buffer is bound to hinted target before the operation * available, the buffer is bound to hinted target before the operation
* (if not already). * (if not already).
* @see @ref minMapAlignment(), @ref flushMappedRange(), @ref unmap(), * @see @ref mapRead(), @ref minMapAlignment(), @ref flushMappedRange(),
* @ref map(MapAccess), @ref setTargetHint(), * @ref unmap(), @ref map(MapAccess), @ref setTargetHint(),
* @fn_gl2{MapNamedBufferRange,MapBufferRange}, * @fn_gl2{MapNamedBufferRange,MapBufferRange},
* @fn_gl_extension{MapNamedBufferRange,EXT,direct_state_access}, * @fn_gl_extension{MapNamedBufferRange,EXT,direct_state_access},
* eventually @fn_gl{BindBuffer} and @fn_gl{MapBufferRange} * eventually @fn_gl{BindBuffer} and @fn_gl{MapBufferRange}
@ -1277,6 +1289,15 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
*/ */
Containers::ArrayView<char> map(GLintptr offset, GLsizeiptr length, MapFlags flags); Containers::ArrayView<char> map(GLintptr offset, GLsizeiptr length, MapFlags flags);
/**
* @brief Map buffer read-only to client memory
*
* Equivalent to @ref map() with @ref MapFlag::Read added implicitly.
*/
Containers::ArrayView<const char> mapRead(GLintptr offset, GLsizeiptr length, MapFlags flags = {}) {
return map(offset, length, flags|MapFlag::Read);
}
#ifdef MAGNUM_BUILD_DEPRECATED #ifdef MAGNUM_BUILD_DEPRECATED
/** @overload /** @overload
* @deprecated Use non-templated @ref map() and @ref Containers::arrayCast() * @deprecated Use non-templated @ref map() and @ref Containers::arrayCast()
@ -1317,8 +1338,8 @@ class MAGNUM_EXPORT Buffer: public AbstractObject {
* the buffer was mapped (e.g. after screen was resized), `true` * the buffer was mapped (e.g. after screen was resized), `true`
* otherwise. * otherwise.
* *
* Unmaps buffer previously mapped with @ref map(), invalidating the * Unmaps buffer previously mapped with @ref map() / @ref mapRead(),
* pointer returned by these functions. If neither * invalidating the pointer returned by these functions. If neither
* @extension{ARB,direct_state_access} (part of OpenGL 4.5) nor * @extension{ARB,direct_state_access} (part of OpenGL 4.5) nor
* @extension{EXT,direct_state_access} desktop extension is available, * @extension{EXT,direct_state_access} desktop extension is available,
* the buffer is bound to hinted target before the operation (if not * the buffer is bound to hinted target before the operation (if not

Loading…
Cancel
Save