![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Core/GL/VertexBuffer.h>
Specialization of Buffer to store vertex array data. More...
Specialization of Buffer to store vertex array data.
Vertex array data specifies the input attributes (coordinates, normals, colors, texture coordinates) of the vertices when rendering primitives. The location of an attribute makes it accessible to the vertex shader. The layout of these attributes are managed by the VertexAttrib interface and automatically evaluated by the VertexBuffer when rendering. The setData() overloads will take care of extracting the correct attribute specification from the input data.
The draw() and drawInstanced() overloads will issue rendering commands for primitives formed by the vertex data in the vertex buffer. You can use indexed rendering by using the overloads taking a reference to a IndexBuffer.
Example uploading and rendering a triangle:
Public Member Functions | |
VertexBuffer (Usage usageHint=Buffer::Usage::StaticDraw) | |
Instantiate a new vertex buffer. | |
template<typename... Ts> | |
void | setData (const std::vector< Ts > &... arrays) |
Upload data to the buffer. | |
template<typename... Ts> | |
void | setData (Utils::Span< Ts >... arrays) |
Upload data to the buffer. | |
void | setVertexAttribNormalization (int index, bool isNormalized) |
Sets whether fixed-point/integral data values in the attribute at index should be normalized to or converted directly as fixed-point values keeping their original value in the shader. | |
size_t | numVertices () const |
Returns the number of vertices in attribute 0 as specified in the last call to setData(). | |
void | draw (Primitive mode) const |
Renders a single primitive using all vertices of this VBO. | |
void | draw (Primitive mode, const IndexBuffer &ibo) const |
Renders a single primitive using the given index buffer referencing the vertices of this VBO. | |
void | drawInstanced (Primitive mode, int32_t count) const |
Renders multiple instances of the same primitive using all vertices of this VBO. | |
void | drawInstanced (Primitive mode, int32_t, const IndexBuffer &ibo) const |
Renders multiple instances of the same primitive using the given index buffer referencing the vertices of this VBO. | |
void | drawMultiRestart (Primitive mode, const std::vector< size_t > &primitiveRestartIndices) const |
Renders multiple primitives using all vertices of this VBO and a list of restart indices. | |
![]() | |
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 std::unique_ptr< VertexBuffer > | createFullscreenSquare () |
Factory method to create a default rectangle with position and texture coordinates. | |
static void | unbind () |
Unbind any bound vertex buffer. | |
![]() | |
static void | unbind (Target target) |
Binds 0 to the specified target. | |
Additional Inherited Members | |
![]() | |
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... | |
![]() | |
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 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() . | |
![]() | |
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 vertex buffer.
usageHint | Expected usage pattern of the buffer |
std::runtime_error | if the corresponding OpenGL buffer object could not be created. |
|
static |
Factory method to create a default rectangle with position and texture coordinates.
The rectangle is created as a triangle strip with 4 vertices with the position ([-1..1], [-1..1], 0)
and the texture coordinates ([0..1], [0..1], 0)
. Position attributes are always at location 0 and texture coordinate attributes at location 1 to be compatible with GL::FixedFunctionPipeline.
void setData | ( | const std::vector< Ts > &... | arrays | ) |
Upload data to the buffer.
The buffer needs to be bound before this method is called. Any previous data will be deleted.
arrays | Pack of vertex data arrays that should be uploaded to the buffer. If you provide multiple arrays their data will be concatenated and end up next to each other without any padding. Unless using custom locations via VertexArrayObject, the vertex data will end up in vertex attribute locations 0..N where N is the size of the arrays template parameter pack (i.e. number of parameters passed). |
void setData | ( | Utils::Span< Ts >... | arrays | ) |
Upload data to the buffer.
The buffer needs to be bound before this method is called. Any previous data will be deleted.
arrays | Pack of vertex data arrays that should be uploaded to the buffer. If you provide multiple arrays their data will be concatenated and end up next to each other without any padding. Unless using custom locations via VertexArrayObject, the vertex data will end up in vertex attribute locations 0..N where N is the size of the arrays template parameter pack (i.e. number of parameters passed). |
void setVertexAttribNormalization | ( | int | index, |
bool | isNormalized ) |
Sets whether fixed-point/integral data values in the attribute at index should be normalized to or converted directly as fixed-point values keeping their original value in the shader.
By default all vertex attributes are considered as not normalized (false
) after calling setData(). You can enable normalization by setting it to true
for instance if you have color data in uint8
format on the CPU but want to see the values in [0..1]
range in the shader.
void drawMultiRestart | ( | Primitive | mode, |
const std::vector< size_t > & | primitiveRestartIndices ) const |
Renders multiple primitives using all vertices of this VBO and a list of restart indices.
mode | Primitive to render |
primitiveRestartIndices | List of vertex indices for which to restart the primitive. The first primitive will start at 0, the last primitive will end at the last vertex. |