Class buffer¶
Defined in File buffer.hpp
Class Documentation¶
-
class
legion::rendering
::
buffer
¶ Low level rendering buffer that can be used for all kinds of purposes. Depending on the target it could be a vertex buffer or shader storage buffer or something else.
Public Functions
-
buffer
() = default¶ Faux constructor. To prevent unnecessary GPU allocations the default constructor doesn’t actually create a buffer. This means that default initialized buffers are invalid temporary objects until they get properly initialized.
-
template<typename
T
>buffer
(GLenum target, const std::vector<T> &data, GLenum usage)¶ Main allocating constructor. This constructor actually creates the GPU side buffer and binds it to this instance.
- Note
Read more at docs.gl.
- Parameters
target
: The buffer type to create. eg: GL_ARRAY_BUFFER, GL_SHADER_STORAGE_BUFFERdata
: Vector of data to store in the buffers VRAM allocation.usage
: Intended memory usage. eg: GL_STATIC_DRAW (Data doesn’t change and ised for drawing many times), GL_DYNAMIC_READ (Changes all the time and is used for reading back to CPU)
-
buffer
(GLenum target, size_type size, void *data, GLenum usage)¶ Main allocating constructor. This constructor actually creates the GPU side buffer and binds it to this instance.
- Note
Read more at docs.gl.
- Note
If the buffer is allocated with a nullptr as the data pointer then the memory in VRAM may be garbage when read. Do not assume null writes to happen.
- Parameters
target
: The buffer type to create. eg: GL_ARRAY_BUFFER, GL_SHADER_STORAGE_BUFFERsize
: Size in bytes to allocate on VRAM.data
: Data to send to VRAM. This may be a nullptr if you only want to allocate VRAM but keep the memory empty.usage
: Intended memory usage. eg: GL_STATIC_DRAW (Data doesn’t change and ised for drawing many times), GL_DYNAMIC_READ (Changes all the time and is used for reading back to CPU)
-
buffer
(GLenum target, GLenum usage)¶ Main non allocating constructor. This constructor actually creates the GPU side buffer and binds it to this instance.
- Note
This constructor doesn’t actually allocate any VRAM to this buffer yet and requires a bufferData call in order to allocate memory for it.
- Parameters
target
: The buffer type to create. eg: GL_ARRAY_BUFFER, GL_SHADER_STORAGE_BUFFERusage
: Intended memory usage. eg: GL_STATIC_DRAW (Data doesn’t change and ised for drawing many times), GL_DYNAMIC_READ (Changes all the time and is used for reading back to CPU)
-
app::gl_id
id
() const¶ Returns the rendering API id of the buffer. Useful for low level native rendering.
-
GLenum
target
() const¶ Returns the rendering API type/target of the buffer. Useful for low level native rendering.
-
GLenum
usage
() const¶ Returns the rendering API intended memory usage of the buffer. Useful for low level native rendering.
-
size_type
size
() const¶ Returns the current size of the buffer in bytes.
-
void
bindBufferBase
(uint index) const¶ Bind buffer to a set indexed buffer binding location in shaders.
- Note
Read more at docs.gl.
- Note
Target must be GL_ATOMIC_COUNTER_BUFFER, GL_TRANSFORM_FEEDBACK_BUFFER, GL_UNIFORM_BUFFER or GL_SHADER_STORAGE_BUFFER.
- Parameters
index
: Indexed buffer binding location to bind to.
-
void
resize
(size_type newSize) const¶ Resize the buffer to a new size. This reallocates VRAM and thus invalidates all data in the buffer.
-
template<typename
T
>
inline voidbufferData
(const std::vector<T> &data) const¶ Send new data to the VRAM of the buffer. This may reallocate the buffer if the size of the new data is larger than the previously allocated VRAM.
- Parameters
data
: Vector with the data to send.
-
void
bufferData
(size_type size, void *data) const¶ Send new data to the VRAM of the buffer. This may reallocate the buffer if the size of the new data is larger than the previously allocated VRAM.
- Parameters
size
: Size the data to send.data
: Pointer to the data to send. (Should not be a nullptr, if you only want to allocate/reallocate then use the resize function.)
-
void
bufferData
(size_type offset, size_type size, void *data) const¶ Send new data to the VRAM of the buffer with a certain offset. This function does not reallocate data and thus the sum of offset + size cannot be more that the size of the buffer.
- Parameters
offset
: Offset since the start of the buffer in bytes.size
: Size of the new data in bytes.data
: Pointer to the new data to write.
-
void
bind
() const¶ Bind the buffer to the current context. Useful for low level native rendering.
-
void
release
() const¶ Release the buffer from the current context. Useful for low level native rendering.
-