Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::OpenGL::VertexBufferObject Class Reference

Convenience wrapper for array buffers with vertex layout management. More...

#include <spk_vertex_buffer_object.hpp>

Inheritance diagram for spk::OpenGL::VertexBufferObject:
Inheritance graph
Collaboration diagram for spk::OpenGL::VertexBufferObject:
Collaboration graph

Classes

class  Layout
 Describes vertex attributes and ensures stride consistency. More...

Public Member Functions

 VertexBufferObject (Usage p_usage)
 Constructs VBO with a usage hint.
 VertexBufferObject (const VertexBufferObject &p_other)
 Copies GPU handle ownership and layout from another VBO.
VertexBufferObjectoperator= (const VertexBufferObject &p_other)
 Copies GPU handle ownership and layout from another VBO.
Layoutlayout ()
 Access layout descriptor.
const Layoutlayout () const
 Access layout descriptor.
size_t vertexCount () const
 Number of vertices based on current stride and size.
template<typename TVertex>
std::vector< TVertex > pull () const
 Downloads vertices from GPU memory.
template<typename TVertex>
void setVertices (const std::vector< TVertex > &p_vertices)
 Replaces buffer contents with provided vertices.
template<typename TVertex>
void setVertices (std::initializer_list< TVertex > p_vertices)
 Replaces buffer contents with initializer list of vertices.
template<typename TVertex>
void pushVertex (const TVertex &p_vertex)
 Appends a single vertex to the buffer.
template<typename TVertex>
void pushVertices (const std::vector< TVertex > &p_vertices)
 Appends multiple vertices to the buffer.
template<typename TVertex>
void pushVertices (std::initializer_list< TVertex > p_vertices)
 Appends vertices from an initializer list.
template<typename TVertex>
std::span< TVertex > vertices ()
 Provides mutable access to the CPU-side vertex span.
template<typename TVertex>
std::span< const TVertex > vertices () const
 Provides immutable access to the CPU-side vertex span.
Public Member Functions inherited from spk::OpenGL::BufferObject
 BufferObject (const Type &p_type, const Usage &p_usage)
 Constructs a buffer with target type and usage hint.
 BufferObject (const BufferObject &p_other)
 Copies buffer configuration and staged content from another buffer.
BufferObjectoperator= (const BufferObject &p_other)
 Copies buffer configuration and staged content from another buffer.
void reserve (size_t p_size)
 Reserves CPU-side storage without changing size.
void resize (size_t p_size)
 Resizes CPU-side buffer and marks for sync.
void swapData (std::vector< uint8_t > &p_data)
 Swaps CPU staging buffer with external vector.
template<typename TType>
void setData (const std::vector< TType > &p_data)
 Replaces buffer contents with a vector of trivially copyable values.
template<typename TType>
void setData (std::initializer_list< TType > p_data)
 Replaces buffer contents with an initializer list of values.
void setData (const void *p_data, size_t p_size)
 Replaces CPU buffer content with raw data.
void pushData (const void *p_data, size_t p_size)
 Appends raw data to CPU buffer.
template<typename TType>
void pushData (const TType &p_value)
 Appends a single trivially copyable value to the buffer.
template<typename TType>
void pushData (const std::vector< TType > &p_values)
 Appends a vector of trivially copyable values to the buffer.
template<typename TType>
void pushData (std::initializer_list< TType > p_values)
 Appends an initializer list of trivially copyable values to the buffer.
void editData (const void *p_data, size_t p_offset, size_t p_size)
 Overwrites a range of the CPU buffer.
template<typename TType>
void editData (const TType &p_value, size_t p_offset)
 Overwrites part of the buffer with a single value.
size_t size () const
 Returns the current CPU buffer size.
Bufferbuffer ()
 Mutable access to the CPU staging buffer.
const Bufferbuffer () const
 Const access to the CPU staging buffer.
Buffer::value_type * data ()
 Mutable pointer to underlying bytes.
const Buffer::value_type * data () const
 Const pointer to underlying bytes.
Public Member Functions inherited from spk::ActivableObject
 ActivableObject ()
 Builds a deactivated object.
 ActivableObject (ActivationStatus p_initial)
 Builds with a custom initial activation state.
void activate ()
 Sets the state to Activated.
void deactivate ()
 Sets the state to Deactivated.
void toggle ()
 Toggles between activated and deactivated states.
bool isActive () const
 Checks whether the object is currently activated.
Contract addActivationCallback (const Job &p_callback)
 Registers a callback executed when the object activates.
Contract addDeactivationCallback (const Job &p_callback)
 Registers a callback executed when the object deactivates.
Public Member Functions inherited from spk::StatefulObject< ActivationStatus >
 StatefulObject (const ActivationStatus &p_initialState)
 Builds with an initial state.
StatefulObjectoperator= (const StatefulObject &p_other)=delete
void setState (const ActivationStatus &p_newState)
 Sets a new state and triggers callbacks registered for it.
ActivationStatus state () const
 Returns the current state.
Contract addCallback (const ActivationStatus &p_state, const Job &p_callback)
 Subscribes a callback for a specific state.
Public Member Functions inherited from spk::SynchronizableObject
void requestSynchronization () noexcept
 Marks the object as needing synchronization.
bool needsSynchronization () const noexcept
 Checks if synchronization is pending.
void synchronize ()
 Performs synchronization if requested.
void forceSynchronization ()
 Forces synchronization regardless of current flag.

Protected Member Functions

void _onSynchronize () override
 Uploads vertex data to GPU and configures attributes when requested.
void _ensureStrideForRead (size_t p_vertexSize) const
 Validates that the layout stride matches a requested vertex size.
Protected Member Functions inherited from spk::OpenGL::BufferObject
void _registerCallbacks ()
 Registers GPU lifecycle callbacks with the cached buffer id.

Additional Inherited Members

Public Types inherited from spk::OpenGL::BufferObject
enum class  Type : GLenum {
  Unknow = GL_INVALID_ENUM , Storage = GL_ARRAY_BUFFER , Element = GL_ELEMENT_ARRAY_BUFFER , Uniform = GL_UNIFORM_BUFFER ,
  Texture = GL_TEXTURE_BUFFER , TransformFeedback = GL_TRANSFORM_FEEDBACK_BUFFER , ShaderStorage = GL_SHADER_STORAGE_BUFFER , PixelPack = GL_PIXEL_PACK_BUFFER ,
  PixelUnpack = GL_PIXEL_UNPACK_BUFFER , DrawIndirect = GL_DRAW_INDIRECT_BUFFER , AtomicCounter = GL_ATOMIC_COUNTER_BUFFER
}
 Supported OpenGL binding targets for buffer uploads.
enum class  Usage : GLenum {
  Unknow = GL_INVALID_ENUM , Static = GL_STATIC_DRAW , Dynamic = GL_DYNAMIC_DRAW , Stream = GL_STREAM_DRAW ,
  StaticRead = GL_STATIC_READ , DynamicRead = GL_DYNAMIC_READ , StreamRead = GL_STREAM_READ , StaticCopy = GL_STATIC_COPY ,
  DynamicCopy = GL_DYNAMIC_COPY , StreamCopy = GL_STREAM_COPY
}
 Usage hints forwarded to the OpenGL driver.
using Buffer = std::vector<uint8_t>
 CPU-side byte buffer used as staging before GPU upload.
Public Types inherited from spk::ActivableObject
using Contract = StatefulObject<ActivationStatus>::Contract
 Subscription handle controlling callback lifetime.
using Job = StatefulObject<ActivationStatus>::Job
 Callback signature executed on activation state changes.
Public Types inherited from spk::StatefulObject< ActivationStatus >
using Contract
 Handle allowing subscribers to manage callback lifetimes.
using Job
 Callable invoked when the object transitions to a state.
Protected Attributes inherited from spk::OpenGL::BufferObject
Type _type
 Buffer target selected at construction.
Usage _usage
 Driver usage hint selected at construction.
spk::CachedData< GLuint > _id
 Lazily created GPU buffer identifier.
size_t _gpuCapacity = 0
 Capacity reserved on the GPU for the current buffer.
Buffer _content
 CPU staging area mirrored to GPU on synchronization.

Detailed Description

Convenience wrapper for array buffers with vertex layout management.

See also
VertexBufferObject::Layout, BufferSetObject

Constructor & Destructor Documentation

◆ VertexBufferObject() [1/2]

spk::OpenGL::VertexBufferObject::VertexBufferObject ( Usage p_usage)

Constructs VBO with a usage hint.

Parameters
p_usageUsage flag.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ VertexBufferObject() [2/2]

spk::OpenGL::VertexBufferObject::VertexBufferObject ( const VertexBufferObject & p_other)

Copies GPU handle ownership and layout from another VBO.

Parameters
p_otherSource VBO.
Here is the call graph for this function:

Member Function Documentation

◆ _ensureStrideForRead()

void spk::OpenGL::VertexBufferObject::_ensureStrideForRead ( size_t p_vertexSize) const
protected

Validates that the layout stride matches a requested vertex size.

Parameters
p_vertexSizeSize in bytes of the vertex type being read.
Here is the caller graph for this function:

◆ _onSynchronize()

void spk::OpenGL::VertexBufferObject::_onSynchronize ( )
overrideprotectedvirtual

Uploads vertex data to GPU and configures attributes when requested.

Reimplemented from spk::OpenGL::BufferObject.

Here is the call graph for this function:

◆ layout() [1/2]

VertexBufferObject::Layout & spk::OpenGL::VertexBufferObject::layout ( )

Access layout descriptor.

Returns
Mutable layout.
Here is the caller graph for this function:

◆ layout() [2/2]

const VertexBufferObject::Layout & spk::OpenGL::VertexBufferObject::layout ( ) const

Access layout descriptor.

Returns
Const layout.

◆ operator=()

VertexBufferObject & spk::OpenGL::VertexBufferObject::operator= ( const VertexBufferObject & p_other)

Copies GPU handle ownership and layout from another VBO.

Parameters
p_otherSource VBO.
Returns
Reference to this.
Here is the call graph for this function:

◆ pull()

template<typename TVertex>
std::vector< TVertex > spk::OpenGL::VertexBufferObject::pull ( ) const
inline

Downloads vertices from GPU memory.

Template Parameters
TVertexTrivially copyable vertex type expected from the buffer.
Returns
Vector containing all vertices in the buffer.
Here is the call graph for this function:

◆ pushVertex()

template<typename TVertex>
void spk::OpenGL::VertexBufferObject::pushVertex ( const TVertex & p_vertex)
inline

Appends a single vertex to the buffer.

Template Parameters
TVertexTrivially copyable vertex type stored in the buffer.
Parameters
p_vertexVertex to append.
Here is the call graph for this function:

◆ pushVertices() [1/2]

template<typename TVertex>
void spk::OpenGL::VertexBufferObject::pushVertices ( const std::vector< TVertex > & p_vertices)
inline

Appends multiple vertices to the buffer.

Template Parameters
TVertexTrivially copyable vertex type stored in the buffer.
Parameters
p_verticesVertices to append.
Here is the call graph for this function:

◆ pushVertices() [2/2]

template<typename TVertex>
void spk::OpenGL::VertexBufferObject::pushVertices ( std::initializer_list< TVertex > p_vertices)
inline

Appends vertices from an initializer list.

Template Parameters
TVertexTrivially copyable vertex type stored in the buffer.
Parameters
p_verticesVertices to append.
Here is the call graph for this function:

◆ setVertices() [1/2]

template<typename TVertex>
void spk::OpenGL::VertexBufferObject::setVertices ( const std::vector< TVertex > & p_vertices)
inline

Replaces buffer contents with provided vertices.

Template Parameters
TVertexTrivially copyable vertex type stored in the buffer.
Parameters
p_verticesVertex data to upload.
Here is the call graph for this function:

◆ setVertices() [2/2]

template<typename TVertex>
void spk::OpenGL::VertexBufferObject::setVertices ( std::initializer_list< TVertex > p_vertices)
inline

Replaces buffer contents with initializer list of vertices.

Template Parameters
TVertexTrivially copyable vertex type stored in the buffer.
Parameters
p_verticesVertex data to upload.
Here is the call graph for this function:

◆ vertexCount()

size_t spk::OpenGL::VertexBufferObject::vertexCount ( ) const

Number of vertices based on current stride and size.

Returns
Vertex count.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vertices() [1/2]

template<typename TVertex>
std::span< TVertex > spk::OpenGL::VertexBufferObject::vertices ( )
inline

Provides mutable access to the CPU-side vertex span.

Template Parameters
TVertexVertex POD type.
Returns
Span of vertices stored locally.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ vertices() [2/2]

template<typename TVertex>
std::span< const TVertex > spk::OpenGL::VertexBufferObject::vertices ( ) const
inline

Provides immutable access to the CPU-side vertex span.

Template Parameters
TVertexVertex POD type.
Returns
Const span of vertices stored locally.
Here is the call graph for this function:

The documentation for this class was generated from the following files: