Magnum::GL::Buffer class

Buffer.

Wraps an OpenGL buffer object.

Data upload

Data can be uploaded to the buffer with setData(), setSubData() or the shorthand Buffer() constructor. All these functions accept a Containers::ArrayView, which is among other things implicitly convertible from statically sized C arrays or can be constructed from a pair of a pointer and a size. You can optionally specify a usage hint in the second argument, which defaults to BufferUsage::StaticDraw.

const Vector3 data[]{
    
};

GL::Buffer buffer;
buffer.setData(data);

GL::Buffer buffer2{data}; // or construct & fill in a single step

Furthermore, if you #include Corrade/Containers/ArrayViewStl.h, you can also directly pass STL types such as a std::vector or a std::array; with Corrade/Containers/ArrayViewStlSpan.h the std::span is convertible to it as well:

std::vector<Vector3> data = ;
buffer.setData(data);

An alternative to setData() that provides more flexibility and better performance guarantees is setStorage(). It's similar in spirit to texture storage, however as it's only available on desktop OpenGL 4.4 ( ARB_buffer_storage), its usage isn't encouraged like with textures. The minimal variant of the call shown below creates an immutable buffer from given data in device memory, in the second argument you can specify StorageFlags that make it CPU-accessible, (persistently) mappable etc.

GL::Buffer buffer;
buffer.setStorage(data, {});

Memory mapping

Buffer data can be also updated asynchronously. First you need to allocate the buffer to desired size by passing nullptr to setData(), e.g.:

buffer.setData({nullptr, 200*sizeof(Vector3)});

Then you can map the buffer to client memory and operate with the memory directly. After you are done with the operation, call unmap() to unmap the buffer again. The map() functions return a view on a char array and you may want to cast it to some useful type first using Containers::arrayCast():

Containers::ArrayView<Vector3> data = Containers::arrayCast<Vector3>(
    buffer.map(0, 200*sizeof(Vector3),
        GL::Buffer::MapFlag::Write|GL::Buffer::MapFlag::InvalidateBuffer));
CORRADE_INTERNAL_ASSERT(data);
for(Vector3& d: data)
    d = {/*...*/};
CORRADE_INTERNAL_ASSERT_OUTPUT(buffer.unmap());

If you are updating only a few discrete portions of the buffer, you can use MapFlag::FlushExplicit and flushMappedRange() to reduce number of memory operations performed by OpenGL on unmapping. Example:

Containers::ArrayView<Vector3> data = Containers::arrayCast<Vector3>(
    buffer.map(0, 200*sizeof(Vector3),
        GL::Buffer::MapFlag::Write|GL::Buffer::MapFlag::FlushExplicit));
CORRADE_INTERNAL_ASSERT(data);
for(std::size_t i: {7, 27, 56, 128}) {
    data[i] = {/*...*/};
    buffer.flushMappedRange(i*sizeof(Vector3), sizeof(Vector3));
}
CORRADE_INTERNAL_ASSERT_OUTPUT(buffer.unmap());

WebGL restrictions

Buffers in WebGL need to be bound only to one unique target, i.e., Buffer bound to Buffer::TargetHint::Array cannot be later rebound to Buffer::TargetHint::ElementArray. However, Magnum by default uses any sufficient target when binding the buffer internally (e.g. for setting data). Which means the following, while completely fine on desktop and OpenGL ES, is not sufficient on WebGL:

GL::Buffer vertices;
GL::Buffer indices;

To avoid GL errors, you have to set target hint to desired target, either in the constructor or using setTargetHint(). A similar care needs to be taken for uniform buffers and other types of buffers.

GL::Buffer vertices{GL::Buffer::TargetHint::Array};
GL::Buffer indices{GL::Buffer::TargetHint::ElementArray};

To simplify debugging, the Mesh class checks proper target hint when adding vertex and index buffers under WebGL.

Performance optimizations

The engine tracks currently bound buffers to avoid unnecessary calls to glBindBuffer(). If the buffer is already bound to some target, functions copy(), setStorage(), setData(), setSubData(), map(), mapRead(), flushMappedRange() and unmap() use that target instead of binding the buffer to some specific target. You can also use setTargetHint() to possibly reduce unnecessary rebinding. Buffer limits and implementation-defined values (such as maxUniformBindings()) are cached, so repeated queries don't result in repeated glGet() calls. See also Context::resetState() and Context::State::Buffers.

If ARB_direct_state_access (part of OpenGL 4.5) is available, functions copy(), setStorage(), size(), data(), subData(), setData(), setSubData(), map(), mapRead(), flushMappedRange() and unmap() use DSA functions to avoid unnecessary calls to glBindBuffer(). See their respective documentation for more information.

You can use functions invalidateData() and 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 ARB_invalidate_subdata (part of OpenGL 4.3) is not available, these functions do nothing.

Base classes

class AbstractObject
Base for all OpenGL objects.

Public types

enum class TargetHint: UnsignedShort { Array = GL_ARRAY_BUFFER, AtomicCounter = GL_ATOMIC_COUNTER_BUFFER, CopyRead = GL_COPY_READ_BUFFER, CopyWrite = GL_COPY_WRITE_BUFFER, DispatchIndirect = GL_DISPATCH_INDIRECT_BUFFER, DrawIndirect = GL_DRAW_INDIRECT_BUFFER, ElementArray = GL_ELEMENT_ARRAY_BUFFER, PixelPack = GL_PIXEL_PACK_BUFFER, PixelUnpack = GL_PIXEL_UNPACK_BUFFER, ShaderStorage = GL_SHADER_STORAGE_BUFFER, Texture = GL_TEXTURE_BUFFER, TransformFeedback = GL_TRANSFORM_FEEDBACK_BUFFER, Uniform = GL_UNIFORM_BUFFER }
Buffer target.
enum class Target: GLenum { AtomicCounter = GL_ATOMIC_COUNTER_BUFFER, ShaderStorage = GL_SHADER_STORAGE_BUFFER, Uniform = GL_UNIFORM_BUFFER }
Buffer binding target.
enum class MapAccess: GLenum { ReadOnly = GL_READ_ONLY, WriteOnly = GL_WRITE_ONLY, ReadWrite = GL_READ_WRITE }
Memory mapping access.
enum class MapFlag: GLbitfield { Read = GL_MAP_READ_BIT, Write = GL_MAP_WRITE_BIT, InvalidateBuffer = GL_MAP_INVALIDATE_BUFFER_BIT, InvalidateRange = GL_MAP_INVALIDATE_RANGE_BIT, FlushExplicit = GL_MAP_FLUSH_EXPLICIT_BIT, Unsynchronized = GL_MAP_UNSYNCHRONIZED_BIT, Persistent = GL_MAP_PERSISTENT_BIT new in Git master, Coherent = GL_MAP_COHERENT_BIT new in Git master }
Memory mapping flag.
enum class StorageFlag: GLbitfield { MapRead = GL_MAP_READ_BIT, MapWrite = GL_MAP_WRITE_BIT, MapPersistent = GL_MAP_PERSISTENT_BIT, MapCoherent = GL_MAP_COHERENT_BIT, DynamicStorage = GL_DYNAMIC_STORAGE_BIT, ClientStorage = GL_CLIENT_STORAGE_BIT } new in Git master
Buffer storage flag.
using MapFlags = Containers::EnumSet<MapFlag>
Memory mapping flags.
using StorageFlags = Containers::EnumSet<StorageFlag> new in Git master
Buffer storage flags.

Public static functions

static auto minMapAlignment() -> Int
Minimal supported mapping alignment.
static auto maxAtomicCounterBindings() -> Int
Max supported atomic counter buffer binding count.
static auto maxShaderStorageBindings() -> Int
Max supported shader storage buffer binding count.
static auto uniformOffsetAlignment() -> Int
Alignment of uniform buffer binding offset.
static auto shaderStorageOffsetAlignment() -> Int
Alignment of shader storage buffer binding offset.
static auto maxUniformBindings() -> Int
Max supported uniform buffer binding count.
static void unbind(Target target, UnsignedInt index)
Unbind any buffer from given indexed target.
static void unbind(Target target, UnsignedInt firstIndex, std::size_t count)
Unbind given range of indexed targets.
static void bind(Target target, UnsignedInt firstIndex, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers) new in Git master
Bind ranges of buffers to given range of indexed targets.
static void bind(Target target, UnsignedInt firstIndex, std::initializer_list<Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers) new in Git master
static void bind(Target target, UnsignedInt firstIndex, Containers::ArrayView<Buffer*const> buffers) new in Git master
Bind buffers to given range of indexed targets.
static void bind(Target target, UnsignedInt firstIndex, std::initializer_list<Buffer*> buffers)
static void copy(Buffer& read, Buffer& write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)
Copy one buffer to another.
static auto wrap(GLuint id, TargetHint targetHint = TargetHint::Array, ObjectFlags flags = {}) -> Buffer
Wrap existing OpenGL buffer object.
static auto wrap(GLuint id, ObjectFlags flags) -> Buffer

Constructors, destructors, conversion operators

Buffer(TargetHint targetHint = TargetHint::Array) explicit
Constructor.
Buffer(NoCreateT) explicit noexcept
Construct without creating the underlying OpenGL object.
Buffer(TargetHint targetHint, Containers::ArrayView<const void> data, BufferUsage usage = BufferUsage::StaticDraw) explicit new in 2020.06
Construct and directly fill with data.
template<class T>
Buffer(TargetHint targetHint, std::initializer_list<T> data, BufferUsage usage = BufferUsage::StaticDraw) explicit new in 2020.06
Buffer(Containers::ArrayView<const void> data, BufferUsage usage = BufferUsage::StaticDraw) explicit new in 2020.06
Buffer(const Buffer&) deleted
Copying is not allowed.
Buffer(Buffer&& other) noexcept
Move constructor.
~Buffer()
Destructor.

Public functions

auto operator=(const Buffer&) -> Buffer& deleted
Copying is not allowed.
auto operator=(Buffer&& other) -> Buffer& noexcept
Move assignment.
auto id() const -> GLuint
OpenGL buffer ID.
auto release() -> GLuint
Release OpenGL object.
auto label() -> Containers::String
Buffer label.
auto setLabel(Containers::StringView label) -> Buffer&
Set buffer label.
auto targetHint() const -> TargetHint
Target hint.
auto setTargetHint(TargetHint hint) -> Buffer&
Set target hint.
auto bind(Target target, UnsignedInt index, GLintptr offset, GLsizeiptr size) -> Buffer&
Bind buffer range to given binding index.
auto bind(Target target, UnsignedInt index) -> Buffer&
Bind buffer to given binding index.
auto setStorage(Containers::ArrayView<const void> data, StorageFlags flags) -> Buffer& new in Git master
Set storage.
auto setStorage(std::size_t size, StorageFlags flags) -> Buffer& new in Git master
Set storage.
auto size() -> Int
Buffer size in bytes.
auto data() -> Containers::Array<char>
Buffer data.
auto subData(GLintptr offset, GLsizeiptr size) -> Containers::Array<char>
Buffer subdata.
auto setData(Containers::ArrayView<const void> data, BufferUsage usage = BufferUsage::StaticDraw) -> Buffer&
Set buffer data.
template<class T>
auto setData(std::initializer_list<T> data, BufferUsage usage = BufferUsage::StaticDraw) -> Buffer& new in 2019.10
auto setSubData(GLintptr offset, Containers::ArrayView<const void> data) -> Buffer&
Set buffer subdata.
template<class T>
auto setSubData(GLintptr offset, std::initializer_list<T> data) -> Buffer& new in 2019.10
auto invalidateData() -> Buffer&
Invalidate buffer data.
auto invalidateSubData(GLintptr offset, GLsizeiptr length) -> Buffer&
Invalidate buffer subdata.
auto map(MapAccess access) -> char*
Map buffer to client memory.
auto mapRead() -> const char*
Map buffer read-only to client memory.
auto map(GLintptr offset, GLsizeiptr length, MapFlags flags) -> Containers::ArrayView<char>
Map buffer to client memory.
auto mapRead(GLintptr offset, GLsizeiptr length, MapFlags flags = {}) -> Containers::ArrayView<const char>
Map buffer read-only to client memory.
auto flushMappedRange(GLintptr offset, GLsizeiptr length) -> Buffer&
Flush mapped range.
auto unmap() -> bool
Unmap buffer.

Enum documentation

enum class Magnum::GL::Buffer::TargetHint: UnsignedShort

Buffer target.

Enumerators
Array

Used for storing vertex attributes.

AtomicCounter

Used for storing atomic counters.

CopyRead

Source for copies. See copy().

CopyWrite

Target for copies. See copy().

DispatchIndirect

Indirect compute dispatch commands.

DrawIndirect

Used for supplying arguments for indirect drawing.

ElementArray

Used for storing vertex indices.

PixelPack

Target for pixel pack operations.

PixelUnpack

Source for texture update operations.

ShaderStorage

Used for shader storage.

Texture

Source for texel fetches. See BufferTexture.

TransformFeedback

Target for transform feedback.

Uniform

Used for storing uniforms.

enum class Magnum::GL::Buffer::Target: GLenum

Buffer binding target.

Enumerators
AtomicCounter

Atomic counter binding

ShaderStorage

Shader storage binding

Uniform

Uniform binding

enum class Magnum::GL::Buffer::MapAccess: GLenum

Memory mapping access.

Enumerators
ReadOnly

Map buffer for reading only.

WriteOnly

Map buffer for writing only.

ReadWrite

Map buffer for both reading and writing.

enum class Magnum::GL::Buffer::MapFlag: GLbitfield

Memory mapping flag.

Enumerators
Read

Map buffer for reading.

Write

Map buffer for writing.

InvalidateBuffer

Previous contents of the entire buffer may be discarded. May not be used in combination with MapFlag::Read.

InvalidateRange

Previous contents of mapped range may be discarded. May not be used in combination with MapFlag::Read.

FlushExplicit

Only one or more discrete subranges of the mapping will be modified. See flushMappedRange() for more information. May only be used in conjunction with MapFlag::Write.

Unsynchronized

No pending operations on the buffer should be synchronized before mapping.

Persistent new in Git master

Allow reading from or writing to the buffer while it is mapped.

Coherent new in Git master

Shared access to buffer that's both mapped and used will be coherent.

enum class Magnum::GL::Buffer::StorageFlag: GLbitfield new in Git master

Buffer storage flag.

Enumerators
MapRead

Allow the buffer to be mapped with MapFlag::Read.

MapWrite

Allow the buffer to be mapped with MapFlag::Write.

MapPersistent

Allow the buffer to be mapped with MapFlag::Persistent.

MapCoherent

Allow the buffer to be mapped with MapFlag::Coherent.

DynamicStorage

Allow the buffer to be updated with setSubData(). Note that the buffer can still be updated through copy() even without this flag present.

ClientStorage

Prefer to allocate the memory in client memory space.

Typedef documentation

typedef Containers::EnumSet<MapFlag> Magnum::GL::Buffer::MapFlags

Memory mapping flags.

typedef Containers::EnumSet<StorageFlag> Magnum::GL::Buffer::StorageFlags new in Git master

Buffer storage flags.

Function documentation

static Int Magnum::GL::Buffer::minMapAlignment()

Minimal supported mapping alignment.

The result is cached, repeated queries don't result in repeated OpenGL calls. If extension ARB_map_buffer_alignment (part of OpenGL 4.2) is not available, returns 1.

static Int Magnum::GL::Buffer::maxAtomicCounterBindings()

Max supported atomic counter buffer binding count.

The result is cached, repeated queries don't result in repeated OpenGL calls. If neither extension ARB_shader_atomic_counters (part of OpenGL 4.2) nor OpenGL ES 3.1 is available, returns 0.

static Int Magnum::GL::Buffer::maxShaderStorageBindings()

Max supported shader storage buffer binding count.

The result is cached, repeated queries don't result in repeated OpenGL calls. If neither extension ARB_shader_storage_buffer_object (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns 0.

static Int Magnum::GL::Buffer::uniformOffsetAlignment()

Alignment of uniform buffer binding offset.

The result is cached, repeated queries don't result in repeated OpenGL calls. If extension ARB_uniform_buffer_object (part of OpenGL 3.1) is not available, returns 1.

static Int Magnum::GL::Buffer::shaderStorageOffsetAlignment()

Alignment of shader storage buffer binding offset.

The result is cached, repeated queries don't result in repeated OpenGL calls. If neither extension ARB_shader_storage_buffer_object (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns 1.

static Int Magnum::GL::Buffer::maxUniformBindings()

Max supported uniform buffer binding count.

The result is cached, repeated queries don't result in repeated OpenGL calls. If extension ARB_uniform_buffer_object (part of OpenGL 3.1) is not available, returns 0.

static void Magnum::GL::Buffer::unbind(Target target, UnsignedInt index)

Unbind any buffer from given indexed target.

The index parameter must respect limits for given target.

static void Magnum::GL::Buffer::unbind(Target target, UnsignedInt firstIndex, std::size_t count)

Unbind given range of indexed targets.

Unbinds all buffers in given target in range $ [ firstIndex ; firstIndex + count ] $ . The range of indices must respect limits for given target. If ARB_multi_bind (part of OpenGL 4.4) is not available, the feature is emulated with sequence of unbind(Target, UnsignedInt) calls.

static void Magnum::GL::Buffer::bind(Target target, UnsignedInt firstIndex, Containers::ArrayView<const Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers) new in Git master

Bind ranges of buffers to given range of indexed targets.

Binds first buffer in the list to firstIndex, second to firstIndex + 1 etc. Second parameter is offset, third is size. If any buffer is nullptr, given indexed target is unbound. The range of indices must respect limits for given target. The offsets must respect alignment, which is 4 bytes for Target::AtomicCounter and implementation-defined for other targets. All the buffers must have allocated data store. If ARB_multi_bind (part of OpenGL 4.4) is not available, the feature is emulated with sequence of bind(Target, UnsignedInt, GLintptr, GLsizeiptr) / unbind(Target, UnsignedInt) calls.

static void Magnum::GL::Buffer::bind(Target target, UnsignedInt firstIndex, std::initializer_list<Containers::Triple<Buffer*, GLintptr, GLsizeiptr>> buffers) new in Git master

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

static void Magnum::GL::Buffer::bind(Target target, UnsignedInt firstIndex, Containers::ArrayView<Buffer*const> buffers) new in Git master

Bind buffers to given range of indexed targets.

Binds first buffer in the list to firstIndex, second to firstIndex + 1 etc. If any buffer is nullptr, given indexed target is unbound. The range of indices must respect limits for given target. All the buffers must have allocated data store. If ARB_multi_bind (part of OpenGL 4.4) is not available, the feature is emulated with sequence of bind(Target, UnsignedInt) / unbind(Target, UnsignedInt) calls.

static void Magnum::GL::Buffer::bind(Target target, UnsignedInt firstIndex, std::initializer_list<Buffer*> buffers)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

static void Magnum::GL::Buffer::copy(Buffer& read, Buffer& write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size)

Copy one buffer to another.

Parameters
read Buffer from which to read
write Buffer to which to copy
readOffset Offset in the read buffer
writeOffset Offset in the write buffer
size Data size

If ARB_direct_state_access (part of OpenGL 4.5) is not available, read buffer is bound for reading and write buffer is bound for writing before the copy is performed (if not already).

static Buffer Magnum::GL::Buffer::wrap(GLuint id, TargetHint targetHint = TargetHint::Array, ObjectFlags flags = {})

Wrap existing OpenGL buffer object.

Parameters
id OpenGL buffer ID
targetHint Target hint, see setTargetHint() for more information
flags Object creation flags

The id is expected to be of an existing OpenGL buffer object. Unlike buffer created using constructor, the OpenGL object is by default not deleted on destruction, use flags for different behavior.

static Buffer Magnum::GL::Buffer::wrap(GLuint id, ObjectFlags flags)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Magnum::GL::Buffer::Buffer(TargetHint targetHint = TargetHint::Array) explicit

Constructor.

Parameters
targetHint Target hint, see setTargetHint() for more information

Creates new OpenGL buffer object. If ARB_direct_state_access (part of OpenGL 4.5) is not available, the buffer is created on first use.

Magnum::GL::Buffer::Buffer(NoCreateT) explicit noexcept

Construct without creating the underlying OpenGL object.

The constructed instance is equivalent to moved-from state. Useful in cases where you will overwrite the instance later anyway. Move another object over it to make it useful.

This function can be safely used for constructing (and later destructing) objects even without any OpenGL context being active. However note that this is a low-level and a potentially dangerous API, see the documentation of NoCreate for alternatives.

Magnum::GL::Buffer::Buffer(TargetHint targetHint, Containers::ArrayView<const void> data, BufferUsage usage = BufferUsage::StaticDraw) explicit new in 2020.06

Construct and directly fill with data.

Parameters
targetHint Target hint, see setTargetHint() for more information
data Data
usage Buffer usage

Equivalent to constructing via Buffer(TargetHint) and then calling setData().

template<class T>
Magnum::GL::Buffer::Buffer(TargetHint targetHint, std::initializer_list<T> data, BufferUsage usage = BufferUsage::StaticDraw) explicit new in 2020.06

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Magnum::GL::Buffer::Buffer(Containers::ArrayView<const void> data, BufferUsage usage = BufferUsage::StaticDraw) explicit new in 2020.06

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Equivalent to calling Buffer(TargetHint, Containers::ArrayView<const void>, BufferUsage) with TargetHint::Array. Unlike with Buffer(TargetHint, std::initializer_list<T>, BufferUsage) an std::initializer_list overload isn't provided in this case as it would cause a lot of undesired implicit conversions when using the {}-style construction. Use the above overload or the Corrade::Containers::arrayView(std::initializer_list<T>) helper instead.

Magnum::GL::Buffer::~Buffer()

Destructor.

Deletes associated OpenGL buffer object.

GLuint Magnum::GL::Buffer::release()

Release OpenGL object.

Releases ownership of OpenGL buffer object and returns its ID so it is not deleted on destruction. The internal state is then equivalent to moved-from state.

Containers::String Magnum::GL::Buffer::label()

Buffer label.

The result is not cached, repeated queries will result in repeated OpenGL calls. If OpenGL 4.3 / OpenGL ES 3.2 is not supported and neither KHR_debug (covered also by ANDROID_extension_pack_es31a) nor EXT_debug_label desktop or ES extension is available, this function returns empty string.

Buffer& Magnum::GL::Buffer::setLabel(Containers::StringView label)

Set buffer label.

Returns Reference to self (for method chaining)

Default is empty string. If OpenGL 4.3 / OpenGL ES 3.2 is not supported and neither KHR_debug (covered also by ANDROID_extension_pack_es31a) nor EXT_debug_label desktop or ES extension is available, this function does nothing.

Buffer& Magnum::GL::Buffer::setTargetHint(TargetHint hint)

Set target hint.

Returns Reference to self (for method chaining)

If ARB_direct_state_access (part of OpenGL 4.5) is not available, the buffer needs to be internally bound to some target before any operation. You can specify target which will always be used when binding the buffer internally, possibly saving some calls to glBindBuffer(). Default target hint is TargetHint::Array.

Buffer& Magnum::GL::Buffer::bind(Target target, UnsignedInt index, GLintptr offset, GLsizeiptr size)

Bind buffer range to given binding index.

The index parameter must respect limits for given target. The offset parameter must respect alignment, which is 4 bytes for Target::AtomicCounter and implementation-defined for other targets. The buffer must have allocated data store.

Buffer& Magnum::GL::Buffer::bind(Target target, UnsignedInt index)

Bind buffer to given binding index.

The index parameter must respect limits for given target. The buffer must have allocated data store.

Buffer& Magnum::GL::Buffer::setStorage(Containers::ArrayView<const void> data, StorageFlags flags) new in Git master

Set storage.

Parameters
data Data
flags Storage flags

If ARB_direct_state_access (part of OpenGL 4.5) is not available, the buffer is bound to hinted target before the operation (if not already).

Buffer& Magnum::GL::Buffer::setStorage(std::size_t size, StorageFlags flags) new in Git master

Set storage.

Parameters
size Size in bytes
flags Storage flags

Equivalent to calling setStorage(Containers::ArrayView<const void>, StorageFlags) with a nullptr view of size bytes.

Int Magnum::GL::Buffer::size()

Buffer size in bytes.

If ARB_direct_state_access (part of OpenGL 4.5) is not available, the buffer is bound to hinted target before the operation (if not already).

Containers::Array<char> Magnum::GL::Buffer::data()

Buffer data.

Returns data of whole buffer. If ARB_direct_state_access (part of OpenGL 4.5) is not available, the buffer is bound to hinted target before the operation (if not already).

Containers::Array<char> Magnum::GL::Buffer::subData(GLintptr offset, GLsizeiptr size)

Buffer subdata.

Parameters
offset Byte offset in the buffer
size Data size in bytes

Returns data of given buffer portion. If ARB_direct_state_access (part of OpenGL 4.5) is not available, the buffer is bound to hinted target before the operation (if not already).

Buffer& Magnum::GL::Buffer::setData(Containers::ArrayView<const void> data, BufferUsage usage = BufferUsage::StaticDraw)

Set buffer data.

Parameters
data Data
usage Buffer usage
Returns Reference to self (for method chaining)

If ARB_direct_state_access (part of OpenGL 4.5) is not available, the buffer is bound to hinted target before the operation (if not already).

template<class T>
Buffer& Magnum::GL::Buffer::setData(std::initializer_list<T> data, BufferUsage usage = BufferUsage::StaticDraw) new in 2019.10

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Buffer& Magnum::GL::Buffer::setSubData(GLintptr offset, Containers::ArrayView<const void> data)

Set buffer subdata.

Parameters
offset Byte offset in the buffer
data Data
Returns Reference to self (for method chaining)

If ARB_direct_state_access (part of OpenGL 4.5) is not available, the buffer is bound to hinted target before the operation (if not already).

template<class T>
Buffer& Magnum::GL::Buffer::setSubData(GLintptr offset, std::initializer_list<T> data) new in 2019.10

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Buffer& Magnum::GL::Buffer::invalidateData()

Invalidate buffer data.

Returns Reference to self (for method chaining)

If running on OpenGL ES or extension ARB_invalidate_subdata (part of OpenGL 4.3) is not available, this function does nothing.

Buffer& Magnum::GL::Buffer::invalidateSubData(GLintptr offset, GLsizeiptr length)

Invalidate buffer subdata.

Parameters
offset Byte offset into the buffer
length Length of the invalidated range
Returns Reference to self (for method chaining)

If running on OpenGL ES or extension ARB_invalidate_subdata (part of OpenGL 4.3) is not available, this function does nothing.

char* Magnum::GL::Buffer::map(MapAccess access)

Map buffer to client memory.

Parameters
access Access
Returns Pointer to mapped buffer data or nullptr on error

If ARB_direct_state_access (part of OpenGL 4.5) is not available, the buffer is bound to hinted target before the operation (if not already).

const char* Magnum::GL::Buffer::mapRead()

Map buffer read-only to client memory.

Equivalent to map() with MapAccess::ReadOnly.

Containers::ArrayView<char> Magnum::GL::Buffer::map(GLintptr offset, GLsizeiptr length, MapFlags flags)

Map buffer to client memory.

Parameters
offset Byte offset into the buffer
length Length of the mapped memory in bytes
flags Flags. At least MapFlag::Read or MapFlag::Write must be specified.
Returns Sized view to buffer data or nullptr on error

If ARB_direct_state_access (part of OpenGL 4.5) is not available, the buffer is bound to hinted target before the operation (if not already).

Containers::ArrayView<const char> Magnum::GL::Buffer::mapRead(GLintptr offset, GLsizeiptr length, MapFlags flags = {})

Map buffer read-only to client memory.

Equivalent to map() with MapFlag::Read added implicitly.

Buffer& Magnum::GL::Buffer::flushMappedRange(GLintptr offset, GLsizeiptr length)

Flush mapped range.

Parameters
offset Byte offset relative to start of mapped range
length Length of the flushed memory in bytes
Returns Reference to self (for method chaining)

Flushes specified subsection of mapped range. Use only if you called map() with MapFlag::FlushExplicit flag. See class documentation for usage example.

If ARB_direct_state_access (part of OpenGL 4.5) is not available, the buffer is bound to hinted target before the operation (if not already).

bool Magnum::GL::Buffer::unmap()

Unmap buffer.

Returns False if the data have become corrupt during the time the buffer was mapped (e.g. after screen was resized), true otherwise.

Unmaps buffer previously mapped with map() / mapRead(), invalidating the pointer returned by these functions. If ARB_direct_state_access (part of OpenGL 4.5) is not available, the buffer is bound to hinted target before the operation (if not already).

Debug& operator<<(Debug& debug, Buffer::TargetHint value)

Debug output operator.

Debug& operator<<(Debug& debug, Buffer::Target value)

Debug output operator.