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

Convenience wrapper for element array buffers storing 32-bit indices. More...

#include <spk_index_buffer_object.hpp>

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

Public Member Functions

 IndexBufferObject (Usage p_usage)
 Constructs an index buffer with a usage hint.
 IndexBufferObject (const IndexBufferObject &p_other)=default
 Copies buffer configuration and stored indices.
IndexBufferObjectoperator= (const IndexBufferObject &p_other)=default
 Assigns index buffer contents from another instance.
void reserve (size_t p_nbIndexes)
 Reserves capacity for a number of indices.
void resize (size_t p_nbIndexes)
 Resizes index storage and marks for sync.
void setIndexes (const std::vector< uint32_t > &p_indexes)
 Replaces indices by moving a vector.
void pushIndex (uint32_t p_index)
 Appends a single index.
void pushIndexes (const std::vector< uint32_t > &p_indexes)
 Appends multiple indices from vector.
void pushIndexes (std::initializer_list< uint32_t > p_values)
 Appends multiple indices from initializer list.
size_t nbIndexes () const
 Returns the number of stored indices.
size_t nbTriangles () const
 Returns the number of triangles (indices / 3).
std::vector< uint32_t > pull () const
 Returns a copy of the indices.
std::span< uint32_t > indices ()
 Mutable span over index data.
std::span< const uint32_t > indices () const
 Const span over index data.
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.

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 Member Functions inherited from spk::OpenGL::BufferObject
void _registerCallbacks ()
 Registers GPU lifecycle callbacks with the cached buffer id.
void _onSynchronize () override
 Uploads staged data to the GPU when synchronization is requested.
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 element array buffers storing 32-bit indices.

See also
VertexBufferObject, BufferSetObject

Constructor & Destructor Documentation

◆ IndexBufferObject() [1/2]

spk::OpenGL::IndexBufferObject::IndexBufferObject ( Usage p_usage)

Constructs an index buffer with a usage hint.

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

◆ IndexBufferObject() [2/2]

spk::OpenGL::IndexBufferObject::IndexBufferObject ( const IndexBufferObject & p_other)
default

Copies buffer configuration and stored indices.

Parameters
p_otherIndex buffer to duplicate.
Here is the call graph for this function:

Member Function Documentation

◆ indices() [1/2]

std::span< uint32_t > spk::OpenGL::IndexBufferObject::indices ( )

Mutable span over index data.

Returns
Span of uint32_t.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ indices() [2/2]

std::span< const uint32_t > spk::OpenGL::IndexBufferObject::indices ( ) const

Const span over index data.

Returns
Span of uint32_t.
Here is the call graph for this function:

◆ nbIndexes()

size_t spk::OpenGL::IndexBufferObject::nbIndexes ( ) const

Returns the number of stored indices.

Returns
Count of indices.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ nbTriangles()

size_t spk::OpenGL::IndexBufferObject::nbTriangles ( ) const

Returns the number of triangles (indices / 3).

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

◆ operator=()

IndexBufferObject & spk::OpenGL::IndexBufferObject::operator= ( const IndexBufferObject & p_other)
default

Assigns index buffer contents from another instance.

Parameters
p_otherIndex buffer to copy from.
Returns
Reference to this buffer.
Here is the call graph for this function:

◆ pull()

std::vector< uint32_t > spk::OpenGL::IndexBufferObject::pull ( ) const

Returns a copy of the indices.

Returns
Vector of indices.
Here is the call graph for this function:

◆ pushIndex()

void spk::OpenGL::IndexBufferObject::pushIndex ( uint32_t p_index)

Appends a single index.

Parameters
p_indexIndex value.
Here is the call graph for this function:

◆ pushIndexes() [1/2]

void spk::OpenGL::IndexBufferObject::pushIndexes ( const std::vector< uint32_t > & p_indexes)

Appends multiple indices from vector.

Parameters
p_indexesSource indices.
Here is the call graph for this function:

◆ pushIndexes() [2/2]

void spk::OpenGL::IndexBufferObject::pushIndexes ( std::initializer_list< uint32_t > p_values)

Appends multiple indices from initializer list.

Parameters
p_valuesSource indices.
Here is the call graph for this function:

◆ reserve()

void spk::OpenGL::IndexBufferObject::reserve ( size_t p_nbIndexes)

Reserves capacity for a number of indices.

Parameters
p_nbIndexesNumber of indices.
Here is the call graph for this function:

◆ resize()

void spk::OpenGL::IndexBufferObject::resize ( size_t p_nbIndexes)

Resizes index storage and marks for sync.

Parameters
p_nbIndexesNew element count.
Here is the call graph for this function:

◆ setIndexes()

void spk::OpenGL::IndexBufferObject::setIndexes ( const std::vector< uint32_t > & p_indexes)

Replaces indices by moving a vector.

Parameters
p_indexesIndex data.
Here is the call graph for this function:

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