![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Core/GL/ShaderStorageBuffer.h>
Specialization of Buffer for OpenGL Shader Storage Buffer Object. More...
Inheritance diagram for ShaderStorageBuffer:Specialization of Buffer for OpenGL Shader Storage Buffer Object.
SSBOs are the most powerful way to transport data between the CPU and OpenGL shaders and allow for both read and write access.
Example for setting up an SSBO and attaching it to a shader
Corresponding GLSL shader code:
ARB_shader_storage_buffer_object extension. Public Member Functions | |
| ShaderStorageBuffer (Usage usageHint=Buffer::Usage::StaticDraw) | |
| Instantiate a new Shader Storage Buffer Object. | |
| void | bindBase (uint32_t index) |
| Bind the buffer to the storage block with the given index. | |
| template<typename... Ts> | |
| void | setSubData (size_t offset, std::vector< Ts >... data) |
| Upload data into the buffer starting at the given offset. | |
| template<typename T> | |
| void | setData (Utils::Span< T > data) |
| Upload data to the buffer. | |
| template<typename T> | |
| void | setData (const std::vector< T > &data) |
| Upload data to the buffer. | |
| template<typename T> | |
| void | getData (std::vector< T > &outData) |
| Download all data from the buffer attached to the given target that fits into the given vector. | |
| template<typename T> | |
| void | getSubData (int64_t offsetBytes, int64_t sizeBytes, std::vector< T > &outData) |
| Download the given range of data of the buffer attached to the given target. | |
| size_t | bufferSize () const |
| Returns the number of bytes that were previously allocated on the GPU for this buffer. | |
| 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. | |
Public Member Functions inherited from Buffer | |
| 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 () |
| Unbind any bound shader storage buffer. | |
Static Public Member Functions inherited from Buffer | |
| static void | unbind (Target target) |
| Binds 0 to the specified target. | |
Additional Inherited Members | |
Public Types inherited from Buffer | |
| 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... | |
Protected Member Functions inherited from Buffer | |
| 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 inherited from Buffer | |
| 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 inherited from Buffer | |
| 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. | |
|
explicit |
Instantiate a new Shader Storage Buffer Object.
| usageHint | Expected usage pattern of the buffer |
| std::runtime_error | if the corresponding OpenGL buffer object could not be created. |
|
inline |
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. |
| void setData | ( | Utils::Span< T > | data | ) |
Upload data to the buffer.
| data | Contiguous sequence of elements that shall be uploaded to the buffer. |
| void setData | ( | const std::vector< T > & | data | ) |
Upload data to the buffer.
| data | Vector of elements that shall be uploaded to the buffer. |
| void getData | ( | std::vector< T > & | outData | ) |
Download all data from the buffer attached to the given target that fits into the given vector.
| outData | Vector in which the data should be downloaded. The size of the vector must correspond the number of bytes to be downloaded. |
| void getSubData | ( | int64_t | offsetBytes, |
| int64_t | sizeBytes, | ||
| std::vector< T > & | outData ) |
Download the given range of data of the buffer attached to the given target.
| offsetBytes | Specifies the offset into the buffer object's data store from which data will be returned, measured in bytes. |
| sizeBytes | Specifies the size in bytes of the data store region being returned. |
| outData | Vector into which the data should be downloaded, will be resized to fit the data. |
| void allocateBuffer | ( | int64_t | numBytes | ) |
Allocates storage on the GPU for this buffer object.
| numBytes | Number of bytes to allocate. |
| void setSubData | ( | size_t | offset, |
| Utils::Span< Ts >... | data ) |
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. |