mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1012 lines
41 KiB
1012 lines
41 KiB
|
16 years ago
|
#ifndef Magnum_Buffer_h
|
||
|
|
#define Magnum_Buffer_h
|
||
|
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
13 years ago
|
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
|
||
|
|
|
||
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
|
copy of this software and associated documentation files (the "Software"),
|
||
|
|
to deal in the Software without restriction, including without limitation
|
||
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
|
||
|
|
The above copyright notice and this permission notice shall be included
|
||
|
|
in all copies or substantial portions of the Software.
|
||
|
|
|
||
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
|
DEALINGS IN THE SOFTWARE.
|
||
|
16 years ago
|
*/
|
||
|
|
|
||
|
13 years ago
|
/** @file /Buffer.h
|
||
|
13 years ago
|
* @brief Class @ref Magnum::Buffer, enum @ref Magnum::BufferUsage
|
||
|
16 years ago
|
*/
|
||
|
|
|
||
|
14 years ago
|
#include <cstddef>
|
||
|
14 years ago
|
#include <array>
|
||
|
14 years ago
|
#include <vector>
|
||
|
13 years ago
|
#include <Containers/Array.h>
|
||
|
14 years ago
|
#include <Containers/EnumSet.h>
|
||
|
13 years ago
|
#include <Utility/Assert.h>
|
||
|
14 years ago
|
|
||
|
13 years ago
|
#include "AbstractObject.h"
|
||
|
16 years ago
|
#include "Magnum.h"
|
||
|
14 years ago
|
|
||
|
16 years ago
|
namespace Magnum {
|
||
|
|
|
||
|
13 years ago
|
/**
|
||
|
13 years ago
|
@brief %Buffer usage
|
||
|
|
|
||
|
|
@see @ref Buffer, @ref Buffer::setData(Containers::ArrayReference<const void>, BufferUsage)
|
||
|
|
*/
|
||
|
13 years ago
|
enum class BufferUsage: GLenum {
|
||
|
13 years ago
|
/** Set once by the application and used infrequently for drawing. */
|
||
|
13 years ago
|
StreamDraw = GL_STREAM_DRAW,
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
/**
|
||
|
13 years ago
|
* Set once as output from an OpenGL command and used infequently for
|
||
|
|
* drawing.
|
||
|
|
* @requires_gles30 Only @ref Magnum::BufferUsage::StreamDraw "BufferUsage::StreamDraw"
|
||
|
13 years ago
|
* is available in OpenGL ES 2.0.
|
||
|
|
*/
|
||
|
|
StreamRead = GL_STREAM_READ,
|
||
|
|
|
||
|
|
/**
|
||
|
13 years ago
|
* Set once as output from an OpenGL command and used infrequently for
|
||
|
|
* drawing or copying to other buffers.
|
||
|
|
* @requires_gles30 Only @ref Magnum::BufferUsage::StreamDraw "BufferUsage::StreamDraw"
|
||
|
13 years ago
|
* is available in OpenGL ES 2.0.
|
||
|
|
*/
|
||
|
|
StreamCopy = GL_STREAM_COPY,
|
||
|
|
#endif
|
||
|
|
|
||
|
13 years ago
|
/** Set once by the application and used frequently for drawing. */
|
||
|
13 years ago
|
StaticDraw = GL_STATIC_DRAW,
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
/**
|
||
|
13 years ago
|
* Set once as output from an OpenGL command and queried many times by the
|
||
|
|
* application.
|
||
|
|
* @requires_gles30 Only @ref Magnum::BufferUsage::StaticDraw "BufferUsage::StaticDraw"
|
||
|
13 years ago
|
* is available in OpenGL ES 2.0.
|
||
|
|
*/
|
||
|
|
StaticRead = GL_STATIC_READ,
|
||
|
|
|
||
|
|
/**
|
||
|
13 years ago
|
* Set once as output from an OpenGL command and used frequently for
|
||
|
|
* drawing or copying to other buffers.
|
||
|
|
* @requires_gles30 Only @ref Magnum::BufferUsage::StaticDraw "BufferUsage::StaticDraw"
|
||
|
13 years ago
|
* is available in OpenGL ES 2.0.
|
||
|
|
*/
|
||
|
|
StaticCopy = GL_STATIC_COPY,
|
||
|
|
#endif
|
||
|
|
|
||
|
|
/**
|
||
|
13 years ago
|
* Updated frequently by the application and used frequently for drawing or
|
||
|
|
* copying to other images.
|
||
|
13 years ago
|
*/
|
||
|
13 years ago
|
DynamicDraw = GL_DYNAMIC_DRAW,
|
||
|
13 years ago
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
/**
|
||
|
13 years ago
|
* Updated frequently as output from OpenGL command and queried many times
|
||
|
|
* from the application.
|
||
|
|
* @requires_gles30 Only @ref Magnum::BufferUsage::DynamicDraw "BufferUsage::DynamicDraw"
|
||
|
13 years ago
|
* is available in OpenGL ES 2.0.
|
||
|
|
*/
|
||
|
|
DynamicRead = GL_DYNAMIC_READ,
|
||
|
|
|
||
|
|
/**
|
||
|
13 years ago
|
* Updated frequently as output from OpenGL command and used frequently for
|
||
|
|
* drawing or copying to other images.
|
||
|
|
* @requires_gles30 Only @ref Magnum::BufferUsage::DynamicDraw "BufferUsage::DynamicDraw"
|
||
|
13 years ago
|
* is available in OpenGL ES 2.0.
|
||
|
|
*/
|
||
|
|
DynamicCopy = GL_DYNAMIC_COPY
|
||
|
|
#endif
|
||
|
|
};
|
||
|
|
|
||
|
14 years ago
|
/**
|
||
|
14 years ago
|
@brief %Buffer
|
||
|
|
|
||
|
|
Encapsulates one OpenGL buffer object and provides functions for convenient
|
||
|
|
data updates.
|
||
|
|
|
||
|
|
@section Buffer-data Data updating
|
||
|
14 years ago
|
|
||
|
13 years ago
|
Default way to set or update buffer data with @ref setData() or @ref setSubData()
|
||
|
|
is to use @ref Corrade::Containers::ArrayReference. See its documentation for
|
||
|
|
more information about automatic conversions etc.
|
||
|
14 years ago
|
@code
|
||
|
13 years ago
|
Containers::ArrayReference<Vector3> data;
|
||
|
13 years ago
|
buffer.setData(data, BufferUsage::StaticDraw);
|
||
|
14 years ago
|
@endcode
|
||
|
13 years ago
|
There is also overload for array-like containers from STL, such as `std::vector`
|
||
|
|
or `std::array`:
|
||
|
14 years ago
|
@code
|
||
|
|
std::vector<Vector3> data;
|
||
|
13 years ago
|
buffer.setData(data, BufferUsage::StaticDraw);
|
||
|
14 years ago
|
@endcode
|
||
|
14 years ago
|
|
||
|
14 years ago
|
@subsection Buffer-data-mapping Memory mapping
|
||
|
|
|
||
|
|
%Buffer data can be also updated asynchronously. First you need to allocate
|
||
|
13 years ago
|
the buffer to desired size by passing `nullptr` to @ref setData(), e.g.:
|
||
|
14 years ago
|
@code
|
||
|
13 years ago
|
buffer.setData({nullptr, 200*sizeof(Vector3)}, BufferUsage::StaticDraw);
|
||
|
14 years ago
|
@endcode
|
||
|
|
Then you can map the buffer to client memory and operate with the memory
|
||
|
13 years ago
|
directly. After you are done with the operation, call @ref unmap() to unmap the
|
||
|
14 years ago
|
buffer again.
|
||
|
|
@code
|
||
|
|
Vector3* data = static_cast<Vector3*>(buffer.map(0, 200*sizeof(Vector3), Buffer::MapFlag::Write|Buffer::MapFlag::InvalidateBuffer));
|
||
|
|
for(std::size_t i = 0; i != 200; ++i)
|
||
|
|
data[i] = ...;
|
||
|
13 years ago
|
CORRADE_INTERNAL_ASSERT_OUTPUT(buffer.unmap());
|
||
|
14 years ago
|
@endcode
|
||
|
|
If you are updating only a few discrete portions of the buffer, you can use
|
||
|
13 years ago
|
@ref MapFlag::FlushExplicit and @ref flushMappedRange() to reduce number of
|
||
|
|
memory operations performed by OpenGL on unmapping. Example:
|
||
|
14 years ago
|
@code
|
||
|
|
Vector3* data = static_cast<Vector3*>(buffer.map(0, 200*sizeof(Vector3), Buffer::MapFlag::Write|Buffer::MapFlag::FlushExplicit));
|
||
|
|
for(std::size_t i: {7, 27, 56, 128}) {
|
||
|
|
data[i] = ...;
|
||
|
|
buffer.flushMappedRange(i*sizeof(Vector3), sizeof(Vector3));
|
||
|
|
}
|
||
|
13 years ago
|
CORRADE_INTERNAL_ASSERT_OUTPUT(buffer.unmap());
|
||
|
14 years ago
|
@endcode
|
||
|
|
|
||
|
14 years ago
|
@section Buffer-performance-optimization Performance optimizations
|
||
|
14 years ago
|
|
||
|
14 years ago
|
The engine tracks currently bound buffers to avoid unnecessary calls to
|
||
|
14 years ago
|
@fn_gl{BindBuffer}. If the buffer is already bound to some target, functions
|
||
|
13 years ago
|
@ref copy(), @ref setData(), @ref setSubData(), @ref map(), @ref flushMappedRange()
|
||
|
|
and @ref unmap() use that target instead of binding the buffer to some specific
|
||
|
|
target. You can also use @ref setTargetHint() to possibly reduce unnecessary
|
||
|
|
rebinding. %Buffer limits and implementation-defined values (such as
|
||
|
|
@ref maxVertexAttributeBindings()) are cached, so repeated queries don't result
|
||
|
|
in repeated @fn_gl{Get} calls.
|
||
|
14 years ago
|
|
||
|
|
If extension @extension{EXT,direct_state_access} is available, functions
|
||
|
13 years ago
|
@ref copy(), @ref setData(), @ref setSubData(), @ref map(), @ref flushMappedRange()
|
||
|
|
and @ref unmap() use DSA functions to avoid unnecessary calls to
|
||
|
|
@fn_gl{BindBuffer}. See their respective documentation for more information.
|
||
|
14 years ago
|
|
||
|
13 years ago
|
You can use functions @ref invalidateData() and @ref invalidateSubData() if you
|
||
|
|
don't need buffer data anymore to avoid unnecessary memory operations performed
|
||
|
|
by OpenGL in order to preserve the data. If running on OpenGL ES or extension
|
||
|
14 years ago
|
@extension{ARB,invalidate_subdata} is not available, these functions do
|
||
|
|
nothing.
|
||
|
|
|
||
|
13 years ago
|
@todo Support for AMD/ARB's query buffer (@extension{AMD,query_buffer_object}, @extension{ARB,query_buffer_object})
|
||
|
14 years ago
|
@todo BindBufferRange/BindBufferOffset/BindBufferBase for transform feedback (3.0, @extension{EXT,transform_feedback})
|
||
|
16 years ago
|
*/
|
||
|
13 years ago
|
class MAGNUM_EXPORT Buffer: public AbstractObject {
|
||
|
14 years ago
|
friend class Context;
|
||
|
|
|
||
|
16 years ago
|
public:
|
||
|
14 years ago
|
/**
|
||
|
|
* @brief %Buffer target
|
||
|
|
*
|
||
|
13 years ago
|
* @see @ref bind(Target), @ref unbind(Target)
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
enum class Target: GLenum {
|
||
|
|
/** Used for storing vertex attributes. */
|
||
|
|
Array = GL_ARRAY_BUFFER,
|
||
|
16 years ago
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
/**
|
||
|
|
* Used for storing atomic counters.
|
||
|
14 years ago
|
* @requires_gl42 %Extension @extension{ARB,shader_atomic_counters}
|
||
|
14 years ago
|
* @requires_gl Atomic counters are not available in OpenGL ES.
|
||
|
14 years ago
|
*/
|
||
|
|
AtomicCounter = GL_ATOMIC_COUNTER_BUFFER,
|
||
|
|
#endif
|
||
|
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
14 years ago
|
/**
|
||
|
13 years ago
|
* Source for copies. See @ref copy().
|
||
|
14 years ago
|
* @requires_gl31 %Extension @extension{ARB,copy_buffer}
|
||
|
14 years ago
|
* @requires_gles30 Buffer copying is not available in OpenGL ES
|
||
|
|
* 2.0.
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
CopyRead = GL_COPY_READ_BUFFER,
|
||
|
|
|
||
|
14 years ago
|
/**
|
||
|
13 years ago
|
* Target for copies. See @ref copy().
|
||
|
14 years ago
|
* @requires_gl31 %Extension @extension{ARB,copy_buffer}
|
||
|
14 years ago
|
* @requires_gles30 Buffer copying is not available in OpenGL ES
|
||
|
|
* 2.0.
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
CopyWrite = GL_COPY_WRITE_BUFFER,
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
14 years ago
|
/**
|
||
|
|
* Indirect compute dispatch commands.
|
||
|
14 years ago
|
* @requires_gl43 %Extension @extension{ARB,compute_shader}
|
||
|
14 years ago
|
* @requires_gl Compute shaders are not available in OpenGL ES.
|
||
|
14 years ago
|
*/
|
||
|
|
DispatchIndirect = GL_DISPATCH_INDIRECT_BUFFER,
|
||
|
|
|
||
|
14 years ago
|
/**
|
||
|
14 years ago
|
* Used for supplying arguments for indirect drawing.
|
||
|
14 years ago
|
* @requires_gl40 %Extension @extension{ARB,draw_indirect}
|
||
|
14 years ago
|
* @requires_gl Indirect drawing not available in OpenGL ES.
|
||
|
14 years ago
|
*/
|
||
|
|
DrawIndirect = GL_DRAW_INDIRECT_BUFFER,
|
||
|
|
#endif
|
||
|
|
|
||
|
14 years ago
|
/** Used for storing vertex indices. */
|
||
|
14 years ago
|
ElementArray = GL_ELEMENT_ARRAY_BUFFER
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
,
|
||
|
14 years ago
|
|
||
|
14 years ago
|
/**
|
||
|
14 years ago
|
* Target for pixel pack operations.
|
||
|
14 years ago
|
* @requires_gles30 Pixel buffer objects are not available in
|
||
|
|
* OpenGL ES 2.0.
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
PixelPack = GL_PIXEL_PACK_BUFFER,
|
||
|
14 years ago
|
|
||
|
14 years ago
|
/**
|
||
|
14 years ago
|
* Source for texture update operations.
|
||
|
14 years ago
|
* @requires_gles30 Pixel buffer objects are not available in
|
||
|
|
* OpenGL ES 2.0.
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
PixelUnpack = GL_PIXEL_UNPACK_BUFFER,
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
14 years ago
|
/**
|
||
|
|
* Used for shader storage.
|
||
|
14 years ago
|
* @requires_gl43 %Extension @extension{ARB,shader_storage_buffer_object}
|
||
|
14 years ago
|
* @requires_gl Shader storage is not available in OpenGL ES.
|
||
|
14 years ago
|
*/
|
||
|
|
ShaderStorage = GL_SHADER_STORAGE_BUFFER,
|
||
|
|
|
||
|
14 years ago
|
/**
|
||
|
14 years ago
|
* Source for texel fetches. See BufferTexture.
|
||
|
14 years ago
|
* @requires_gl31 %Extension @extension{ARB,texture_buffer_object}
|
||
|
14 years ago
|
* @requires_gl Texture buffers are not available in OpenGL ES.
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
Texture = GL_TEXTURE_BUFFER,
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
14 years ago
|
/**
|
||
|
|
* Target for transform feedback.
|
||
|
14 years ago
|
* @requires_gl30 %Extension @extension{EXT,transform_feedback}
|
||
|
14 years ago
|
* @requires_gles30 Transform feedback is not available in OpenGL
|
||
|
|
* ES 2.0.
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
TransformFeedback = GL_TRANSFORM_FEEDBACK_BUFFER,
|
||
|
|
|
||
|
14 years ago
|
/**
|
||
|
|
* Used for storing uniforms.
|
||
|
14 years ago
|
* @requires_gl31 %Extension @extension{ARB,uniform_buffer_object}
|
||
|
14 years ago
|
* @requires_gles30 Uniform buffers are not available in OpenGL ES
|
||
|
|
* 2.0.
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
Uniform = GL_UNIFORM_BUFFER
|
||
|
14 years ago
|
#endif
|
||
|
16 years ago
|
};
|
||
|
|
|
||
|
13 years ago
|
#ifdef MAGNUM_BUILD_DEPRECATED
|
||
|
14 years ago
|
/**
|
||
|
13 years ago
|
* @copybrief BufferUsage
|
||
|
|
* @deprecated Use @ref Magnum::BufferUsage "BufferUsage" instead.
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
typedef CORRADE_DEPRECATED("use BufferUsage instead") BufferUsage Usage;
|
||
|
13 years ago
|
#endif
|
||
|
16 years ago
|
|
||
|
14 years ago
|
/**
|
||
|
|
* @brief Memory mapping access
|
||
|
|
*
|
||
|
13 years ago
|
* @deprecated_gl Prefer to use @ref Magnum::Buffer::map(GLintptr, GLsizeiptr, MapFlags) "map(GLintptr, GLsizeiptr, MapFlags)"
|
||
|
14 years ago
|
* instead, as it has more complete set of features.
|
||
|
13 years ago
|
* @see @ref map(MapAccess), @ref mapSub()
|
||
|
13 years ago
|
* @requires_es_extension %Extension @es_extension{OES,mapbuffer} or
|
||
|
13 years ago
|
* @es_extension{CHROMIUM,map_sub}
|
||
|
14 years ago
|
*/
|
||
|
|
enum class MapAccess: GLenum {
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
/**
|
||
|
|
* Map buffer for reading only.
|
||
|
|
* @requires_gl Only @ref Magnum::Buffer::MapAccess "MapAccess::WriteOnly"
|
||
|
13 years ago
|
* is available in OpenGL ES.
|
||
|
14 years ago
|
*/
|
||
|
|
ReadOnly = GL_READ_ONLY,
|
||
|
|
#endif
|
||
|
|
|
||
|
13 years ago
|
/** Map buffer for writing only. */
|
||
|
14 years ago
|
#ifdef MAGNUM_TARGET_GLES
|
||
|
|
WriteOnly = GL_WRITE_ONLY_OES
|
||
|
|
#else
|
||
|
|
WriteOnly = GL_WRITE_ONLY,
|
||
|
14 years ago
|
|
||
|
|
/**
|
||
|
|
* Map buffer for both reading and writing.
|
||
|
|
* @requires_gl Only @ref Magnum::Buffer::MapAccess "MapAccess::WriteOnly"
|
||
|
13 years ago
|
* is available in OpenGL ES.
|
||
|
14 years ago
|
*/
|
||
|
|
ReadWrite = GL_READ_WRITE
|
||
|
|
#endif
|
||
|
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Memory mapping flag
|
||
|
|
*
|
||
|
13 years ago
|
* @see @ref MapFlags, @ref map(GLintptr, GLsizeiptr, MapFlags)
|
||
|
14 years ago
|
* @requires_gl30 %Extension @extension{ARB,map_buffer_range}
|
||
|
|
* @requires_gles30 %Extension @es_extension{EXT,map_buffer_range}
|
||
|
|
*/
|
||
|
|
enum class MapFlag: GLbitfield {
|
||
|
|
/** Map buffer for reading. */
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
14 years ago
|
Read = GL_MAP_READ_BIT,
|
||
|
14 years ago
|
#else
|
||
|
|
Read = GL_MAP_READ_BIT_EXT,
|
||
|
|
#endif
|
||
|
14 years ago
|
|
||
|
|
/** Map buffer for writing. */
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
14 years ago
|
Write = GL_MAP_WRITE_BIT,
|
||
|
14 years ago
|
#else
|
||
|
|
Write = GL_MAP_WRITE_BIT_EXT,
|
||
|
|
#endif
|
||
|
14 years ago
|
|
||
|
|
/**
|
||
|
13 years ago
|
* Previous contents of the entire buffer may be discarded. May not
|
||
|
|
* be used in combination with @ref MapFlag::Read.
|
||
|
|
* @see @ref invalidateData()
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
14 years ago
|
InvalidateBuffer = GL_MAP_INVALIDATE_BUFFER_BIT,
|
||
|
14 years ago
|
#else
|
||
|
|
InvalidateBuffer = GL_MAP_INVALIDATE_BUFFER_BIT_EXT,
|
||
|
|
#endif
|
||
|
14 years ago
|
|
||
|
|
/**
|
||
|
13 years ago
|
* Previous contents of mapped range may be discarded. May not be
|
||
|
|
* used in combination with @ref MapFlag::Read.
|
||
|
|
* @see @ref invalidateSubData()
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
14 years ago
|
InvalidateRange = GL_MAP_INVALIDATE_RANGE_BIT,
|
||
|
14 years ago
|
#else
|
||
|
|
InvalidateRange = GL_MAP_INVALIDATE_RANGE_BIT_EXT,
|
||
|
|
#endif
|
||
|
14 years ago
|
|
||
|
|
/**
|
||
|
|
* Only one or more discrete subranges of the mapping will be
|
||
|
13 years ago
|
* modified. See @ref flushMappedRange() for more information. May
|
||
|
|
* only be used in conjuction with @ref MapFlag::Write.
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
14 years ago
|
FlushExplicit = GL_MAP_FLUSH_EXPLICIT_BIT,
|
||
|
14 years ago
|
#else
|
||
|
|
FlushExplicit = GL_MAP_FLUSH_EXPLICIT_BIT_EXT,
|
||
|
|
#endif
|
||
|
14 years ago
|
|
||
|
|
/**
|
||
|
|
* No pending operations on the buffer should be synchronized
|
||
|
|
* before mapping.
|
||
|
|
*/
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
14 years ago
|
Unsynchronized = GL_MAP_UNSYNCHRONIZED_BIT
|
||
|
14 years ago
|
#else
|
||
|
|
Unsynchronized = GL_MAP_UNSYNCHRONIZED_BIT_EXT
|
||
|
|
#endif
|
||
|
14 years ago
|
};
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Memory mapping flags
|
||
|
|
*
|
||
|
13 years ago
|
* @see @ref map(GLintptr, GLsizeiptr, MapFlags)
|
||
|
13 years ago
|
* @requires_gl30 %Extension @extension{ARB,map_buffer_range}
|
||
|
|
* @requires_gles30 %Extension @es_extension{EXT,map_buffer_range}
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
typedef Containers::EnumSet<MapFlag, GLbitfield> MapFlags;
|
||
|
14 years ago
|
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
/**
|
||
|
|
* @brief Minimal supported mapping alignment
|
||
|
|
*
|
||
|
|
* The result is cached, repeated queries don't result in repeated
|
||
|
|
* OpenGL calls.
|
||
|
|
* @see @ref map(), @fn_gl{Get} with @def_gl{MIN_MAP_BUFFER_ALIGNMENT}
|
||
|
|
* @requires_gl No minimal value is specified for OpenGL ES.
|
||
|
|
*/
|
||
|
|
static Int minMapAlignment();
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Max supported atomic counter buffer binding count
|
||
|
|
*
|
||
|
|
* The result is cached, repeated queries don't result in repeated
|
||
|
|
* OpenGL calls. If extension @extension{ARB,shader_atomic_counters} is
|
||
|
|
* not available, returns `0`.
|
||
|
|
* @see @fn_gl{Get} with @def_gl{MAX_ATOMIC_COUNTER_BUFFER_BINDINGS}
|
||
|
|
* @requires_gl Atomic counters are not available in OpenGL ES.
|
||
|
|
*/
|
||
|
|
static Int maxAtomicCounterBindings();
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Max supported shader storage buffer binding count
|
||
|
|
*
|
||
|
|
* The result is cached, repeated queries don't result in repeated
|
||
|
|
* OpenGL calls. If extension @extension{ARB,shader_storage_buffer_object}
|
||
|
|
* is not available, returns `0`.
|
||
|
|
* @see @fn_gl{Get} with @def_gl{MAX_SHADER_STORAGE_BUFFER_BINDINGS}
|
||
|
|
* @requires_gl Atomic counters are not available in OpenGL ES.
|
||
|
|
*/
|
||
|
|
static Int maxShaderStorageBindings();
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Alignment of shader storage buffer binding offset
|
||
|
|
*
|
||
|
|
* The result is cached, repeated queries don't result in repeated
|
||
|
|
* OpenGL calls. If extension @extension{ARB,shader_storage_buffer_object}
|
||
|
|
* is not available, returns `0`.
|
||
|
|
* @see @fn_gl{Get} with @def_gl{SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT}
|
||
|
|
* @requires_gl Atomic counters are not available in OpenGL ES.
|
||
|
|
*/
|
||
|
|
static Int shaderStorageOffsetAlignment();
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
/**
|
||
|
|
* @brief Max supported uniform buffer binding count
|
||
|
|
*
|
||
|
|
* The result is cached, repeated queries don't result in repeated
|
||
|
|
* OpenGL calls. If extension @extension{ARB,uniform_buffer_object}
|
||
|
|
* is not available, returns `0`.
|
||
|
|
* @see @fn_gl{Get} with @def_gl{MAX_UNIFORM_BUFFER_BINDINGS}
|
||
|
|
* @requires_gles30 Uniform blocks are not available in OpenGL ES 2.0.
|
||
|
|
*/
|
||
|
|
static Int maxUniformBindings();
|
||
|
|
#endif
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Max supported vertex buffer binding count
|
||
|
|
*
|
||
|
|
* The result is cached, repeated queries don't result in repeated
|
||
|
|
* OpenGL calls.
|
||
|
|
* @see @fn_gl{Get} with @def_gl{MAX_VERTEX_ATTRIB_BINDINGS}
|
||
|
|
*/
|
||
|
|
static Int maxVertexAttributeBindings();
|
||
|
|
|
||
|
14 years ago
|
/**
|
||
|
|
* @brief Unbind any buffer from given target
|
||
|
14 years ago
|
* @param target %Target
|
||
|
14 years ago
|
*
|
||
|
|
* @see @fn_gl{BindBuffer}
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
static void unbind(Target target) { bind(target, 0); }
|
||
|
14 years ago
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
14 years ago
|
/**
|
||
|
|
* @brief Copy one buffer to another
|
||
|
|
* @param read %Buffer from which to read
|
||
|
|
* @param write %Buffer to which to copy
|
||
|
|
* @param readOffset Offset in the read buffer
|
||
|
|
* @param writeOffset Offset in the write buffer
|
||
|
|
* @param size Data size
|
||
|
|
*
|
||
|
14 years ago
|
* If @extension{EXT,direct_state_access} is not available and the
|
||
|
|
* buffers aren't already bound somewhere, they are bound to
|
||
|
13 years ago
|
* @ref Target::CopyRead and @ref Target::CopyWrite before the copy is
|
||
|
14 years ago
|
* performed.
|
||
|
14 years ago
|
* @see @fn_gl{BindBuffer} and @fn_gl{CopyBufferSubData} or
|
||
|
|
* @fn_gl_extension{NamedCopyBufferSubData,EXT,direct_state_access}
|
||
|
14 years ago
|
* @requires_gl31 %Extension @extension{ARB,copy_buffer}
|
||
|
|
* @requires_gles30 %Buffer copying is not available in OpenGL ES 2.0.
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
static void copy(Buffer& read, Buffer& write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size) {
|
||
|
14 years ago
|
copyImplementation(read, write, readOffset, writeOffset, size);
|
||
|
|
}
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
16 years ago
|
/**
|
||
|
|
* @brief Constructor
|
||
|
13 years ago
|
* @param targetHint Target hint, see @ref setTargetHint() for more
|
||
|
14 years ago
|
* information
|
||
|
16 years ago
|
*
|
||
|
13 years ago
|
* Creates new OpenGL buffer.
|
||
|
14 years ago
|
* @see @fn_gl{GenBuffers}
|
||
|
16 years ago
|
*/
|
||
|
13 years ago
|
explicit Buffer(Target targetHint = Target::Array);
|
||
|
16 years ago
|
|
||
|
13 years ago
|
/** @brief Copying is not allowed */
|
||
|
|
Buffer(const Buffer&) = delete;
|
||
|
|
|
||
|
|
/** @brief Move constructor */
|
||
|
|
Buffer(Buffer&& other) noexcept;
|
||
|
|
|
||
|
16 years ago
|
/**
|
||
|
|
* @brief Destructor
|
||
|
|
*
|
||
|
|
* Deletes associated OpenGL buffer.
|
||
|
14 years ago
|
* @see @fn_gl{DeleteBuffers}
|
||
|
16 years ago
|
*/
|
||
|
13 years ago
|
~Buffer();
|
||
|
16 years ago
|
|
||
|
13 years ago
|
/** @brief Copying is not allowed */
|
||
|
|
Buffer& operator=(const Buffer&) = delete;
|
||
|
|
|
||
|
|
/** @brief Move assignment */
|
||
|
|
Buffer& operator=(Buffer&& other) noexcept;
|
||
|
|
|
||
|
14 years ago
|
/** @brief OpenGL buffer ID */
|
||
|
13 years ago
|
GLuint id() const { return _id; }
|
||
|
14 years ago
|
|
||
|
13 years ago
|
/**
|
||
|
|
* @brief %Buffer label
|
||
|
|
*
|
||
|
|
* The result is *not* cached, repeated queries will result in repeated
|
||
|
|
* OpenGL calls. If neither @extension{KHR,debug} nor
|
||
|
13 years ago
|
* @extension2{EXT,debug_label} desktop or ES extension is available,
|
||
|
13 years ago
|
* this function returns empty string.
|
||
|
|
* @see @fn_gl{GetObjectLabel} with @def_gl{BUFFER} or
|
||
|
13 years ago
|
* @fn_gl_extension2{GetObjectLabel,EXT,debug_label} with
|
||
|
13 years ago
|
* @def_gl{BUFFER_OBJECT_EXT}
|
||
|
|
*/
|
||
|
|
std::string label() const;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Set buffer label
|
||
|
|
* @return Reference to self (for method chaining)
|
||
|
|
*
|
||
|
|
* Default is empty string. If neither @extension{KHR,debug} nor
|
||
|
13 years ago
|
* @extension2{EXT,debug_label} desktop or ES extension is available,
|
||
|
13 years ago
|
* this function does nothing.
|
||
|
13 years ago
|
* @see @ref maxLabelLength(), @fn_gl{ObjectLabel} with @def_gl{BUFFER}
|
||
|
|
* or @fn_gl_extension2{LabelObject,EXT,debug_label} with
|
||
|
|
* @def_gl{BUFFER_OBJECT_EXT}
|
||
|
13 years ago
|
*/
|
||
|
|
Buffer& setLabel(const std::string& label);
|
||
|
|
|
||
|
14 years ago
|
/** @brief Target hint */
|
||
|
13 years ago
|
Target targetHint() const { return _targetHint; }
|
||
|
14 years ago
|
|
||
|
14 years ago
|
/**
|
||
|
14 years ago
|
* @brief Set target hint
|
||
|
13 years ago
|
* @return Reference to self (for method chaining)
|
||
|
14 years ago
|
*
|
||
|
14 years ago
|
* If @extension{EXT,direct_state_access} is not available, the buffer
|
||
|
|
* must be internally bound to some target before any operation. You
|
||
|
13 years ago
|
* can specify target which will always be used when binding the buffer
|
||
|
|
* internally, possibly saving some calls to @fn_gl{BindBuffer}.
|
||
|
14 years ago
|
*
|
||
|
13 years ago
|
* Default target hint is @ref Target::Array.
|
||
|
|
* @see @ref setData(), @ref setSubData()
|
||
|
14 years ago
|
* @todo Target::ElementArray cannot be used when no VAO is bound -
|
||
|
|
* http://www.opengl.org/wiki/Vertex_Specification#Index_buffers
|
||
|
|
* ... damned GL state
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
Buffer& setTargetHint(Target hint) {
|
||
|
13 years ago
|
_targetHint = hint;
|
||
|
13 years ago
|
return *this;
|
||
|
13 years ago
|
}
|
||
|
14 years ago
|
|
||
|
|
/**
|
||
|
|
* @brief Bind buffer
|
||
|
14 years ago
|
* @param target %Target
|
||
|
14 years ago
|
*
|
||
|
14 years ago
|
* @todo Allow binding to Target::ElementArray only if VAO is bound
|
||
|
|
* to avoid potential issues?
|
||
|
14 years ago
|
* @bug Binding to ElementArray if any VAO is active will corrupt the mesh
|
||
|
|
* @todo Don't allow user to bind buffers?
|
||
|
14 years ago
|
* @see @fn_gl{BindBuffer}
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
void bind(Target target) { bind(target, _id); }
|
||
|
16 years ago
|
|
||
|
13 years ago
|
/**
|
||
|
13 years ago
|
* @brief %Buffer size
|
||
|
13 years ago
|
*
|
||
|
|
* If @extension{EXT,direct_state_access} is not available and the
|
||
|
|
* buffer is not already bound somewhere, it is bound to hinted target
|
||
|
|
* before the operation.
|
||
|
|
* @see @fn_gl{BindBuffer} and @fn_gl{GetBufferParameter} or
|
||
|
|
* @fn_gl_extension{GetNamedBufferParameter,EXT,direct_state_access}
|
||
|
|
* with @def_gl{BUFFER_SIZE}
|
||
|
|
*/
|
||
|
|
Int size();
|
||
|
|
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
/**
|
||
|
13 years ago
|
* @brief %Buffer data
|
||
|
13 years ago
|
*
|
||
|
|
* Returns data of whole buffer. If @extension{EXT,direct_state_access}
|
||
|
|
* is not available and the buffer is not already bound somewhere, it
|
||
|
|
* is bound to hinted target before the operation.
|
||
|
13 years ago
|
* @see @ref size(), @ref subData(), @ref setData(), @fn_gl{BindBuffer}
|
||
|
|
* and @fn_gl{GetBufferParameter} or
|
||
|
13 years ago
|
* @fn_gl_extension{GetNamedBufferParameter,EXT,direct_state_access}
|
||
|
|
* with @def_gl{BUFFER_SIZE}, @fn_gl{GetBufferSubData} or
|
||
|
|
* @fn_gl_extension{GetNamedBufferSubData,EXT,direct_state_access}
|
||
|
13 years ago
|
* @requires_gl %Buffer data queries are not available in OpenGL ES.
|
||
|
|
* Use @ref Magnum::Buffer::map() "map()" instead.
|
||
|
13 years ago
|
*/
|
||
|
13 years ago
|
template<class T = unsigned char> Containers::Array<T> data();
|
||
|
13 years ago
|
|
||
|
|
/**
|
||
|
13 years ago
|
* @brief %Buffer subdata
|
||
|
13 years ago
|
* @param offset Byte offset in the buffer
|
||
|
|
* @param size Data size (count of @p T values)
|
||
|
13 years ago
|
*
|
||
|
|
* Returns data of given buffer portion. If @extension{EXT,direct_state_access}
|
||
|
|
* is not available and the buffer is not already bound somewhere, it
|
||
|
|
* is bound to hinted target before the operation.
|
||
|
13 years ago
|
* @see @ref size(), @ref data(), @ref setSubData(), @fn_gl{BindBuffer}
|
||
|
|
* and @fn_gl{GetBufferSubData} or
|
||
|
|
* @fn_gl_extension{GetNamedBufferSubData,EXT,direct_state_access}
|
||
|
13 years ago
|
* @requires_gl %Buffer data queries are not available in OpenGL ES.
|
||
|
|
* Use @ref Magnum::Buffer::map() "map()" instead.
|
||
|
13 years ago
|
*/
|
||
|
13 years ago
|
template<class T = unsigned char> Containers::Array<T> subData(GLintptr offset, GLsizeiptr size);
|
||
|
13 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
16 years ago
|
/**
|
||
|
|
* @brief Set buffer data
|
||
|
13 years ago
|
* @param data Data
|
||
|
14 years ago
|
* @param usage %Buffer usage
|
||
|
13 years ago
|
* @return Reference to self (for method chaining)
|
||
|
14 years ago
|
*
|
||
|
14 years ago
|
* If @extension{EXT,direct_state_access} is not available and the
|
||
|
|
* buffer is not already bound somewhere, it is bound to hinted target
|
||
|
|
* before the operation.
|
||
|
13 years ago
|
* @see @ref setTargetHint(), @fn_gl{BindBuffer} and @fn_gl{BufferData}
|
||
|
|
* or @fn_gl_extension{NamedBufferData,EXT,direct_state_access}
|
||
|
16 years ago
|
*/
|
||
|
13 years ago
|
Buffer& setData(Containers::ArrayReference<const void> data, BufferUsage usage) {
|
||
|
13 years ago
|
(this->*dataImplementation)(data.size(), data, usage);
|
||
|
13 years ago
|
return *this;
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
#ifdef MAGNUM_BUILD_DEPRECATED
|
||
|
14 years ago
|
/**
|
||
|
|
* @brief Set buffer data
|
||
|
13 years ago
|
* @deprecated Use @ref Magnum::Buffer::setData(Containers::ArrayReference<const void>, BufferUsage) "setData(Containers::ArrayReference<const void>, BufferUsage)"
|
||
|
13 years ago
|
* instead.
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
CORRADE_DEPRECATED("use setData(Containers::ArrayReference, BufferUsage) instead") Buffer& setData(GLsizeiptr size, const GLvoid* data, BufferUsage usage) {
|
||
|
13 years ago
|
return setData({data, std::size_t(size)}, usage);
|
||
|
14 years ago
|
}
|
||
|
13 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
13 years ago
|
/** @overload */
|
||
|
13 years ago
|
template<class T> Buffer& setData(const std::vector<T>& data, BufferUsage usage) {
|
||
|
13 years ago
|
setData({data.data(), data.size()}, usage);
|
||
|
13 years ago
|
return *this;
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
/** @overload */
|
||
|
13 years ago
|
template<std::size_t size, class T> Buffer& setData(const std::array<T, size>& data, BufferUsage usage) {
|
||
|
13 years ago
|
setData({data.data(), data.size()}, usage);
|
||
|
13 years ago
|
return *this;
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
/**
|
||
|
|
* @brief Set buffer subdata
|
||
|
14 years ago
|
* @param offset Offset in the buffer
|
||
|
13 years ago
|
* @param data Data
|
||
|
13 years ago
|
* @return Reference to self (for method chaining)
|
||
|
14 years ago
|
*
|
||
|
14 years ago
|
* If @extension{EXT,direct_state_access} is not available and the
|
||
|
|
* buffer is not already bound somewhere, it is bound to hinted target
|
||
|
|
* before the operation.
|
||
|
13 years ago
|
* @see @ref setTargetHint(), @fn_gl{BindBuffer} and @fn_gl{BufferSubData}
|
||
|
14 years ago
|
* or @fn_gl_extension{NamedBufferSubData,EXT,direct_state_access}
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
Buffer& setSubData(GLintptr offset, Containers::ArrayReference<const void> data) {
|
||
|
|
(this->*subDataImplementation)(offset, data.size(), data);
|
||
|
13 years ago
|
return *this;
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
#ifdef MAGNUM_BUILD_DEPRECATED
|
||
|
14 years ago
|
/**
|
||
|
|
* @brief Set buffer subdata
|
||
|
13 years ago
|
* @deprecated Use @ref Magnum::Buffer::setSubData(GLintptr, Containers::ArrayReference<const void>) "setSubData(GLintptr, Containers::ArrayReference<const void>)"
|
||
|
|
* instead.
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
CORRADE_DEPRECATED("use setSubData(GLintptr, Containers::ArrayReference) instead") Buffer& setSubData(GLintptr offset, GLsizeiptr size, const GLvoid* data) {
|
||
|
13 years ago
|
return setSubData(offset, {data, std::size_t(size)});
|
||
|
14 years ago
|
}
|
||
|
13 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
13 years ago
|
/** @overload */
|
||
|
13 years ago
|
template<class T> Buffer& setSubData(GLintptr offset, const std::vector<T>& data) {
|
||
|
13 years ago
|
setSubData(offset, {data.data(), data.size()});
|
||
|
13 years ago
|
return *this;
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
/** @overload */
|
||
|
13 years ago
|
template<std::size_t size, class T> Buffer& setSubData(GLintptr offset, const std::array<T, size>& data) {
|
||
|
13 years ago
|
setSubData(offset, {data.data(), data.size()});
|
||
|
13 years ago
|
return *this;
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
/**
|
||
|
|
* @brief Invalidate buffer data
|
||
|
13 years ago
|
* @return Reference to self (for method chaining)
|
||
|
14 years ago
|
*
|
||
|
14 years ago
|
* If running on OpenGL ES or extension @extension{ARB,invalidate_subdata}
|
||
|
|
* is not available, this function does nothing.
|
||
|
13 years ago
|
* @see @ref MapFlag::InvalidateBuffer, @fn_gl{InvalidateBufferData}
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
Buffer& invalidateData() {
|
||
|
14 years ago
|
(this->*invalidateImplementation)();
|
||
|
13 years ago
|
return *this;
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Invalidate buffer subdata
|
||
|
|
* @param offset Offset into the buffer
|
||
|
|
* @param length Length of the invalidated range
|
||
|
13 years ago
|
* @return Reference to self (for method chaining)
|
||
|
14 years ago
|
*
|
||
|
14 years ago
|
* If running on OpenGL ES or extension @extension{ARB,invalidate_subdata}
|
||
|
|
* is not available, this function does nothing.
|
||
|
13 years ago
|
* @see @ref MapFlag::InvalidateRange, @fn_gl{InvalidateBufferData}
|
||
|
14 years ago
|
*/
|
||
|
13 years ago
|
Buffer& invalidateSubData(GLintptr offset, GLsizeiptr length) {
|
||
|
14 years ago
|
(this->*invalidateSubImplementation)(offset, length);
|
||
|
13 years ago
|
return *this;
|
||
|
14 years ago
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
14 years ago
|
/**
|
||
|
|
* @brief Map buffer to client memory
|
||
|
|
* @param access Access
|
||
|
|
* @return Pointer to buffer data
|
||
|
|
*
|
||
|
|
* If @extension{EXT,direct_state_access} is not available and the
|
||
|
|
* buffer is not already bound somewhere, it is bound to hinted target
|
||
|
|
* before the operation.
|
||
|
13 years ago
|
* @deprecated_gl Prefer to use @ref Magnum::Buffer::map(GLintptr, GLsizeiptr, MapFlags) "map(GLintptr, GLsizeiptr, MapFlags)"
|
||
|
14 years ago
|
* instead, as it has more complete set of features.
|
||
|
13 years ago
|
* @see @ref minMapAlignment(), @ref unmap(), @ref setTargetHint(),
|
||
|
|
* @fn_gl{BindBuffer} and @fn_gl{MapBuffer} or
|
||
|
|
* @fn_gl_extension{MapNamedBuffer,EXT,direct_state_access}
|
||
|
14 years ago
|
* @requires_es_extension %Extension @es_extension{OES,mapbuffer} in
|
||
|
|
* OpenGL ES 2.0, use @ref Magnum::Buffer::map(GLintptr, GLsizeiptr, MapFlags) "map(GLintptr, GLsizeiptr, MapFlags)"
|
||
|
|
* in OpenGL ES 3.0 instead.
|
||
|
|
*/
|
||
|
13 years ago
|
void* map(MapAccess access) {
|
||
|
14 years ago
|
return (this->*mapImplementation)(access);
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
#if defined(MAGNUM_TARGET_GLES2) || defined(DOXYGEN_GENERATING_OUTPUT)
|
||
|
|
/**
|
||
|
|
* @brief Map portion of buffer to client memory
|
||
|
|
* @param offset Offset into the buffer
|
||
|
|
* @param length Length of the mapped memory
|
||
|
|
* @param access Access
|
||
|
|
* @return Pointer to buffer data
|
||
|
|
*
|
||
|
|
* If the buffer is not already bound somewhere, it is bound to hinted
|
||
|
|
* target before the operation.
|
||
|
13 years ago
|
* @deprecated_gl Prefer to use @ref Magnum::Buffer::map(GLintptr, GLsizeiptr, MapFlags) "map(GLintptr, GLsizeiptr, MapFlags)"
|
||
|
13 years ago
|
* instead, as it has more complete set of features.
|
||
|
13 years ago
|
* @see @ref unmapSub(), @ref setTargetHint(),
|
||
|
|
* @fn_gl_extension{MapBufferSubData,CHROMIUM,map_sub}
|
||
|
13 years ago
|
* @requires_gles20 Not available in ES 3.0 or desktop OpenGL. Use
|
||
|
|
* @ref Magnum::Buffer::map(GLintptr, GLsizeiptr, MapFlags) "map(GLintptr, GLsizeiptr, MapFlags)"
|
||
|
|
* instead.
|
||
|
|
* @requires_es_extension %Extension @es_extension{CHROMIUM,map_sub}
|
||
|
|
*/
|
||
|
|
void* mapSub(GLintptr offset, GLsizeiptr length, MapAccess access);
|
||
|
|
#endif
|
||
|
|
|
||
|
14 years ago
|
/**
|
||
|
|
* @brief Map buffer to client memory
|
||
|
|
* @param offset Offset into the buffer
|
||
|
|
* @param length Length of the mapped memory
|
||
|
13 years ago
|
* @param flags Flags. At least @ref MapFlag::Read or
|
||
|
|
* @ref MapFlag::Write must be specified.
|
||
|
14 years ago
|
* @return Pointer to buffer data
|
||
|
|
*
|
||
|
|
* If @extension{EXT,direct_state_access} is not available and the
|
||
|
|
* buffer is not already bound somewhere, it is bound to hinted target
|
||
|
|
* before the operation.
|
||
|
13 years ago
|
* @see @ref minMapAlignment(), @ref flushMappedRange(), @ref unmap(),
|
||
|
|
* @ref map(MapAccess), @ref setTargetHint(), @fn_gl{BindBuffer}
|
||
|
14 years ago
|
* and @fn_gl{MapBufferRange} or @fn_gl_extension{MapNamedBufferRange,EXT,direct_state_access}
|
||
|
|
* @requires_gl30 %Extension @extension{ARB,map_buffer_range}
|
||
|
|
* @requires_gles30 %Extension @es_extension{EXT,map_buffer_range}
|
||
|
|
*/
|
||
|
13 years ago
|
void* map(GLintptr offset, GLsizeiptr length, MapFlags flags) {
|
||
|
14 years ago
|
return (this->*mapRangeImplementation)(offset, length, flags);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Flush mapped range
|
||
|
|
* @param offset Offset relative to start of mapped range
|
||
|
|
* @param length Length of the flushed memory
|
||
|
13 years ago
|
* @return Reference to self (for method chaining)
|
||
|
14 years ago
|
*
|
||
|
|
* Flushes specified subsection of mapped range. Use only if you called
|
||
|
13 years ago
|
* @ref map() with @ref MapFlag::FlushExplicit flag. See
|
||
|
14 years ago
|
* @ref Buffer-data-mapping "class documentation" for usage example.
|
||
|
|
*
|
||
|
|
* If @extension{EXT,direct_state_access} is not available and the
|
||
|
|
* buffer is not already bound somewhere, it is bound to hinted target
|
||
|
|
* before the operation.
|
||
|
13 years ago
|
* @see @ref setTargetHint(), @fn_gl{BindBuffer} and @fn_gl{FlushMappedBufferRange}
|
||
|
14 years ago
|
* or @fn_gl_extension{FlushMappedNamedBufferRange,EXT,direct_state_access}
|
||
|
|
* @requires_gl30 %Extension @extension{ARB,map_buffer_range}
|
||
|
|
* @requires_gles30 %Extension @es_extension{EXT,map_buffer_range}
|
||
|
|
*/
|
||
|
13 years ago
|
Buffer& flushMappedRange(GLintptr offset, GLsizeiptr length) {
|
||
|
14 years ago
|
(this->*flushMappedRangeImplementation)(offset, length);
|
||
|
13 years ago
|
return *this;
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Unmap buffer
|
||
|
|
* @return `False` if the data have become corrupt during the time
|
||
|
|
* the buffer was mapped (e.g. after screen was resized), `true`
|
||
|
|
* otherwise.
|
||
|
|
*
|
||
|
13 years ago
|
* Unmaps buffer previously mapped with @ref map(), invalidating the
|
||
|
14 years ago
|
* pointer returned by these functions. If @extension{EXT,direct_state_access}
|
||
|
|
* is not available and the buffer is not already bound somewhere, it
|
||
|
|
* is bound to hinted target before the operation.
|
||
|
|
* @see setTargetHint(), @fn_gl{BindBuffer} and @fn_gl{UnmapBuffer} or
|
||
|
|
* @fn_gl_extension{UnmapNamedBuffer,EXT,direct_state_access}
|
||
|
|
* @requires_gles30 %Extension @es_extension{OES,mapbuffer}
|
||
|
|
*/
|
||
|
13 years ago
|
bool unmap() {
|
||
|
14 years ago
|
return (this->*unmapImplementation)();
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
#if defined(MAGNUM_TARGET_GLES2) || defined(DOXYGEN_GENERATING_OUTPUT)
|
||
|
|
/**
|
||
|
|
* @brief Unmap portion of buffer
|
||
|
|
*
|
||
|
13 years ago
|
* Unmaps portion of buffer previously mapped with @ref mapSub(),
|
||
|
13 years ago
|
* invalidating the pointer returned by the function.
|
||
|
|
* @see @fn_gl_extension{UnmapBufferSubData,CHROMIUM,map_sub}
|
||
|
|
* @requires_gles20 Not available in ES 3.0 or desktop OpenGL. Use
|
||
|
|
* @ref Magnum::Buffer::map(GLintptr, GLsizeiptr, MapFlags) "map(GLintptr, GLsizeiptr, MapFlags)"
|
||
|
|
* instead.
|
||
|
|
* @requires_es_extension %Extension @es_extension{CHROMIUM,map_sub}
|
||
|
|
*/
|
||
|
|
void unmapSub();
|
||
|
|
#endif
|
||
|
|
|
||
|
16 years ago
|
private:
|
||
|
13 years ago
|
static void MAGNUM_LOCAL initializeContextBasedFunctionality(Context& context);
|
||
|
14 years ago
|
|
||
|
14 years ago
|
static void bind(Target hint, GLuint id);
|
||
|
14 years ago
|
Target MAGNUM_LOCAL bindInternal(Target hint);
|
||
|
14 years ago
|
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
13 years ago
|
typedef void(*CopyImplementation)(Buffer&, Buffer&, GLintptr, GLintptr, GLsizeiptr);
|
||
|
|
static void MAGNUM_LOCAL copyImplementationDefault(Buffer& read, Buffer& write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
static void MAGNUM_LOCAL copyImplementationDSA(Buffer& read, Buffer& write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
static CopyImplementation copyImplementation;
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
13 years ago
|
typedef void(Buffer::*GetParameterImplementation)(GLenum, GLint*);
|
||
|
|
void MAGNUM_LOCAL getParameterImplementationDefault(GLenum value, GLint* data);
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
void MAGNUM_LOCAL getParameterImplementationDSA(GLenum value, GLint* data);
|
||
|
|
#endif
|
||
|
|
static MAGNUM_LOCAL GetParameterImplementation getParameterImplementation;
|
||
|
|
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
typedef void(Buffer::*GetSubDataImplementation)(GLintptr, GLsizeiptr, GLvoid*);
|
||
|
|
void MAGNUM_LOCAL getSubDataImplementationDefault(GLintptr offset, GLsizeiptr size, GLvoid* data);
|
||
|
|
void MAGNUM_LOCAL getSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, GLvoid* data);
|
||
|
13 years ago
|
static GetSubDataImplementation getSubDataImplementation;
|
||
|
13 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
13 years ago
|
typedef void(Buffer::*DataImplementation)(GLsizeiptr, const GLvoid*, BufferUsage);
|
||
|
|
void MAGNUM_LOCAL dataImplementationDefault(GLsizeiptr size, const GLvoid* data, BufferUsage usage);
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
void MAGNUM_LOCAL dataImplementationDSA(GLsizeiptr size, const GLvoid* data, BufferUsage usage);
|
||
|
14 years ago
|
#endif
|
||
|
13 years ago
|
static DataImplementation dataImplementation;
|
||
|
14 years ago
|
|
||
|
13 years ago
|
typedef void(Buffer::*SubDataImplementation)(GLintptr, GLsizeiptr, const GLvoid*);
|
||
|
|
void MAGNUM_LOCAL subDataImplementationDefault(GLintptr offset, GLsizeiptr size, const GLvoid* data);
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
void MAGNUM_LOCAL subDataImplementationDSA(GLintptr offset, GLsizeiptr size, const GLvoid* data);
|
||
|
14 years ago
|
#endif
|
||
|
13 years ago
|
static SubDataImplementation subDataImplementation;
|
||
|
14 years ago
|
|
||
|
14 years ago
|
typedef void(Buffer::*InvalidateImplementation)();
|
||
|
|
void MAGNUM_LOCAL invalidateImplementationNoOp();
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
void MAGNUM_LOCAL invalidateImplementationARB();
|
||
|
|
#endif
|
||
|
|
static InvalidateImplementation invalidateImplementation;
|
||
|
|
|
||
|
|
typedef void(Buffer::*InvalidateSubImplementation)(GLintptr, GLsizeiptr);
|
||
|
|
void MAGNUM_LOCAL invalidateSubImplementationNoOp(GLintptr offset, GLsizeiptr length);
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
void MAGNUM_LOCAL invalidateSubImplementationARB(GLintptr offset, GLsizeiptr length);
|
||
|
|
#endif
|
||
|
|
static InvalidateSubImplementation invalidateSubImplementation;
|
||
|
|
|
||
|
14 years ago
|
typedef void*(Buffer::*MapImplementation)(MapAccess);
|
||
|
|
void MAGNUM_LOCAL * mapImplementationDefault(MapAccess access);
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
void MAGNUM_LOCAL * mapImplementationDSA(MapAccess access);
|
||
|
|
#endif
|
||
|
|
static MapImplementation mapImplementation;
|
||
|
|
|
||
|
|
typedef void*(Buffer::*MapRangeImplementation)(GLintptr, GLsizeiptr, MapFlags);
|
||
|
|
void MAGNUM_LOCAL * mapRangeImplementationDefault(GLintptr offset, GLsizeiptr length, MapFlags access);
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
void MAGNUM_LOCAL * mapRangeImplementationDSA(GLintptr offset, GLsizeiptr length, MapFlags access);
|
||
|
|
#endif
|
||
|
|
static MapRangeImplementation mapRangeImplementation;
|
||
|
|
|
||
|
|
typedef void(Buffer::*FlushMappedRangeImplementation)(GLintptr, GLsizeiptr);
|
||
|
|
void MAGNUM_LOCAL flushMappedRangeImplementationDefault(GLintptr offset, GLsizeiptr length);
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
void MAGNUM_LOCAL flushMappedRangeImplementationDSA(GLintptr offset, GLsizeiptr length);
|
||
|
|
#endif
|
||
|
|
static FlushMappedRangeImplementation flushMappedRangeImplementation;
|
||
|
|
|
||
|
|
typedef bool(Buffer::*UnmapImplementation)();
|
||
|
|
bool MAGNUM_LOCAL unmapImplementationDefault();
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
bool MAGNUM_LOCAL unmapImplementationDSA();
|
||
|
|
#endif
|
||
|
|
static UnmapImplementation unmapImplementation;
|
||
|
|
|
||
|
14 years ago
|
GLuint _id;
|
||
|
14 years ago
|
Target _targetHint;
|
||
|
13 years ago
|
#ifdef CORRADE_TARGET_NACL
|
||
|
|
void* _mappedBuffer;
|
||
|
|
#endif
|
||
|
16 years ago
|
};
|
||
|
|
|
||
|
14 years ago
|
CORRADE_ENUMSET_OPERATORS(Buffer::MapFlags)
|
||
|
|
|
||
|
13 years ago
|
/** @debugoperator{Magnum::Buffer} */
|
||
|
|
Debug MAGNUM_EXPORT operator<<(Debug debug, Buffer::Target value);
|
||
|
|
|
||
|
13 years ago
|
inline Buffer::Buffer(Buffer&& other) noexcept: _id(other._id), _targetHint(other._targetHint) {
|
||
|
|
other._id = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline Buffer& Buffer::operator=(Buffer&& other) noexcept {
|
||
|
|
std::swap(_id, other._id);
|
||
|
|
std::swap(_targetHint, other._targetHint);
|
||
|
|
return *this;
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
template<class T> Containers::Array<T> inline Buffer::data() {
|
||
|
|
const Int bufferSize = size();
|
||
|
13 years ago
|
CORRADE_ASSERT(bufferSize%sizeof(T) == 0, "Buffer::data(): the buffer size is" << bufferSize << "bytes, which can't be expressed as array of types with size" << sizeof(T), nullptr);
|
||
|
13 years ago
|
return subData<T>(0, bufferSize/sizeof(T));
|
||
|
|
}
|
||
|
|
|
||
|
|
template<class T> Containers::Array<T> inline Buffer::subData(const GLintptr offset, const GLsizeiptr size) {
|
||
|
|
Containers::Array<T> data(size);
|
||
|
|
if(size) (this->*getSubDataImplementation)(offset, size*sizeof(T), data);
|
||
|
|
return std::move(data);
|
||
|
|
}
|
||
|
|
#endif
|
||
|
|
|
||
|
16 years ago
|
}
|
||
|
|
|
||
|
|
#endif
|