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.
1382 lines
60 KiB
1382 lines
60 KiB
|
8 years ago
|
#ifndef Magnum_GL_Buffer_h
|
||
|
|
#define Magnum_GL_Buffer_h
|
||
|
16 years ago
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
8 years ago
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018
|
||
|
12 years ago
|
Vladimír Vondruš <mosra@centrum.cz>
|
||
|
13 years ago
|
|
||
|
|
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
|
||
|
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>
|
||
|
9 years ago
|
#include <Corrade/Containers/ArrayView.h>
|
||
|
13 years ago
|
#include <Corrade/Containers/EnumSet.h>
|
||
|
|
#include <Corrade/Utility/Assert.h>
|
||
|
14 years ago
|
|
||
|
11 years ago
|
#include "Magnum/Tags.h"
|
||
|
8 years ago
|
#include "Magnum/GL/AbstractObject.h"
|
||
|
|
#include "Magnum/GL/GL.h"
|
||
|
14 years ago
|
|
||
|
11 years ago
|
#ifdef MAGNUM_BUILD_DEPRECATED
|
||
|
9 years ago
|
#include <Corrade/Containers/Array.h>
|
||
|
11 years ago
|
#include <Corrade/Utility/Macros.h>
|
||
|
|
#endif
|
||
|
|
|
||
|
16 years ago
|
namespace Magnum {
|
||
|
|
|
||
|
13 years ago
|
/**
|
||
|
12 years ago
|
@brief Buffer usage
|
||
|
13 years ago
|
|
||
|
11 years ago
|
@see @ref Buffer, @ref Buffer::setData(Containers::ArrayView<const void>, BufferUsage)
|
||
|
8 years ago
|
@m_enum_values_as_keywords
|
||
|
13 years ago
|
*/
|
||
|
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.
|
||
|
11 years ago
|
* @requires_gles30 Only @ref BufferUsage::StreamDraw is available in
|
||
|
|
* OpenGL ES 2.0.
|
||
|
11 years ago
|
* @requires_webgl20 Only @ref BufferUsage::StreamDraw is available in
|
||
|
|
* WebGL 1.0.
|
||
|
13 years ago
|
*/
|
||
|
|
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.
|
||
|
11 years ago
|
* @requires_gles30 Only @ref BufferUsage::StreamDraw is available in
|
||
|
|
* OpenGL ES 2.0.
|
||
|
11 years ago
|
* @requires_webgl20 Only @ref BufferUsage::StreamDraw is available in
|
||
|
|
* WebGL 1.0.
|
||
|
13 years ago
|
*/
|
||
|
|
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.
|
||
|
11 years ago
|
* @requires_gles30 Only @ref BufferUsage::StaticDraw is available in
|
||
|
|
* OpenGL ES 2.0.
|
||
|
11 years ago
|
* @requires_webgl20 Only @ref BufferUsage::StaticDraw is available in
|
||
|
|
* WebGL 1.0.
|
||
|
13 years ago
|
*/
|
||
|
|
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.
|
||
|
11 years ago
|
* @requires_gles30 Only @ref BufferUsage::StaticDraw is available in
|
||
|
|
* OpenGL ES 2.0.
|
||
|
11 years ago
|
* @requires_webgl20 Only @ref BufferUsage::StaticDraw is available in
|
||
|
|
* WebGL 1.0.
|
||
|
13 years ago
|
*/
|
||
|
|
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.
|
||
|
11 years ago
|
* @requires_gles30 Only @ref BufferUsage::DynamicDraw is available in
|
||
|
|
* OpenGL ES 2.0.
|
||
|
11 years ago
|
* @requires_webgl20 Only @ref BufferUsage::DynamicDraw is available in
|
||
|
|
* WebGL 1.0.
|
||
|
13 years ago
|
*/
|
||
|
|
DynamicRead = GL_DYNAMIC_READ,
|
||
|
|
|
||
|
|
/**
|
||
|
13 years ago
|
* Updated frequently as output from OpenGL command and used frequently for
|
||
|
|
* drawing or copying to other images.
|
||
|
11 years ago
|
* @requires_gles30 Only @ref BufferUsage::DynamicDraw is available in
|
||
|
|
* OpenGL ES 2.0.
|
||
|
11 years ago
|
* @requires_webgl20 Only @ref BufferUsage::DynamicDraw is available in
|
||
|
|
* WebGL 1.0.
|
||
|
13 years ago
|
*/
|
||
|
|
DynamicCopy = GL_DYNAMIC_COPY
|
||
|
|
#endif
|
||
|
|
};
|
||
|
|
|
||
|
12 years ago
|
namespace Implementation { struct BufferState; }
|
||
|
12 years ago
|
|
||
|
14 years ago
|
/**
|
||
|
12 years ago
|
@brief Buffer
|
||
|
14 years ago
|
|
||
|
|
Encapsulates one OpenGL buffer object and provides functions for convenient
|
||
|
|
data updates.
|
||
|
|
|
||
|
8 years ago
|
@section Buffer-data-updating Data updating
|
||
|
14 years ago
|
|
||
|
13 years ago
|
Default way to set or update buffer data with @ref setData() or @ref setSubData()
|
||
|
11 years ago
|
is to use @ref Corrade::Containers::ArrayView. See its documentation for
|
||
|
13 years ago
|
more information about automatic conversions etc.
|
||
|
8 years ago
|
|
||
|
8 years ago
|
@snippet MagnumGL.cpp Buffer-setdata
|
||
|
8 years ago
|
|
||
|
|
There is also overload for array-like containers from STL, such as
|
||
|
8 years ago
|
@ref std::vector or @link std::array @endlink:
|
||
|
8 years ago
|
|
||
|
8 years ago
|
@snippet MagnumGL.cpp Buffer-setdata-stl
|
||
|
14 years ago
|
|
||
|
8 years ago
|
@section Buffer-data-mapping Memory mapping
|
||
|
14 years ago
|
|
||
|
12 years ago
|
Buffer data can be also updated asynchronously. First you need to allocate
|
||
|
8 years ago
|
the buffer to desired size by passing @cpp nullptr @ce to @ref setData(), e.g.:
|
||
|
|
|
||
|
8 years ago
|
@snippet MagnumGL.cpp Buffer-setdata-allocate
|
||
|
8 years ago
|
|
||
|
14 years ago
|
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
|
||
|
9 years ago
|
buffer again. The @ref map() functions return a view on `char` array and you
|
||
|
|
may want to cast it to some useful type first using @ref Containers::arrayCast():
|
||
|
8 years ago
|
|
||
|
8 years ago
|
@snippet MagnumGL.cpp Buffer-map
|
||
|
8 years ago
|
|
||
|
14 years ago
|
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:
|
||
|
8 years ago
|
|
||
|
8 years ago
|
@snippet MagnumGL.cpp Buffer-flush
|
||
|
14 years ago
|
|
||
|
8 years ago
|
@section Buffer-webgl-restrictions WebGL restrictions
|
||
|
9 years ago
|
|
||
|
|
Buffers in @ref MAGNUM_TARGET_WEBGL "WebGL" need to be bound only to one unique
|
||
|
8 years ago
|
target, i.e., @ref Buffer bound to @ref Buffer::TargetHint::Array cannot be
|
||
|
|
later rebound to @ref Buffer::TargetHint::ElementArray. However, Magnum by
|
||
|
|
default uses any sufficient target when binding the buffer internally (e.g. for
|
||
|
8 years ago
|
setting data). To avoid GL errors, the following, while completely fine on
|
||
|
|
desktop, is not sufficient on WebGL:
|
||
|
|
|
||
|
8 years ago
|
@snippet MagnumGL.cpp Buffer-webgl-nope
|
||
|
8 years ago
|
|
||
|
|
You have to set target hint to desired target, either in constructor or using
|
||
|
|
@ref Buffer::setTargetHint() like this (and similarly for other bufffer types
|
||
|
|
such as UBOs):
|
||
|
8 years ago
|
|
||
|
8 years ago
|
@snippet MagnumGL.cpp Buffer-webgl
|
||
|
12 years ago
|
|
||
|
8 years ago
|
To simplify debugging, @ref Mesh checks proper target hint when adding vertex
|
||
|
|
and index buffers in WebGL.
|
||
|
12 years ago
|
|
||
|
8 years ago
|
@section Buffer-performance-optimizations Performance optimizations
|
||
|
14 years ago
|
|
||
|
14 years ago
|
The engine tracks currently bound buffers to avoid unnecessary calls to
|
||
|
8 years ago
|
@fn_gl_keyword{BindBuffer}. If the buffer is already bound to some target,
|
||
|
|
functions @ref copy(), @ref setData(), @ref setSubData(), @ref map(),
|
||
|
|
@ref mapRead(), @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 maxUniformBindings()) are
|
||
|
|
cached, so repeated queries don't result in repeated @fn_gl{Get} calls. See
|
||
|
|
also @ref Context::resetState() and @ref Context::State::Buffers.
|
||
|
14 years ago
|
|
||
|
11 years ago
|
If either @extension{ARB,direct_state_access} (part of OpenGL 4.5) or
|
||
|
|
@extension{EXT,direct_state_access} desktop extension is available, functions
|
||
|
12 years ago
|
@ref copy(), @ref size(), @ref data(), @ref subData(), @ref setData(),
|
||
|
9 years ago
|
@ref setSubData(), @ref map(), @ref mapRead(), @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
|
||
|
12 years ago
|
@extension{ARB,invalidate_subdata} (part of OpenGL 4.3) is not available, these
|
||
|
|
functions do nothing.
|
||
|
16 years ago
|
*/
|
||
|
8 years ago
|
class MAGNUM_GL_EXPORT Buffer: public AbstractObject {
|
||
|
12 years ago
|
friend Implementation::BufferState;
|
||
|
14 years ago
|
|
||
|
16 years ago
|
public:
|
||
|
14 years ago
|
/**
|
||
|
12 years ago
|
* @brief Buffer target
|
||
|
14 years ago
|
*
|
||
|
12 years ago
|
* @see @ref Buffer(), @ref setTargetHint()
|
||
|
8 years ago
|
* @m_enum_values_as_keywords
|
||
|
14 years ago
|
*/
|
||
|
12 years ago
|
enum class TargetHint: GLenum {
|
||
|
14 years ago
|
/** Used for storing vertex attributes. */
|
||
|
|
Array = GL_ARRAY_BUFFER,
|
||
|
16 years ago
|
|
||
|
12 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
14 years ago
|
/**
|
||
|
|
* Used for storing atomic counters.
|
||
|
12 years ago
|
* @requires_gl42 Extension @extension{ARB,shader_atomic_counters}
|
||
|
12 years ago
|
* @requires_gles31 Atomic counters are not available in OpenGL ES
|
||
|
|
* 3.0 and older.
|
||
|
11 years ago
|
* @requires_gles Atomic counters are not available in WebGL.
|
||
|
14 years ago
|
*/
|
||
|
|
AtomicCounter = GL_ATOMIC_COUNTER_BUFFER,
|
||
|
11 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
14 years ago
|
/**
|
||
|
13 years ago
|
* Source for copies. See @ref copy().
|
||
|
12 years ago
|
* @requires_gl31 Extension @extension{ARB,copy_buffer}
|
||
|
14 years ago
|
* @requires_gles30 Buffer copying is not available in OpenGL ES
|
||
|
|
* 2.0.
|
||
|
11 years ago
|
* @requires_webgl20 Buffer copying is not available in WebGL 1.0.
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
CopyRead = GL_COPY_READ_BUFFER,
|
||
|
|
|
||
|
14 years ago
|
/**
|
||
|
13 years ago
|
* Target for copies. See @ref copy().
|
||
|
12 years ago
|
* @requires_gl31 Extension @extension{ARB,copy_buffer}
|
||
|
14 years ago
|
* @requires_gles30 Buffer copying is not available in OpenGL ES
|
||
|
|
* 2.0.
|
||
|
11 years ago
|
* @requires_webgl20 Buffer copying is not available in WebGL 1.0.
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
CopyWrite = GL_COPY_WRITE_BUFFER,
|
||
|
|
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
14 years ago
|
/**
|
||
|
|
* Indirect compute dispatch commands.
|
||
|
12 years ago
|
* @requires_gl43 Extension @extension{ARB,compute_shader}
|
||
|
12 years ago
|
* @requires_gles31 Compute shaders are not available in OpenGL ES
|
||
|
|
* 3.0 and older.
|
||
|
11 years ago
|
* @requires_gles Compute shaders are not available in WebGL.
|
||
|
14 years ago
|
*/
|
||
|
|
DispatchIndirect = GL_DISPATCH_INDIRECT_BUFFER,
|
||
|
|
|
||
|
14 years ago
|
/**
|
||
|
14 years ago
|
* Used for supplying arguments for indirect drawing.
|
||
|
12 years ago
|
* @requires_gl40 Extension @extension{ARB,draw_indirect}
|
||
|
11 years ago
|
* @requires_gles31 Indirect drawing is not available in OpenGL ES
|
||
|
|
* 3.0 and older.
|
||
|
|
* @requires_gles Indirect drawing is not available in WebGL.
|
||
|
14 years ago
|
*/
|
||
|
|
DrawIndirect = GL_DRAW_INDIRECT_BUFFER,
|
||
|
|
#endif
|
||
|
11 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
14 years ago
|
/** Used for storing vertex indices. */
|
||
|
12 years ago
|
ElementArray = GL_ELEMENT_ARRAY_BUFFER,
|
||
|
14 years ago
|
|
||
|
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
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.
|
||
|
11 years ago
|
* @requires_webgl20 Pixel buffer objects are not available in
|
||
|
|
* WebGL 1.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.
|
||
|
11 years ago
|
* @requires_webgl20 Pixel buffer objects are not available in
|
||
|
|
* WebGL 1.0.
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
PixelUnpack = GL_PIXEL_UNPACK_BUFFER,
|
||
|
14 years ago
|
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
14 years ago
|
/**
|
||
|
|
* Used for shader storage.
|
||
|
12 years ago
|
* @requires_gl43 Extension @extension{ARB,shader_storage_buffer_object}
|
||
|
12 years ago
|
* @requires_gles31 Shader storage is not available in OpenGL ES
|
||
|
|
* 3.0 and older.
|
||
|
11 years ago
|
* @requires_gles Shader storage is not available in WebGL.
|
||
|
14 years ago
|
*/
|
||
|
|
ShaderStorage = GL_SHADER_STORAGE_BUFFER,
|
||
|
12 years ago
|
#endif
|
||
|
11 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
9 years ago
|
#if !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL)
|
||
|
14 years ago
|
/**
|
||
|
12 years ago
|
* Source for texel fetches. See @ref BufferTexture.
|
||
|
12 years ago
|
* @requires_gl31 Extension @extension{ARB,texture_buffer_object}
|
||
|
9 years ago
|
* @requires_gles30 Not defined in OpenGL ES 2.0.
|
||
|
|
* @requires_gles32 Extension @extension{ANDROID,extension_pack_es31a} /
|
||
|
|
* @extension{EXT,texture_buffer}
|
||
|
|
* @requires_gles Texture buffers are not available in WebGL.
|
||
|
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.
|
||
|
12 years ago
|
* @requires_gl30 Extension @extension{EXT,transform_feedback}
|
||
|
14 years ago
|
* @requires_gles30 Transform feedback is not available in OpenGL
|
||
|
|
* ES 2.0.
|
||
|
11 years ago
|
* @requires_webgl20 Transform feedback is not available in WebGL
|
||
|
|
* 1.0.
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
TransformFeedback = GL_TRANSFORM_FEEDBACK_BUFFER,
|
||
|
|
|
||
|
14 years ago
|
/**
|
||
|
|
* Used for storing uniforms.
|
||
|
12 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.
|
||
|
11 years ago
|
* @requires_webgl20 Uniform buffers are not available in WebGL
|
||
|
|
* 1.0.
|
||
|
14 years ago
|
*/
|
||
|
14 years ago
|
Uniform = GL_UNIFORM_BUFFER
|
||
|
14 years ago
|
#endif
|
||
|
16 years ago
|
};
|
||
|
|
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
12 years ago
|
/**
|
||
|
12 years ago
|
* @brief Buffer binding target
|
||
|
12 years ago
|
*
|
||
|
|
* @see @ref bind(), @ref unbind()
|
||
|
8 years ago
|
* @m_enum_values_as_keywords
|
||
|
12 years ago
|
*/
|
||
|
|
enum class Target: GLenum {
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
12 years ago
|
/**
|
||
|
|
* Atomic counter binding
|
||
|
12 years ago
|
* @requires_gl42 Extension @extension{ARB,shader_atomic_counters}
|
||
|
12 years ago
|
* @requires_gles31 Atomic counters are not available in OpenGL ES
|
||
|
11 years ago
|
* 3.0 and older.
|
||
|
|
* @requires_gles Atomic counters are not available in WebGL.
|
||
|
12 years ago
|
*/
|
||
|
|
AtomicCounter = GL_ATOMIC_COUNTER_BUFFER,
|
||
|
|
#endif
|
||
|
|
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
12 years ago
|
/**
|
||
|
|
* Shader storage binding
|
||
|
12 years ago
|
* @requires_gl43 Extension @extension{ARB,shader_storage_buffer_object}
|
||
|
12 years ago
|
* @requires_gles31 Shader storage is not available in OpenGL ES
|
||
|
11 years ago
|
* 3.0 and older.
|
||
|
|
* @requires_gles Shader storage is not available in WebGL.
|
||
|
12 years ago
|
*/
|
||
|
|
ShaderStorage = GL_SHADER_STORAGE_BUFFER,
|
||
|
|
#endif
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Uniform binding
|
||
|
12 years ago
|
* @requires_gl31 Extension @extension{ARB,uniform_buffer_object}
|
||
|
12 years ago
|
* @requires_gles30 Uniform buffers are not available in OpenGL ES
|
||
|
11 years ago
|
* 2.0.
|
||
|
|
* @requires_webgl20 Uniform buffers are not available in WebGL
|
||
|
|
* 1.0.
|
||
|
12 years ago
|
*/
|
||
|
|
Uniform = GL_UNIFORM_BUFFER
|
||
|
|
};
|
||
|
|
#endif
|
||
|
|
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
14 years ago
|
/**
|
||
|
|
* @brief Memory mapping access
|
||
|
|
*
|
||
|
9 years ago
|
* @see @ref map(MapAccess)
|
||
|
8 years ago
|
* @m_enum_values_as_keywords
|
||
|
8 years ago
|
* @requires_es_extension Extension @extension{OES,mapbuffer}
|
||
|
11 years ago
|
* @requires_gles Buffer mapping is not available in WebGL.
|
||
|
11 years ago
|
* @deprecated_gl Prefer to use @ref map(GLintptr, GLsizeiptr, MapFlags)
|
||
|
12 years ago
|
* instead, as it has more complete set of features.
|
||
|
14 years ago
|
*/
|
||
|
|
enum class MapAccess: GLenum {
|
||
|
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
|
/**
|
||
|
|
* Map buffer for reading only.
|
||
|
11 years ago
|
* @requires_gl Only @ref MapAccess::WriteOnly 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.
|
||
|
11 years ago
|
* @requires_gl Only @ref MapAccess::WriteOnly 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)
|
||
|
8 years ago
|
* @m_enum_values_as_keywords
|
||
|
12 years ago
|
* @requires_gl30 Extension @extension{ARB,map_buffer_range}
|
||
|
9 years ago
|
* @requires_gles30 Extension @extension{EXT,map_buffer_range} in
|
||
|
11 years ago
|
* OpenGL ES 2.0.
|
||
|
|
* @requires_gles Buffer mapping is not available in WebGL.
|
||
|
14 years ago
|
*/
|
||
|
|
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)
|
||
|
12 years ago
|
* @requires_gl30 Extension @extension{ARB,map_buffer_range}
|
||
|
9 years ago
|
* @requires_gles30 Extension @extension{EXT,map_buffer_range} in
|
||
|
11 years ago
|
* OpenGL ES 2.0.
|
||
|
|
* @requires_gles Buffer mapping is not available in WebGL.
|
||
|
14 years ago
|
*/
|
||
|
12 years ago
|
typedef Containers::EnumSet<MapFlag> MapFlags;
|
||
|
11 years ago
|
#endif
|
||
|
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
|
||
|
12 years ago
|
* OpenGL calls. If extension @extension{ARB,map_buffer_alignment}
|
||
|
8 years ago
|
* (part of OpenGL 4.2) is not available, returns @cpp 1 @ce.
|
||
|
9 years ago
|
* @see @ref map(), @ref mapRead(), @fn_gl{Get} with
|
||
|
8 years ago
|
* @def_gl_keyword{MIN_MAP_BUFFER_ALIGNMENT}
|
||
|
11 years ago
|
* @requires_gl No minimal value is specified for OpenGL ES. Buffer
|
||
|
|
* mapping is not available in WebGL.
|
||
|
13 years ago
|
*/
|
||
|
|
static Int minMapAlignment();
|
||
|
12 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
12 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
13 years ago
|
/**
|
||
|
|
* @brief Max supported atomic counter buffer binding count
|
||
|
|
*
|
||
|
|
* The result is cached, repeated queries don't result in repeated
|
||
|
12 years ago
|
* OpenGL calls. If neither extension @extension{ARB,shader_atomic_counters}
|
||
|
8 years ago
|
* (part of OpenGL 4.2) nor OpenGL ES 3.1 is available, returns
|
||
|
|
* @cpp 0 @ce.
|
||
|
12 years ago
|
* @see @ref bind(), @ref unbind(), @fn_gl{Get} with
|
||
|
8 years ago
|
* @def_gl_keyword{MAX_ATOMIC_COUNTER_BUFFER_BINDINGS}
|
||
|
11 years ago
|
* @requires_gles30 Not defined in OpenGL ES 2.0.
|
||
|
|
* @requires_gles Atomic counters are not available in WebGL.
|
||
|
13 years ago
|
*/
|
||
|
|
static Int maxAtomicCounterBindings();
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Max supported shader storage buffer binding count
|
||
|
|
*
|
||
|
|
* The result is cached, repeated queries don't result in repeated
|
||
|
12 years ago
|
* OpenGL calls. If neither extension @extension{ARB,shader_storage_buffer_object}
|
||
|
8 years ago
|
* (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns
|
||
|
|
* @cpp 0 @ce.
|
||
|
12 years ago
|
* @see @ref bind(), @ref unbind(), @fn_gl{Get} with
|
||
|
8 years ago
|
* @def_gl_keyword{MAX_SHADER_STORAGE_BUFFER_BINDINGS}
|
||
|
11 years ago
|
* @requires_gles30 Not defined in OpenGL ES 2.0.
|
||
|
|
* @requires_gles Shader storage is not available in WebGL.
|
||
|
13 years ago
|
*/
|
||
|
|
static Int maxShaderStorageBindings();
|
||
|
11 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
12 years ago
|
/**
|
||
|
|
* @brief Alignment of uniform buffer binding offset
|
||
|
|
*
|
||
|
|
* The result is cached, repeated queries don't result in repeated
|
||
|
|
* OpenGL calls. If extension @extension{ARB,uniform_buffer_object}
|
||
|
8 years ago
|
* (part of OpenGL 3.1) is not available, returns @cpp 1 @ce.
|
||
|
|
* @see @ref bind(), @fn_gl{Get} with
|
||
|
|
* @def_gl_keyword{UNIFORM_BUFFER_OFFSET_ALIGNMENT}
|
||
|
11 years ago
|
* @requires_gles30 Uniform buffers are not available in OpenGL ES 2.0.
|
||
|
|
* @requires_webgl20 Uniform buffers are not available in WebGL 1.0.
|
||
|
12 years ago
|
*/
|
||
|
|
static Int uniformOffsetAlignment();
|
||
|
|
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
13 years ago
|
/**
|
||
|
|
* @brief Alignment of shader storage buffer binding offset
|
||
|
|
*
|
||
|
|
* The result is cached, repeated queries don't result in repeated
|
||
|
12 years ago
|
* OpenGL calls. If neither extension @extension{ARB,shader_storage_buffer_object}
|
||
|
8 years ago
|
* (part of OpenGL 4.3) nor OpenGL ES 3.1 is available, returns
|
||
|
|
* @cpp 1 @ce.
|
||
|
|
* @see @ref bind(), @fn_gl{Get} with
|
||
|
|
* @def_gl_keyword{SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT}
|
||
|
11 years ago
|
* @requires_gles30 Not defined in OpenGL ES 2.0.
|
||
|
|
* @requires_gles Shader storage is not available in WebGL.
|
||
|
13 years ago
|
*/
|
||
|
|
static Int shaderStorageOffsetAlignment();
|
||
|
11 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
|
/**
|
||
|
|
* @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}
|
||
|
8 years ago
|
* (part of OpenGL 3.1) is not available, returns @cpp 0 @ce.
|
||
|
12 years ago
|
* @see @ref bind(), @ref unbind(), @fn_gl{Get} with
|
||
|
8 years ago
|
* @def_gl_keyword{MAX_UNIFORM_BUFFER_BINDINGS}
|
||
|
11 years ago
|
* @requires_gles30 Uniform buffers are not available in OpenGL ES 2.0.
|
||
|
|
* @requires_webgl20 Uniform buffers are not available in WebGL 1.0.
|
||
|
13 years ago
|
*/
|
||
|
|
static Int maxUniformBindings();
|
||
|
|
|
||
|
12 years ago
|
/**
|
||
|
|
* @brief Unbind any buffer from given indexed target
|
||
|
|
*
|
||
|
|
* The @p index parameter must respect limits for given @p target.
|
||
|
|
* @note This function is meant to be used only internally from
|
||
|
|
* @ref AbstractShaderProgram subclasses. See its documentation
|
||
|
|
* for more information.
|
||
|
|
* @see @ref bind(), @ref maxAtomicCounterBindings(),
|
||
|
|
* @ref maxShaderStorageBindings(), @ref maxUniformBindings(),
|
||
|
8 years ago
|
* @fn_gl_keyword{BindBufferBase}
|
||
|
12 years ago
|
* @requires_gl30 No form of indexed buffer binding is available in
|
||
|
11 years ago
|
* OpenGL 2.1, see particular @ref Target values for
|
||
|
|
* version/extension requirements.
|
||
|
12 years ago
|
* @requires_gles30 No form of indexed buffer binding is available in
|
||
|
11 years ago
|
* OpenGL ES 2.0, see particular @ref Target values for version
|
||
|
|
* requirements.
|
||
|
11 years ago
|
* @requires_webgl20 No form of indexed buffer binding is available in
|
||
|
|
* WebGL 1.0, see particular @ref Target values for version
|
||
|
|
* requirements.
|
||
|
12 years ago
|
*/
|
||
|
|
static void unbind(Target target, UnsignedInt index);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Unbind given range of indexed targets
|
||
|
|
*
|
||
|
|
* Unbinds all buffers in given target in range @f$ [ firstIndex ; firstIndex + count ] @f$.
|
||
|
|
* The range of indices must respect limits for given @p target. If
|
||
|
|
* @extension{ARB,multi_bind} (part of OpenGL 4.4) is not available,
|
||
|
|
* the feature is emulated with sequence of @ref unbind(Target, UnsignedInt)
|
||
|
|
* calls.
|
||
|
|
* @note This function is meant to be used only internally from
|
||
|
|
* @ref AbstractShaderProgram subclasses. See its documentation
|
||
|
|
* for more information.
|
||
|
|
* @see @ref unbind(Target, UnsignedInt), @ref maxAtomicCounterBindings(),
|
||
|
|
* @ref maxShaderStorageBindings(), @ref maxUniformBindings(),
|
||
|
8 years ago
|
* @fn_gl_keyword{BindBuffersBase} or
|
||
|
|
* @fn_gl_keyword{BindBufferBase}
|
||
|
12 years ago
|
* @requires_gl30 No form of indexed buffer binding is available in
|
||
|
11 years ago
|
* OpenGL 2.1, see particular @ref Target values for
|
||
|
|
* version/extension requirements.
|
||
|
12 years ago
|
* @requires_gles30 No form of indexed buffer binding is available in
|
||
|
11 years ago
|
* OpenGL ES 2.0, see particular @ref Target values for version
|
||
|
|
* requirements.
|
||
|
11 years ago
|
* @requires_webgl20 No form of indexed buffer binding is available in
|
||
|
|
* WebGL 1.0, see particular @ref Target values for version
|
||
|
|
* requirements.
|
||
|
12 years ago
|
*/
|
||
|
|
static void unbind(Target target, UnsignedInt firstIndex, std::size_t count);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Bind ranges of buffers to given range of indexed targets
|
||
|
|
*
|
||
|
|
* Binds first buffer in the list to @p 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 @p target. The offsets must
|
||
|
|
* respect alignment, which is 4 bytes for @ref Target::AtomicCounter
|
||
|
12 years ago
|
* and implementation-defined for other targets. All the buffers must
|
||
|
|
* have allocated data store. If @extension{ARB,multi_bind} (part of
|
||
|
|
* OpenGL 4.4) is not available, the feature is emulated with sequence
|
||
|
|
* of @ref bind(Target, UnsignedInt, GLintptr, GLsizeiptr) /
|
||
|
12 years ago
|
* @ref unbind(Target, UnsignedInt) calls.
|
||
|
|
* @note This function is meant to be used only internally from
|
||
|
|
* @ref AbstractShaderProgram subclasses. See its documentation
|
||
|
|
* for more information.
|
||
|
|
* @see @ref bind(Target, UnsignedInt, GLintptr, GLsizeiptr),
|
||
|
|
* @ref maxAtomicCounterBindings(), @ref maxShaderStorageBindings(),
|
||
|
|
* @ref maxUniformBindings(), @ref shaderStorageOffsetAlignment(),
|
||
|
12 years ago
|
* @ref uniformOffsetAlignment(), @ref TransformFeedback::attachBuffers(),
|
||
|
8 years ago
|
* @fn_gl_keyword{BindBuffersRange} or
|
||
|
|
* @fn_gl_keyword{BindBufferRange}
|
||
|
12 years ago
|
* @requires_gl30 No form of indexed buffer binding is available in
|
||
|
11 years ago
|
* OpenGL 2.1, see particular @ref Target values for
|
||
|
|
* version/extension requirements.
|
||
|
12 years ago
|
* @requires_gles30 No form of indexed buffer binding is available in
|
||
|
11 years ago
|
* OpenGL ES 2.0, see particular @ref Target values for version
|
||
|
|
* requirements.
|
||
|
11 years ago
|
* @requires_webgl20 No form of indexed buffer binding is available in
|
||
|
|
* WebGL 1.0, see particular @ref Target values for version
|
||
|
|
* requirements.
|
||
|
12 years ago
|
*/
|
||
|
|
static void bind(Target target, UnsignedInt firstIndex, std::initializer_list<std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Bind buffers to given range of indexed targets
|
||
|
|
*
|
||
|
|
* Binds first buffer in the list to @p firstIndex, second to
|
||
|
|
* `firstIndex + 1` etc. If any buffer is `nullptr`, given indexed
|
||
|
|
* target is unbound. The range of indices must respect limits for
|
||
|
12 years ago
|
* given @p target. All the buffers must have allocated data store. If
|
||
|
|
* @extension{ARB,multi_bind} (part of OpenGL 4.4) is not available,
|
||
|
|
* the feature is emulated with sequence of @ref bind(Target, UnsignedInt)
|
||
|
|
* / @ref unbind(Target, UnsignedInt) calls.
|
||
|
12 years ago
|
* @note This function is meant to be used only internally from
|
||
|
|
* @ref AbstractShaderProgram subclasses. See its documentation
|
||
|
|
* for more information.
|
||
|
|
* @see @ref bind(Target, UnsignedInt), @ref maxAtomicCounterBindings(),
|
||
|
|
* @ref maxShaderStorageBindings(), @ref maxUniformBindings(),
|
||
|
8 years ago
|
* @ref TransformFeedback::attachBuffers(),
|
||
|
|
* @fn_gl_keyword{BindBuffersBase} or @fn_gl_keyword{BindBufferBase}
|
||
|
12 years ago
|
* @requires_gl30 No form of indexed buffer binding is available in
|
||
|
11 years ago
|
* OpenGL 2.1, see particular @ref Target values for
|
||
|
|
* version/extension requirements.
|
||
|
12 years ago
|
* @requires_gles30 No form of indexed buffer binding is available in
|
||
|
11 years ago
|
* OpenGL ES 2.0, see particular @ref Target values for version
|
||
|
|
* requirements.
|
||
|
11 years ago
|
* @requires_webgl20 No form of indexed buffer binding is available in
|
||
|
|
* WebGL 1.0, see particular @ref Target values for version
|
||
|
|
* requirements.
|
||
|
12 years ago
|
*/
|
||
|
|
static void bind(Target target, UnsignedInt firstIndex, std::initializer_list<Buffer*> buffers);
|
||
|
|
|
||
|
14 years ago
|
/**
|
||
|
|
* @brief Copy one buffer to another
|
||
|
12 years ago
|
* @param read Buffer from which to read
|
||
|
|
* @param write Buffer to which to copy
|
||
|
14 years ago
|
* @param readOffset Offset in the read buffer
|
||
|
|
* @param writeOffset Offset in the write buffer
|
||
|
|
* @param size Data size
|
||
|
|
*
|
||
|
11 years ago
|
* If neither @extension{ARB,direct_state_access} (part of OpenGL 4.5)
|
||
|
|
* nor @extension{EXT,direct_state_access} desktop extension is
|
||
|
|
* available, @p read buffer is bound for reading and @p write buffer
|
||
|
|
* is bound for writing before the copy is performed (if not already).
|
||
|
8 years ago
|
* @see @fn_gl2_keyword{CopyNamedBufferSubData,CopyBufferSubData},
|
||
|
|
* @fn_gl_extension_keyword{NamedCopyBufferSubData,EXT,direct_state_access},
|
||
|
|
* eventually @fn_gl{BindBuffer} and @fn_gl_keyword{CopyBufferSubData}
|
||
|
12 years ago
|
* @requires_gl31 Extension @extension{ARB,copy_buffer}
|
||
|
|
* @requires_gles30 Buffer copying is not available in OpenGL ES 2.0.
|
||
|
11 years ago
|
* @requires_webgl20 Buffer copying is not available in WebGL 1.0.
|
||
|
14 years ago
|
*/
|
||
|
12 years ago
|
static void copy(Buffer& read, Buffer& write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
11 years ago
|
/**
|
||
|
|
* @brief Wrap existing OpenGL buffer object
|
||
|
|
* @param id OpenGL buffer ID
|
||
|
|
* @param targetHint Target hint, see @ref setTargetHint() for more
|
||
|
|
* information
|
||
|
|
* @param flags Object creation flags
|
||
|
|
*
|
||
|
|
* The @p 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 @p flags for different
|
||
|
|
* behavior.
|
||
|
|
* @see @ref release()
|
||
|
|
*/
|
||
|
|
static Buffer wrap(GLuint id, TargetHint targetHint = TargetHint::Array, ObjectFlags flags = {}) {
|
||
|
|
return Buffer{id, targetHint, flags};
|
||
|
|
}
|
||
|
|
|
||
|
|
/** @overload */
|
||
|
|
static Buffer wrap(GLuint id, ObjectFlags flags) {
|
||
|
|
return Buffer(id, TargetHint::Array, flags);
|
||
|
|
}
|
||
|
|
|
||
|
16 years ago
|
/**
|
||
|
|
* @brief Constructor
|
||
|
13 years ago
|
* @param targetHint Target hint, see @ref setTargetHint() for more
|
||
|
14 years ago
|
* information
|
||
|
16 years ago
|
*
|
||
|
12 years ago
|
* Creates new OpenGL buffer object. If @extension{ARB,direct_state_access}
|
||
|
11 years ago
|
* (part of OpenGL 4.5) is not available, the buffer is created on
|
||
|
12 years ago
|
* first use.
|
||
|
8 years ago
|
* @see @ref Buffer(NoCreateT), @ref wrap(), @fn_gl_keyword{CreateBuffers},
|
||
|
|
* eventually @fn_gl_keyword{GenBuffers}
|
||
|
16 years ago
|
*/
|
||
|
12 years ago
|
explicit Buffer(TargetHint targetHint = TargetHint::Array);
|
||
|
|
|
||
|
11 years ago
|
/**
|
||
|
|
* @brief 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.
|
||
|
9 years ago
|
*
|
||
|
|
* This function can be safely used for constructing (and later
|
||
|
|
* destructing) objects even without any OpenGL context being active.
|
||
|
11 years ago
|
* @see @ref Buffer(TargetHint), @ref wrap()
|
||
|
|
*/
|
||
|
|
explicit Buffer(NoCreateT) noexcept;
|
||
|
|
|
||
|
13 years ago
|
/** @brief Copying is not allowed */
|
||
|
|
Buffer(const Buffer&) = delete;
|
||
|
|
|
||
|
|
/** @brief Move constructor */
|
||
|
11 years ago
|
/* MinGW complains loudly if the declaration doesn't also have inline */
|
||
|
|
inline Buffer(Buffer&& other) noexcept;
|
||
|
13 years ago
|
|
||
|
16 years ago
|
/**
|
||
|
|
* @brief Destructor
|
||
|
|
*
|
||
|
12 years ago
|
* Deletes associated OpenGL buffer object.
|
||
|
8 years ago
|
* @see @ref wrap(), @ref release(), @fn_gl_keyword{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 */
|
||
|
11 years ago
|
/* MinGW complains loudly if the declaration doesn't also have inline */
|
||
|
|
inline Buffer& operator=(Buffer&& other) noexcept;
|
||
|
13 years ago
|
|
||
|
14 years ago
|
/** @brief OpenGL buffer ID */
|
||
|
13 years ago
|
GLuint id() const { return _id; }
|
||
|
14 years ago
|
|
||
|
11 years ago
|
/**
|
||
|
|
* @brief 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.
|
||
|
|
* @see @ref wrap()
|
||
|
|
*/
|
||
|
11 years ago
|
/* MinGW complains loudly if the declaration doesn't also have inline */
|
||
|
|
inline GLuint release();
|
||
|
11 years ago
|
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
13 years ago
|
/**
|
||
|
12 years ago
|
* @brief Buffer label
|
||
|
13 years ago
|
*
|
||
|
|
* The result is *not* cached, repeated queries will result in repeated
|
||
|
8 years ago
|
* OpenGL calls. If OpenGL 4.3 / OpenGL ES 3.2 is not supported and
|
||
|
|
* neither @extension{KHR,debug} (covered also by
|
||
|
|
* @extension{ANDROID,extension_pack_es31a}) nor @extension{EXT,debug_label}
|
||
|
|
* desktop or ES extension is available, this function returns empty
|
||
|
|
* string.
|
||
|
8 years ago
|
* @see @fn_gl_keyword{GetObjectLabel} with @def_gl{BUFFER} or
|
||
|
|
* @fn_gl_extension_keyword{GetObjectLabel,EXT,debug_label} with
|
||
|
13 years ago
|
* @def_gl{BUFFER_OBJECT_EXT}
|
||
|
11 years ago
|
* @requires_gles Debug output is not available in WebGL.
|
||
|
13 years ago
|
*/
|
||
|
12 years ago
|
std::string label();
|
||
|
13 years ago
|
|
||
|
|
/**
|
||
|
|
* @brief Set buffer label
|
||
|
|
* @return Reference to self (for method chaining)
|
||
|
|
*
|
||
|
8 years ago
|
* Default is empty string. If OpenGL 4.3 / OpenGL ES 3.2 is not
|
||
|
|
* supported and neither @extension{KHR,debug} (covered also by
|
||
|
|
* @extension{ANDROID,extension_pack_es31a}) nor @extension{EXT,debug_label}
|
||
|
|
* desktop or ES extension is available, this function does nothing.
|
||
|
8 years ago
|
* @see @ref maxLabelLength(), @fn_gl_keyword{ObjectLabel} with
|
||
|
|
* @def_gl{BUFFER} or @fn_gl_extension_keyword{LabelObject,EXT,debug_label}
|
||
|
|
* with @def_gl{BUFFER_OBJECT_EXT}
|
||
|
11 years ago
|
* @requires_gles Debug output is not available in WebGL.
|
||
|
13 years ago
|
*/
|
||
|
12 years ago
|
Buffer& setLabel(const std::string& label) {
|
||
|
|
return setLabelInternal({label.data(), label.size()});
|
||
|
|
}
|
||
|
|
|
||
|
|
/** @overload */
|
||
|
|
template<std::size_t size> Buffer& setLabel(const char(&label)[size]) {
|
||
|
11 years ago
|
return setLabelInternal({label, size - 1});
|
||
|
12 years ago
|
}
|
||
|
11 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
14 years ago
|
/** @brief Target hint */
|
||
|
12 years ago
|
TargetHint 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
|
*
|
||
|
11 years ago
|
* If neither @extension{ARB,direct_state_access} (part of OpenGL 4.5)
|
||
|
|
* nor @extension{EXT,direct_state_access} desktop extension is
|
||
|
|
* 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
|
||
|
8 years ago
|
* to @fn_gl{BindBuffer}. Default target hint is @ref TargetHint::Array.
|
||
|
13 years ago
|
* @see @ref setData(), @ref setSubData()
|
||
|
14 years ago
|
*/
|
||
|
12 years ago
|
Buffer& setTargetHint(TargetHint hint) {
|
||
|
13 years ago
|
_targetHint = hint;
|
||
|
13 years ago
|
return *this;
|
||
|
13 years ago
|
}
|
||
|
14 years ago
|
|
||
|
12 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
|
/**
|
||
|
|
* @brief Bind buffer range to given binding index
|
||
|
|
*
|
||
|
|
* The @p index parameter must respect limits for given @p target. The
|
||
|
|
* @p offset parameter must respect alignment, which is 4 bytes for
|
||
|
|
* @ref Target::AtomicCounter and implementation-defined for other
|
||
|
12 years ago
|
* targets. The buffer must have allocated data store.
|
||
|
12 years ago
|
* @note This function is meant to be used only internally from
|
||
|
|
* @ref AbstractShaderProgram subclasses. See its documentation
|
||
|
|
* for more information.
|
||
|
|
* @see @ref bind(Target, UnsignedInt, std::initializer_list<std::tuple<Buffer*, GLintptr, GLsizeiptr>>),
|
||
|
|
* @ref maxAtomicCounterBindings(), @ref maxShaderStorageBindings(),
|
||
|
|
* @ref maxUniformBindings(), @ref shaderStorageOffsetAlignment(),
|
||
|
12 years ago
|
* @ref uniformOffsetAlignment(), @ref TransformFeedback::attachBuffer(),
|
||
|
8 years ago
|
* @fn_gl_keyword{BindBufferRange}
|
||
|
12 years ago
|
* @requires_gl30 No form of indexed buffer binding is available in
|
||
|
11 years ago
|
* OpenGL 2.1, see particular @ref Target values for
|
||
|
|
* version/extension requirements.
|
||
|
12 years ago
|
* @requires_gles30 No form of indexed buffer binding is available in
|
||
|
11 years ago
|
* OpenGL ES 2.0, see particular @ref Target values for version
|
||
|
|
* requirements.
|
||
|
11 years ago
|
* @requires_webgl20 No form of indexed buffer binding is available in
|
||
|
|
* WebGL 1.0, see particular @ref Target values for version
|
||
|
|
* requirements.
|
||
|
12 years ago
|
* @todo State tracking for indexed binding
|
||
|
|
*/
|
||
|
|
Buffer& bind(Target target, UnsignedInt index, GLintptr offset, GLsizeiptr size);
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @brief Bind buffer to given binding index
|
||
|
|
*
|
||
|
12 years ago
|
* The @p index parameter must respect limits for given @p target. The
|
||
|
|
* buffer must have allocated data store.
|
||
|
12 years ago
|
* @note This function is meant to be used only internally from
|
||
|
|
* @ref AbstractShaderProgram subclasses. See its documentation
|
||
|
|
* for more information.
|
||
|
|
* @see @ref bind(Target, UnsignedInt, std::initializer_list<Buffer*>),
|
||
|
|
* @ref maxAtomicCounterBindings(), @ref maxShaderStorageBindings(),
|
||
|
12 years ago
|
* @ref maxUniformBindings(), @ref TransformFeedback::attachBuffer(),
|
||
|
8 years ago
|
* @fn_gl_keyword{BindBufferBase}
|
||
|
12 years ago
|
* @requires_gl30 No form of indexed buffer binding is available in
|
||
|
11 years ago
|
* OpenGL 2.1, see particular @ref Target values for
|
||
|
|
* version/extension requirements.
|
||
|
12 years ago
|
* @requires_gles30 No form of indexed buffer binding is available in
|
||
|
11 years ago
|
* OpenGL ES 2.0, see particular @ref Target values for version
|
||
|
|
* requirements.
|
||
|
11 years ago
|
* @requires_webgl20 No form of indexed buffer binding is available in
|
||
|
|
* WebGL 1.0, see particular @ref Target values for version
|
||
|
|
* requirements.
|
||
|
12 years ago
|
*/
|
||
|
|
Buffer& bind(Target target, UnsignedInt index);
|
||
|
|
#endif
|
||
|
|
|
||
|
13 years ago
|
/**
|
||
|
12 years ago
|
* @brief Buffer size
|
||
|
13 years ago
|
*
|
||
|
11 years ago
|
* If neither @extension{ARB,direct_state_access} (part of OpenGL 4.5)
|
||
|
|
* nor @extension{EXT,direct_state_access} desktop extension is
|
||
|
|
* available, the buffer is bound to hinted target before the operation
|
||
|
|
* (if not already).
|
||
|
8 years ago
|
* @see @ref setTargetHint(), @fn_gl2_keyword{GetNamedBufferParameter,GetBufferParameter},
|
||
|
|
* @fn_gl_extension_keyword{GetNamedBufferParameter,EXT,direct_state_access},
|
||
|
|
* eventually @fn_gl{BindBuffer} and @fn_gl_keyword{GetBufferParameter}
|
||
|
13 years ago
|
*/
|
||
|
|
Int size();
|
||
|
|
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
13 years ago
|
/**
|
||
|
12 years ago
|
* @brief Buffer data
|
||
|
13 years ago
|
*
|
||
|
12 years ago
|
* Returns data of whole buffer. If neither @extension{ARB,direct_state_access}
|
||
|
|
* (part of OpenGL 4.5) nor @extension{EXT,direct_state_access} is
|
||
|
|
* available, the buffer is bound to hinted target before the operation
|
||
|
|
* (if not already).
|
||
|
|
* @see @ref size(), @ref subData(), @ref setData(), @ref setTargetHint(),
|
||
|
|
* @fn_gl2{GetNamedBufferParameter,GetBufferParameter},
|
||
|
|
* @fn_gl_extension{GetNamedBufferParameter,EXT,direct_state_access},
|
||
|
|
* eventually @fn_gl{BindBuffer} and @fn_gl{GetBufferParameter}
|
||
|
8 years ago
|
* with @def_gl{BUFFER_SIZE}, then @fn_gl2_keyword{GetNamedBufferSubData,GetBufferSubData},
|
||
|
|
* @fn_gl_extension_keyword{GetNamedBufferSubData,EXT,direct_state_access},
|
||
|
|
* eventually @fn_gl_keyword{GetBufferSubData}
|
||
|
11 years ago
|
* @requires_gl Buffer data queries are not available in OpenGL ES and
|
||
|
9 years ago
|
* WebGL. Use @ref map(), @ref mapRead() or @ref DebugTools::bufferData()
|
||
|
|
* in OpenGL ES instead.
|
||
|
13 years ago
|
*/
|
||
|
9 years ago
|
Containers::Array<char> data();
|
||
|
|
|
||
|
|
#ifdef MAGNUM_BUILD_DEPRECATED
|
||
|
8 years ago
|
/** @brief @copybrief data()
|
||
|
9 years ago
|
* @deprecated Use non-templated @ref subData() and @ref Containers::arrayCast()
|
||
|
|
* instead.
|
||
|
|
*/
|
||
|
11 years ago
|
/* MinGW complains loudly if the declaration doesn't also have inline */
|
||
|
9 years ago
|
template<class T> CORRADE_DEPRECATED("use non-templated data() and Containers::arrayCast() instead") inline Containers::Array<T> data();
|
||
|
|
#endif
|
||
|
13 years ago
|
|
||
|
|
/**
|
||
|
12 years ago
|
* @brief Buffer subdata
|
||
|
13 years ago
|
* @param offset Byte offset in the buffer
|
||
|
9 years ago
|
* @param size Data size in bytes
|
||
|
13 years ago
|
*
|
||
|
12 years ago
|
* Returns data of given buffer portion. If neither
|
||
|
|
* @extension{ARB,direct_state_access} (part of OpenGL 4.5) nor
|
||
|
|
* @extension{EXT,direct_state_access} is available, the buffer is
|
||
|
|
* bound to hinted target before the operation (if not already).
|
||
|
|
* @see @ref size(), @ref data(), @ref setSubData(), @ref setTargetHint(),
|
||
|
8 years ago
|
* @fn_gl2_keyword{GetNamedBufferSubData,GetBufferSubData},
|
||
|
|
* @fn_gl_extension_keyword{GetNamedBufferSubData,EXT,direct_state_access},
|
||
|
|
* eventually @fn_gl{BindBuffer} and @fn_gl_keyword{GetBufferSubData}
|
||
|
11 years ago
|
* @requires_gl Buffer data queries are not available in OpenGL ES and
|
||
|
9 years ago
|
* WebGL. Use @ref map(), @ref mapRead() or @ref DebugTools::bufferData()
|
||
|
|
* in OpenGL ES instead.
|
||
|
13 years ago
|
*/
|
||
|
9 years ago
|
Containers::Array<char> subData(GLintptr offset, GLsizeiptr size);
|
||
|
|
|
||
|
|
#ifdef MAGNUM_BUILD_DEPRECATED
|
||
|
8 years ago
|
/** @brief @copybrief subData()
|
||
|
9 years ago
|
* @deprecated Use non-templated @ref subData() and @ref Containers::arrayCast() instead
|
||
|
|
*/
|
||
|
11 years ago
|
/* MinGW complains loudly if the declaration doesn't also have inline */
|
||
|
9 years ago
|
template<class T> CORRADE_DEPRECATED("use non-templated subData() and Containers::arrayCast() instead") inline Containers::Array<T> subData(GLintptr offset, GLsizeiptr size);
|
||
|
|
#endif
|
||
|
13 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
16 years ago
|
/**
|
||
|
|
* @brief Set buffer data
|
||
|
13 years ago
|
* @param data Data
|
||
|
12 years ago
|
* @param usage Buffer usage
|
||
|
13 years ago
|
* @return Reference to self (for method chaining)
|
||
|
14 years ago
|
*
|
||
|
11 years ago
|
* If neither @extension{ARB,direct_state_access} (part of OpenGL 4.5)
|
||
|
|
* nor @extension{EXT,direct_state_access} desktop extension is
|
||
|
|
* available, the buffer is bound to hinted target before the operation
|
||
|
|
* (if not already).
|
||
|
8 years ago
|
* @see @ref setTargetHint(), @fn_gl2_keyword{NamedBufferData,BufferData},
|
||
|
|
* @fn_gl_extension_keyword{NamedBufferData,EXT,direct_state_access},
|
||
|
|
* eventually @fn_gl{BindBuffer} and @fn_gl_keyword{BufferData}
|
||
|
16 years ago
|
*/
|
||
|
11 years ago
|
Buffer& setData(Containers::ArrayView<const void> data, BufferUsage usage);
|
||
|
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
|
||
|
9 years ago
|
* @param offset Byte offset in the buffer
|
||
|
13 years ago
|
* @param data Data
|
||
|
13 years ago
|
* @return Reference to self (for method chaining)
|
||
|
14 years ago
|
*
|
||
|
11 years ago
|
* If neither @extension{ARB,direct_state_access} (part of OpenGL 4.5)
|
||
|
|
* nor @extension{EXT,direct_state_access} desktop extension is
|
||
|
|
* available, the buffer is bound to hinted target before the operation
|
||
|
|
* (if not already).
|
||
|
8 years ago
|
* @see @ref setTargetHint(), @fn_gl2_keyword{NamedBufferSubData,BufferSubData},
|
||
|
|
* @fn_gl_extension_keyword{NamedBufferSubData,EXT,direct_state_access},
|
||
|
|
* eventually @fn_gl{BindBuffer} and @fn_gl_keyword{BufferSubData}
|
||
|
14 years ago
|
*/
|
||
|
11 years ago
|
Buffer& setSubData(GLintptr offset, Containers::ArrayView<const void> data);
|
||
|
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
|
/**
|
||
|
|
* @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}
|
||
|
13 years ago
|
* (part of OpenGL 4.3) is not available, this function does nothing.
|
||
|
8 years ago
|
* @see @ref MapFlag::InvalidateBuffer, @fn_gl_keyword{InvalidateBufferData}
|
||
|
14 years ago
|
*/
|
||
|
12 years ago
|
Buffer& invalidateData();
|
||
|
14 years ago
|
|
||
|
|
/**
|
||
|
|
* @brief Invalidate buffer subdata
|
||
|
9 years ago
|
* @param offset Byte offset into the buffer
|
||
|
14 years ago
|
* @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}
|
||
|
13 years ago
|
* (part of OpenGL 4.3) is not available, this function does nothing.
|
||
|
8 years ago
|
* @see @ref MapFlag::InvalidateRange, @fn_gl_keyword{InvalidateBufferData}
|
||
|
14 years ago
|
*/
|
||
|
12 years ago
|
Buffer& invalidateSubData(GLintptr offset, GLsizeiptr length);
|
||
|
14 years ago
|
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
14 years ago
|
/**
|
||
|
|
* @brief Map buffer to client memory
|
||
|
|
* @param access Access
|
||
|
8 years ago
|
* @return Pointer to mapped buffer data or @cpp nullptr @ce on error
|
||
|
14 years ago
|
*
|
||
|
11 years ago
|
* If neither @extension{ARB,direct_state_access} (part of OpenGL 4.5)
|
||
|
|
* nor @extension{EXT,direct_state_access} desktop extension is
|
||
|
|
* available, the buffer is bound to hinted target before the operation
|
||
|
|
* (if not already).
|
||
|
9 years ago
|
* @see @ref mapRead(), @ref minMapAlignment(), @ref unmap(),
|
||
|
8 years ago
|
* @ref setTargetHint(), @fn_gl2_keyword{MapNamedBuffer,MapBuffer},
|
||
|
|
* @fn_gl_extension_keyword{MapNamedBuffer,EXT,direct_state_access},
|
||
|
|
* eventually @fn_gl{BindBuffer} and @fn_gl_keyword{MapBuffer}
|
||
|
9 years ago
|
* @requires_es_extension Extension @extension{OES,mapbuffer} in
|
||
|
11 years ago
|
* OpenGL ES 2.0, use @ref map(GLintptr, GLsizeiptr, MapFlags) in
|
||
|
|
* OpenGL ES 3.0 instead.
|
||
|
11 years ago
|
* @requires_gles Buffer mapping is not available in WebGL.
|
||
|
11 years ago
|
* @deprecated_gl Prefer to use @ref map(GLintptr, GLsizeiptr, MapFlags)
|
||
|
12 years ago
|
* instead, as it has more complete set of features.
|
||
|
14 years ago
|
*/
|
||
|
9 years ago
|
char* map(MapAccess access);
|
||
|
14 years ago
|
|
||
|
9 years ago
|
#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
|
||
|
|
|
||
|
9 years ago
|
#ifdef MAGNUM_BUILD_DEPRECATED
|
||
|
|
/** @overload
|
||
|
|
* @deprecated Use non-templated @ref map() and cast the result
|
||
|
|
* manually instead.
|
||
|
|
*/
|
||
|
|
template<class T> CORRADE_DEPRECATED("use non-templated map() and cast the result manually instead") T* map(MapAccess access) {
|
||
|
|
return reinterpret_cast<T*>(map(access));
|
||
|
11 years ago
|
}
|
||
|
9 years ago
|
#endif
|
||
|
11 years ago
|
|
||
|
14 years ago
|
/**
|
||
|
|
* @brief Map buffer to client memory
|
||
|
9 years ago
|
* @param offset Byte offset into the buffer
|
||
|
|
* @param length Length of the mapped memory in bytes
|
||
|
13 years ago
|
* @param flags Flags. At least @ref MapFlag::Read or
|
||
|
|
* @ref MapFlag::Write must be specified.
|
||
|
9 years ago
|
* @return Sized view to buffer data or `nullptr` on error
|
||
|
14 years ago
|
*
|
||
|
11 years ago
|
* If neither @extension{ARB,direct_state_access} (part of OpenGL 4.5)
|
||
|
|
* nor @extension{EXT,direct_state_access} desktop extension is
|
||
|
|
* available, the buffer is bound to hinted target before the operation
|
||
|
|
* (if not already).
|
||
|
9 years ago
|
* @see @ref mapRead(), @ref minMapAlignment(), @ref flushMappedRange(),
|
||
|
|
* @ref unmap(), @ref map(MapAccess), @ref setTargetHint(),
|
||
|
8 years ago
|
* @fn_gl2_keyword{MapNamedBufferRange,MapBufferRange},
|
||
|
|
* @fn_gl_extension_keyword{MapNamedBufferRange,EXT,direct_state_access},
|
||
|
|
* eventually @fn_gl{BindBuffer} and @fn_gl_keyword{MapBufferRange}
|
||
|
12 years ago
|
* @requires_gl30 Extension @extension{ARB,map_buffer_range}
|
||
|
9 years ago
|
* @requires_gles30 Extension @extension{EXT,map_buffer_range} in
|
||
|
11 years ago
|
* OpenGL ES 2.0.
|
||
|
|
* @requires_gles Buffer mapping is not available in WebGL.
|
||
|
14 years ago
|
*/
|
||
|
9 years ago
|
Containers::ArrayView<char> map(GLintptr offset, GLsizeiptr length, MapFlags flags);
|
||
|
14 years ago
|
|
||
|
9 years ago
|
/**
|
||
|
|
* @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);
|
||
|
|
}
|
||
|
|
|
||
|
9 years ago
|
#ifdef MAGNUM_BUILD_DEPRECATED
|
||
|
|
/** @overload
|
||
|
|
* @deprecated Use non-templated @ref map() and @ref Containers::arrayCast()
|
||
|
|
* instead.
|
||
|
|
*/
|
||
|
|
template<class T> CORRADE_DEPRECATED("use non-templated map() and Containers::arrayCast() instead") T* map(GLintptr offset, GLsizeiptr length, MapFlags flags) {
|
||
|
|
return Containers::arrayCast<T>(map(offset, length, flags));
|
||
|
11 years ago
|
}
|
||
|
9 years ago
|
#endif
|
||
|
11 years ago
|
|
||
|
14 years ago
|
/**
|
||
|
|
* @brief Flush mapped range
|
||
|
9 years ago
|
* @param offset Byte offset relative to start of mapped range
|
||
|
|
* @param length Length of the flushed memory in bytes
|
||
|
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.
|
||
|
|
*
|
||
|
11 years ago
|
* If neither @extension{ARB,direct_state_access} (part of OpenGL 4.5)
|
||
|
|
* nor @extension{EXT,direct_state_access} desktop extension is
|
||
|
|
* available, the buffer is bound to hinted target before the operation
|
||
|
|
* (if not already).
|
||
|
8 years ago
|
* @see @ref setTargetHint(), @fn_gl2_keyword{FlushMappedNamedBufferRange,FlushMappedBufferRange},
|
||
|
|
* @fn_gl_extension_keyword{FlushMappedNamedBufferRange,EXT,direct_state_access},
|
||
|
|
* eventually @fn_gl{BindBuffer} and @fn_gl_keyword{FlushMappedBufferRange}
|
||
|
12 years ago
|
* @requires_gl30 Extension @extension{ARB,map_buffer_range}
|
||
|
9 years ago
|
* @requires_gles30 Extension @extension{EXT,map_buffer_range} in
|
||
|
11 years ago
|
* OpenGL ES 2.0.
|
||
|
|
* @requires_gles Buffer mapping is not available in WebGL.
|
||
|
14 years ago
|
*/
|
||
|
12 years ago
|
Buffer& flushMappedRange(GLintptr offset, GLsizeiptr length);
|
||
|
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.
|
||
|
|
*
|
||
|
9 years ago
|
* Unmaps buffer previously mapped with @ref map() / @ref mapRead(),
|
||
|
|
* invalidating the pointer returned by these functions. If neither
|
||
|
12 years ago
|
* @extension{ARB,direct_state_access} (part of OpenGL 4.5) nor
|
||
|
11 years ago
|
* @extension{EXT,direct_state_access} desktop extension is available,
|
||
|
|
* the buffer is bound to hinted target before the operation (if not
|
||
|
|
* already).
|
||
|
8 years ago
|
* @see @ref setTargetHint(), @fn_gl2_keyword{UnmapNamedBuffer,UnmapBuffer},
|
||
|
|
* @fn_gl_extension_keyword{UnmapNamedBuffer,EXT,direct_state_access},
|
||
|
|
* eventually @fn_gl{BindBuffer} and @fn_gl_keyword{UnmapBuffer}
|
||
|
9 years ago
|
* @requires_gles30 Extension @extension{OES,mapbuffer} in OpenGL
|
||
|
11 years ago
|
* ES 2.0.
|
||
|
|
* @requires_gles Buffer mapping is not available in WebGL.
|
||
|
14 years ago
|
*/
|
||
|
12 years ago
|
bool unmap();
|
||
|
11 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
12 years ago
|
#ifdef DOXYGEN_GENERATING_OUTPUT
|
||
|
|
private:
|
||
|
|
#endif
|
||
|
12 years ago
|
/* There should be no need to use these from user code. Also it's a bit
|
||
|
|
unfortunate to have the parameter typed as TargetHint while in this
|
||
|
|
case it is no hint at all, but it allows to have cleaner public
|
||
|
|
binding API (just with short Target name) */
|
||
|
|
static void unbindInternal(TargetHint target) { bindInternal(target, nullptr); }
|
||
|
|
void bindInternal(TargetHint target) { bindInternal(target, this); }
|
||
|
12 years ago
|
|
||
|
16 years ago
|
private:
|
||
|
12 years ago
|
static void bindInternal(TargetHint hint, Buffer* buffer);
|
||
|
8 years ago
|
TargetHint MAGNUM_GL_LOCAL bindSomewhereInternal(TargetHint hint);
|
||
|
12 years ago
|
|
||
|
12 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
8 years ago
|
static void MAGNUM_GL_LOCAL bindImplementationFallback(Target target, GLuint firstIndex, Containers::ArrayView<Buffer* const> buffers);
|
||
|
12 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
8 years ago
|
static void MAGNUM_GL_LOCAL bindImplementationMulti(Target target, GLuint firstIndex, Containers::ArrayView<Buffer* const> buffers);
|
||
|
12 years ago
|
#endif
|
||
|
|
|
||
|
8 years ago
|
static void MAGNUM_GL_LOCAL bindImplementationFallback(Target target, GLuint firstIndex, Containers::ArrayView<const std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers);
|
||
|
12 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
8 years ago
|
static void MAGNUM_GL_LOCAL bindImplementationMulti(Target target, GLuint firstIndex, Containers::ArrayView<const std::tuple<Buffer*, GLintptr, GLsizeiptr>> buffers);
|
||
|
12 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
8 years ago
|
static void MAGNUM_GL_LOCAL copyImplementationDefault(Buffer& read, Buffer& write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
8 years ago
|
static void MAGNUM_GL_LOCAL copyImplementationDSA(Buffer& read, Buffer& write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
|
||
|
|
static void MAGNUM_GL_LOCAL copyImplementationDSAEXT(Buffer& read, Buffer& write, GLintptr readOffset, GLintptr writeOffset, GLsizeiptr size);
|
||
|
14 years ago
|
#endif
|
||
|
|
#endif
|
||
|
14 years ago
|
|
||
|
11 years ago
|
explicit Buffer(GLuint id, TargetHint targetHint, ObjectFlags flags) noexcept: _id{id}, _targetHint{targetHint}, _flags{flags} {}
|
||
|
|
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL createImplementationDefault();
|
||
|
12 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL createImplementationDSA();
|
||
|
12 years ago
|
#endif
|
||
|
|
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL createIfNotAlready();
|
||
|
12 years ago
|
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
11 years ago
|
Buffer& setLabelInternal(Containers::ArrayView<const char> label);
|
||
|
11 years ago
|
#endif
|
||
|
12 years ago
|
|
||
|
9 years ago
|
#if !defined(MAGNUM_TARGET_GLES) && defined(MAGNUM_BUILD_DEPRECATED)
|
||
|
|
CORRADE_DEPRECATED("used only by deprecated subData<T>()") void subDataInternal(GLintptr offset, GLsizeiptr size, GLvoid* data);
|
||
|
12 years ago
|
#endif
|
||
|
|
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL getParameterImplementationDefault(GLenum value, GLint* data);
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL getParameterImplementationDSA(GLenum value, GLint* data);
|
||
|
|
void MAGNUM_GL_LOCAL getParameterImplementationDSAEXT(GLenum value, GLint* data);
|
||
|
13 years ago
|
#endif
|
||
|
|
|
||
|
13 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL getSubDataImplementationDefault(GLintptr offset, GLsizeiptr size, GLvoid* data);
|
||
|
|
void MAGNUM_GL_LOCAL getSubDataImplementationDSA(GLintptr offset, GLsizeiptr size, GLvoid* data);
|
||
|
|
void MAGNUM_GL_LOCAL getSubDataImplementationDSAEXT(GLintptr offset, GLsizeiptr size, GLvoid* data);
|
||
|
13 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL dataImplementationDefault(GLsizeiptr size, const GLvoid* data, BufferUsage usage);
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL dataImplementationDSA(GLsizeiptr size, const GLvoid* data, BufferUsage usage);
|
||
|
|
void MAGNUM_GL_LOCAL dataImplementationDSAEXT(GLsizeiptr size, const GLvoid* data, BufferUsage usage);
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL subDataImplementationDefault(GLintptr offset, GLsizeiptr size, const GLvoid* data);
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL subDataImplementationDSA(GLintptr offset, GLsizeiptr size, const GLvoid* data);
|
||
|
|
void MAGNUM_GL_LOCAL subDataImplementationDSAEXT(GLintptr offset, GLsizeiptr size, const GLvoid* data);
|
||
|
14 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL invalidateImplementationNoOp();
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL invalidateImplementationARB();
|
||
|
14 years ago
|
#endif
|
||
|
|
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL invalidateSubImplementationNoOp(GLintptr offset, GLsizeiptr length);
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL invalidateSubImplementationARB(GLintptr offset, GLsizeiptr length);
|
||
|
14 years ago
|
#endif
|
||
|
|
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL * mapImplementationDefault(MapAccess access);
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL * mapImplementationDSA(MapAccess access);
|
||
|
|
void MAGNUM_GL_LOCAL * mapImplementationDSAEXT(MapAccess access);
|
||
|
14 years ago
|
#endif
|
||
|
|
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL * mapRangeImplementationDefault(GLintptr offset, GLsizeiptr length, MapFlags access);
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL * mapRangeImplementationDSA(GLintptr offset, GLsizeiptr length, MapFlags access);
|
||
|
|
void MAGNUM_GL_LOCAL * mapRangeImplementationDSAEXT(GLintptr offset, GLsizeiptr length, MapFlags access);
|
||
|
14 years ago
|
#endif
|
||
|
|
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL flushMappedRangeImplementationDefault(GLintptr offset, GLsizeiptr length);
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
8 years ago
|
void MAGNUM_GL_LOCAL flushMappedRangeImplementationDSA(GLintptr offset, GLsizeiptr length);
|
||
|
|
void MAGNUM_GL_LOCAL flushMappedRangeImplementationDSAEXT(GLintptr offset, GLsizeiptr length);
|
||
|
14 years ago
|
#endif
|
||
|
|
|
||
|
8 years ago
|
bool MAGNUM_GL_LOCAL unmapImplementationDefault();
|
||
|
14 years ago
|
#ifndef MAGNUM_TARGET_GLES
|
||
|
8 years ago
|
bool MAGNUM_GL_LOCAL unmapImplementationDSA();
|
||
|
|
bool MAGNUM_GL_LOCAL unmapImplementationDSAEXT();
|
||
|
14 years ago
|
#endif
|
||
|
11 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
14 years ago
|
GLuint _id;
|
||
|
12 years ago
|
TargetHint _targetHint;
|
||
|
11 years ago
|
ObjectFlags _flags;
|
||
|
16 years ago
|
};
|
||
|
|
|
||
|
11 years ago
|
#ifndef MAGNUM_TARGET_WEBGL
|
||
|
14 years ago
|
CORRADE_ENUMSET_OPERATORS(Buffer::MapFlags)
|
||
|
11 years ago
|
#endif
|
||
|
14 years ago
|
|
||
|
12 years ago
|
/** @debugoperatorclassenum{Magnum::Buffer,Magnum::Buffer::TargetHint} */
|
||
|
8 years ago
|
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, Buffer::TargetHint value);
|
||
|
12 years ago
|
|
||
|
8 years ago
|
#ifndef MAGNUM_TARGET_GLES2
|
||
|
12 years ago
|
/** @debugoperatorclassenum{Magnum::Buffer,Magnum::Buffer::Target} */
|
||
|
8 years ago
|
MAGNUM_GL_EXPORT Debug& operator<<(Debug& debug, Buffer::Target value);
|
||
|
12 years ago
|
#endif
|
||
|
13 years ago
|
|
||
|
9 years ago
|
inline Buffer::Buffer(NoCreateT) noexcept: _id{0}, _targetHint{TargetHint::Array}, _flags{ObjectFlag::DeleteOnDestruction} {}
|
||
|
11 years ago
|
|
||
|
9 years ago
|
inline Buffer::Buffer(Buffer&& other) noexcept: _id{other._id}, _targetHint{other._targetHint}, _flags{other._flags} {
|
||
|
13 years ago
|
other._id = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
inline Buffer& Buffer::operator=(Buffer&& other) noexcept {
|
||
|
11 years ago
|
using std::swap;
|
||
|
|
swap(_id, other._id);
|
||
|
|
swap(_targetHint, other._targetHint);
|
||
|
11 years ago
|
swap(_flags, other._flags);
|
||
|
13 years ago
|
return *this;
|
||
|
|
}
|
||
|
|
|
||
|
11 years ago
|
inline GLuint Buffer::release() {
|
||
|
|
const GLuint id = _id;
|
||
|
|
_id = 0;
|
||
|
|
return id;
|
||
|
|
}
|
||
|
|
|
||
|
9 years ago
|
#if !defined(MAGNUM_TARGET_GLES) && defined(MAGNUM_BUILD_DEPRECATED)
|
||
|
8 years ago
|
CORRADE_IGNORE_DEPRECATED_PUSH
|
||
|
13 years ago
|
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);
|
||
|
12 years ago
|
if(size) subDataInternal(offset, size*sizeof(T), data);
|
||
|
11 years ago
|
return data;
|
||
|
13 years ago
|
}
|
||
|
8 years ago
|
CORRADE_IGNORE_DEPRECATED_POP
|
||
|
13 years ago
|
#endif
|
||
|
|
|
||
|
16 years ago
|
}
|
||
|
|
|
||
|
|
#endif
|