ImFusion SDK 4.3
VertexBuffer Class Reference

#include <ImFusion/Core/GL/VertexBuffer.h>

Specialization of Buffer to store vertex array data. More...

+ Inheritance diagram for VertexBuffer:

Detailed Description

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:

std::vector<vec3f> vertices = {
vec3f(-1.0, -1.0, 0.0),
vec3f(1.0, -1.0, 0.0),
vec3f(-1.0, 1.0, 0.0)
};
vbo.bind();
vbo.setData(vertices);
void bind() const
Binds the buffer to the target given during construction.
Specialization of Buffer to store vertex array data.
Definition VertexBuffer.h:59
void draw(Primitive mode) const
Renders a single primitive using all vertices of this VBO.
void setData(const std::vector< Ts > &... arrays)
Upload data to the buffer.
Definition VertexBuffer.h:266
@ Triangles
Vertices 0, 1, and 2 form a triangle. Vertices 3, 4, and 5 form a triangle. And so on.
Definition Types.h:71
Note
Since VertexBuffer uses a default Vertex Array Object (VAO) for rendering, the VertexBuffer::draw() overloads are not bind-sensitive, i.e. both vertex buffer and index buffer (if needed) are bound automatically. The buffer bind state after a draw call is undefined/driver implementation- specific. All other member functions remain bind-sensitive as specified in the base class.
See also

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.
 
- 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 std::unique_ptr< VertexBuffercreateFullscreenSquare ()
 Factory method to create a default rectangle with position and texture coordinates.
 
static void unbind ()
 Unbind any bound vertex 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.
 

Constructor & Destructor Documentation

◆ VertexBuffer()

VertexBuffer ( Usage usageHint = Buffer::Usage::StaticDraw)
explicit

Instantiate a new vertex buffer.

Parameters
usageHintExpected usage pattern of the buffer
Exceptions
std::runtime_errorif the corresponding OpenGL buffer object could not be created.

Member Function Documentation

◆ createFullscreenSquare()

static std::unique_ptr< VertexBuffer > createFullscreenSquare ( )
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.

See also
GL::FullscreenSquare

◆ setData() [1/2]

template<typename... Ts>
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.

Parameters
arraysPack 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).

◆ setData() [2/2]

template<typename... Ts>
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.

Parameters
arraysPack 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).

◆ setVertexAttribNormalization()

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.

Note
This setting is not sticky and must be reconfigured after every call to setData().
See also
https://www.khronos.org/opengl/wiki/GLAPI/glVertexAttribPointer

◆ drawMultiRestart()

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.

Parameters
modePrimitive to render
primitiveRestartIndicesList 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.

The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close