cgv
Loading...
Searching...
No Matches
cgv::render::uniform_buffer< T > Class Template Reference

Helper class template for handling vertex buffers of type uniform buffer object that explicitly states the type of data stored. More...

#include <uniform_buffer.h>

Inheritance diagram for cgv::render::uniform_buffer< T >:
cgv::render::vertex_buffer cgv::render::vertex_buffer_base cgv::render::render_component

Public Member Functions

 uniform_buffer (VertexBufferUsage usage=VertexBufferUsage::VBU_STREAM_COPY)
 Construct with the given usage.
 
bool create (const context &ctx)
 Create an empty buffer of size sizeof(T).
 
bool create (const context &ctx, size_t array_size)
 Create an empty buffer of size array_size * sizeof(T).
 
bool resize (const context &ctx, size_t array_size)
 Resize to array_size * sizeof(T).
 
bool resize (const context &ctx, const T &data)
 Resize to sizeof(T) and set the given data.
 
bool resize (const context &ctx, const std::vector< T > &array)
 Resize to array.size() * sizeof(T) and set the given array as data.
 
bool replace (const context &ctx, const T &data)
 Replace the content with the given data.
 
bool replace (const context &ctx, const std::vector< T > &array)
 Replace the content with the given array.
 
bool resize_or_replace (const context &ctx, const T &data)
 Resize to sizeof(T) if necessary and set the given data.
 
bool resize_or_replace (const context &ctx, std::vector< T > &array)
 Resize to array.size() * sizeof(T) if necessary and set the given array as data.
 
bool create_or_resize ()=delete
 Deleted to avoid resizing this buffer to any arbitrary size.
 
- Public Member Functions inherited from cgv::render::vertex_buffer
 vertex_buffer (VertexBufferType type=VBT_VERTICES, VertexBufferUsage usage=VBU_STATIC_DRAW)
 Construct a vertex buffer of the given type and usage.
 
 ~vertex_buffer ()
 calls the destruct method if necessary
 
void bind (const context &ctx, VertexBufferType type=VBT_UNDEF) const
 Bind buffer to appropriate target.
 
void unbind (const context &ctx, VertexBufferType type=VBT_UNDEF) const
 Unbind buffer from the appropriate target.
 
void unbind (const context &ctx, unsigned index) const
 Unbind this buffer from the appropriate indexed binding target.
 
void unbind (const context &ctx, VertexBufferType type, unsigned index) const
 Unbind from the choosen binding target.
 
void bind (const context &ctx, unsigned index) const
 Bind this buffer to the appropriate indexed buffer target.
 
void bind (const context &ctx, VertexBufferType type, unsigned index) const
 Bind this buffer to the appropriate indexed buffer target.
 
bool create (const context &ctx, size_t size_in_bytes)
 create empty vertex buffer of size size given in bytes
 
template<typename T >
bool create (const context &ctx, const T &array)
 create vertex buffer and copy data from CPU array array into buffer memory
 
template<typename T >
bool create (const context &ctx, const T *array_ptr, size_t nr_elements)
 create vertex buffer and copy data from CPU array array_ptr into buffer memory
 
bool is_created () const override
 Check whether the vertex buffer has been created.
 
size_t get_size_in_bytes () const
 Retrieves the current size of the buffer in bytes.
 
bool resize (const context &ctx, size_t size_in_bytes)
 resize vertex buffer to size size given in bytes clearing all data
 
template<typename T , typename = std::enable_if_t<std::is_class<T>::value, bool>>
bool resize (const context &ctx, const T &array)
 resize vertex buffer and copy data from CPU array array into buffer memory
 
template<typename T >
bool resize (const context &ctx, const T *array_ptr, size_t nr_elements)
 resize vertex buffer and copy data from CPU array array_ptr into buffer memory
 
bool create_or_resize (const context &ctx, size_t size_in_bytes)
 Convenience wrapper to either create() or resize() the buffer.
 
template<typename T , typename = std::enable_if_t<std::is_class<T>::value, bool>>
bool create_or_resize (const context &ctx, const T &array)
 Convenience wrapper to either create() or resize() the buffer.
 
template<typename T >
bool create_or_resize (const context &ctx, const T *array_ptr, size_t nr_elements)
 Convenience wrapper to either create() or resize() the buffer.
 
bool clear (const context &ctx)
 Clear the entire buffer to zeros.
 
template<typename T >
bool replace (const context &ctx, size_t buffer_offset_in_bytes, const T *array_ptr, size_t nr_elements)
 replace part (starting at byte offset buffer_offset_in_bytes) or whole vertex buffer content from nr_elements of CPU array array_ptr
 
bool copy (const context &ctx, size_t src_offset_in_bytes, size_t size_in_bytes, vertex_buffer &dst, size_t dst_offset_in_bytes) const
 Copy bytes between different vertex_buffer instances.
 
template<typename T >
bool copy (const context &ctx, size_t src_offset_in_bytes, T *array_ptr, size_t nr_elements) const
 Copy elements from the buffer into the CPU array.
 
template<typename T , typename = std::enable_if_t<std::is_class<T>::value, bool>>
bool copy (const context &ctx, T &array, size_t src_offset_in_bytes=0) const
 Copy elements from the buffer into the CPU array.
 
void destruct (const context &ctx)
 destruct the render buffer
 
- Public Member Functions inherited from cgv::render::render_component
 render_component ()
 initialize members
 
void put_id_void (void *ptr) const
 copy the rendering api specific id the component to the memory location of the given pointer.
 
template<typename T >
void put_id (T &id) const
 cast the refence to rendering api specific representation of component id to the specified type
 

Additional Inherited Members

- Public Attributes inherited from cgv::render::vertex_buffer_base
VertexBufferType type = VBT_VERTICES
 buffer type defaults to VBT_VERTICES
 
VertexBufferUsage usage = VBU_STATIC_DRAW
 usage defaults to VBU_STATIC_DRAW
 
- Public Attributes inherited from cgv::render::render_component
void * handle
 
void * internal_format
 
void * user_data
 
const contextctx_ptr
 keep pointer to my context
 
std::string last_error
 a string that contains the last error
 
- Protected Attributes inherited from cgv::render::vertex_buffer
size_t size_in_bytes = 0
 

Detailed Description

template<class T>
class cgv::render::uniform_buffer< T >

Helper class template for handling vertex buffers of type uniform buffer object that explicitly states the type of data stored.

Definition at line 12 of file uniform_buffer.h.

Constructor & Destructor Documentation

◆ uniform_buffer()

template<class T >
cgv::render::uniform_buffer< T >::uniform_buffer ( VertexBufferUsage  usage = VertexBufferUsage::VBU_STREAM_COPY)
inline

Construct with the given usage.

Parameters
usageThe default usage of this buffer.

Definition at line 17 of file uniform_buffer.h.

Member Function Documentation

◆ create() [1/2]

template<class T >
bool cgv::render::uniform_buffer< T >::create ( const context ctx)
inline

Create an empty buffer of size sizeof(T).

Parameters
ctxThe CGV rendering context.
Returns
True if success, false otherwise.

Definition at line 23 of file uniform_buffer.h.

References cgv::render::vertex_buffer::create().

◆ create() [2/2]

template<class T >
bool cgv::render::uniform_buffer< T >::create ( const context ctx,
size_t  array_size 
)
inline

Create an empty buffer of size array_size * sizeof(T).

Parameters
ctxThe CGV rendering context.
array_sizeThe number of array elements of T to allocate space for.
Returns
True if success, false otherwise.

Definition at line 32 of file uniform_buffer.h.

References cgv::render::vertex_buffer::create().

◆ replace() [1/2]

template<class T >
bool cgv::render::uniform_buffer< T >::replace ( const context ctx,
const std::vector< T > &  array 
)
inline

Replace the content with the given array.

The buffer must have a size in bytes of at least array.size() * sizeof(T). All buffer data beyond the array size is left untouched.

Parameters
ctxThe CGV rendering context.
arrayThe new buffer data.
Returns
True if success, false otherwise.

Definition at line 82 of file uniform_buffer.h.

References cgv::render::vertex_buffer::replace().

◆ replace() [2/2]

template<class T >
bool cgv::render::uniform_buffer< T >::replace ( const context ctx,
const T &  data 
)
inline

Replace the content with the given data.

The buffer should have a size equivalent to that of a single element of T. Otherwise, only the first sizeof(T) bytes of the buffer will be overwritten, with the remaining bytes left untouched.

Parameters
ctxThe CGV rendering context.
dataThe new buffer data.
Returns
True if success, false otherwise.

Definition at line 71 of file uniform_buffer.h.

References cgv::render::vertex_buffer::replace().

Referenced by cgv::render::uniform_buffer< T >::resize_or_replace(), and cgv::render::uniform_buffer< T >::resize_or_replace().

◆ resize() [1/3]

template<class T >
bool cgv::render::uniform_buffer< T >::resize ( const context ctx,
const std::vector< T > &  array 
)
inline

Resize to array.size() * sizeof(T) and set the given array as data.

Parameters
ctxThe CGV rendering context.
arrayThe new buffer data.
Returns
True if success, false otherwise.

Definition at line 59 of file uniform_buffer.h.

References cgv::render::vertex_buffer::resize().

◆ resize() [2/3]

template<class T >
bool cgv::render::uniform_buffer< T >::resize ( const context ctx,
const T &  data 
)
inline

Resize to sizeof(T) and set the given data.

Parameters
ctxThe CGV rendering context.
dataThe new buffer data.
Returns
True if success, false otherwise.

Definition at line 50 of file uniform_buffer.h.

References cgv::render::vertex_buffer::resize().

◆ resize() [3/3]

template<class T >
bool cgv::render::uniform_buffer< T >::resize ( const context ctx,
size_t  array_size 
)
inline

Resize to array_size * sizeof(T).

Parameters
ctxThe CGV rendering context.
array_sizeThe number of array elements of T to allocate space for.
Returns
True if success, false otherwise.

Definition at line 41 of file uniform_buffer.h.

References cgv::render::vertex_buffer::resize().

Referenced by cgv::render::uniform_buffer< T >::resize_or_replace(), and cgv::render::uniform_buffer< T >::resize_or_replace().

◆ resize_or_replace() [1/2]

template<class T >
bool cgv::render::uniform_buffer< T >::resize_or_replace ( const context ctx,
const T &  data 
)
inline

Resize to sizeof(T) if necessary and set the given data.

In contrast to resize(), will not resize the buffer if it already has the exact size needed.

Parameters
ctxThe CGV rendering context.
dataThe new buffer data.
Returns
True if success, false otherwise.

Definition at line 92 of file uniform_buffer.h.

References cgv::render::uniform_buffer< T >::replace(), and cgv::render::uniform_buffer< T >::resize().

◆ resize_or_replace() [2/2]

template<class T >
bool cgv::render::uniform_buffer< T >::resize_or_replace ( const context ctx,
std::vector< T > &  array 
)
inline

Resize to array.size() * sizeof(T) if necessary and set the given array as data.

In contrast to resize(), will not resize the buffer if it already has the exact size needed.

Parameters
ctxThe CGV rendering context.
dataThe new buffer data.
Returns
True if success, false otherwise.

Definition at line 102 of file uniform_buffer.h.

References cgv::render::uniform_buffer< T >::replace(), and cgv::render::uniform_buffer< T >::resize().


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