![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Core/GL/Buffer.h>
Wrapper class for OpenGL Buffer Objects. More...
Wrapper class for OpenGL Buffer Objects.
OpenGL buffers serve many different purposes of which this base class implements the common interface. However, this class is not meant to be used directly. Instead you should use one of the specializations such as VertexBuffer, ShaderStorageBuffer, etc. instead for improved type safety. Furthermore, each specialization provides an extended API that is tailored to its buffer type.
Public Types | |
enum class | Target { Array = 0x8892 , AtomicCounter = 0x92C0 , CopyRead = 0x8F36 , CopyWrite = 0x8F37 , DrawIndirect = 0x8F3F , ElementArray = 0x8893 , PixelPack = 0x88EB , PixelUnpack = 0x88EC , ShaderStorage = 0x90D2 , Texture = 0x8C2A , TransformFeedback = 0x8C8E , Uniform = 0x8A11 } |
Enumeration of the different OpenGL buffer types. More... | |
enum class | Usage { StreamDraw = 0x88E0 , StreamRead = 0x88E1 , StreamCopy = 0x88E2 , StaticDraw = 0x88E4 , StaticRead = 0x88E5 , StaticCopy = 0x88E6 , DynamicDraw = 0x88E8 , DynamicRead = 0x88E9 , DynamicCopy = 0x88EA } |
Enumeration for usage pattern hints to provide to the GPU when allocating data. More... | |
Public Member Functions | |
Buffer (Target target, Usage usage) | |
Creates a new Buffer. | |
void | bind () const |
Binds the buffer to the target given during construction. | |
Usage | usageHint () const |
Returns the buffer usage hint passed to OpenGL during allocation. | |
void | setUsageHint (Usage value) |
Sets the buffer usage hint passed to OpenGL during allocation. | |
uint32_t | id () const |
Return a handle to the internal OpenGL buffer object. | |
Static Public Member Functions | |
static void | unbind (Target target) |
Binds 0 to the specified target. | |
Protected Member Functions | |
void | allocateBuffer (int64_t numBytes) |
Allocates storage on the GPU for this buffer object. | |
template<typename... Ts> | |
void | setSubData (size_t offset, Utils::Span< Ts >... data) |
Upload data into the buffer starting at the given offset. | |
template<typename... Ts> | |
size_t | getBufferSize (Utils::Span< Ts >... data) const |
Compute the total number of bytes used by all provided data together. | |
Static Protected Member Functions | |
static void | glBufferSubDataImpl (Target target, int64_t offset, int64_t size, const void *data) |
forwards to OpenGL's glBufferSubData() . | |
static void | glGetBufferSubDataImpl (Target target, int64_t offset, int64_t size, void *data) |
forwards to OpenGL's glGetBufferSubData() . | |
Protected Attributes | |
const Target | m_target |
Target binding point for the buffer, will never change for a Buffer instance. | |
Usage | m_usageHint |
Buffer usage hint passed to OpenGL unless explicitly specified otherwise. | |
uint32_t | m_id = 0 |
Internal OpenGL handle to buffer object. | |
int64_t | m_bufferSize = 0 |
Number of bytes allocated on the GPU. | |
|
strong |
Enumeration of the different OpenGL buffer types.
If you use the specializations of Buffer, you will not need to use these.
|
strong |
Enumeration for usage pattern hints to provide to the GPU when allocating data.
Enumerator | |
---|---|
StreamDraw | The data is modified once and used at most a few times; it is modified by the application, and used as the source for GL drawing and image specification commands. |
StreamRead | The data is modified once and used at most a few times; it is modified by reading data from the GL device, and used to return that data when queried by the application. |
StreamCopy | The data is modified once and used at most a few times; it is modified by reading data from the GL device, and used as the source for GL drawing and image specification commands. |
StaticDraw | The data is modified once and used many times; the data is modified by the application, and used as the source for GL drawing and image specification commands. |
StaticRead | The data is modified once and used many times; it is modified by reading data from the GL device, and used to return that data when queried by the application. |
StaticCopy | The data is modified once and used many times; it is modified by reading data from the GL device, and used as the source for GL drawing and image specification commands. |
DynamicDraw | The data is modified repeatedly and used many times; it is modified by the application, and used as the source for GL drawing and image specification commands. |
DynamicRead | The data is modified repeatedly and used many times; it is modified by reading data from the GL device, and used to return that data when queried by the application. |
DynamicCopy | The data is modified repeatedly and used many times; it is modified by reading data from the GL device, and used as the source for GL drawing and image specification commands. |
Creates a new Buffer.
Needs a valid OpenGL context.
std::runtime_error | if the corresponding OpenGL buffer object could not be created. |
uint32_t id | ( | ) | const |
Return a handle to the internal OpenGL buffer object.
|
protected |
Allocates storage on the GPU for this buffer object.
numBytes | Number of bytes to allocate. |
|
protected |
Upload data into the buffer starting at the given offset.
offset | Offset in bytes into the buffer object's data store where start writing data. |
data | Pack of data arrays that should be copied to the buffer. If you provide multiple spans they will be concatenated and end up next to each other in the buffer without any padding. |