cgv
|
a vertex buffer is an unstructured memory block on the GPU. More...
#include <vertex_buffer.h>
Public Member Functions | |
vertex_buffer (VertexBufferType _type=VBT_VERTICES, VertexBufferUsage _usage=VBU_STATIC_DRAW) | |
construct from description of component format, where the default format specifies a color buffer with alpha channel | |
~vertex_buffer () | |
calls the destruct method if necessary | |
void | bind (context &ctx, VertexBufferType type=VBT_UNDEF) const |
Bind buffer to appropriate target. | |
void | unbind (context &ctx, VertexBufferType type=VBT_UNDEF) const |
Unbind buffer from the appropriate target. | |
void | unbind (context &ctx, unsigned index) const |
Unbind this buffer from the appropriate indexed binding target. | |
void | unbind (context &ctx, VertexBufferType type, unsigned index) const |
Unbind from the choosen binding target. | |
void | bind (context &ctx, unsigned index) const |
Bind this buffer to the appropriate indexed buffer target. | |
void | bind (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. | |
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) |
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) |
Copy elements from the buffer into the CPU array. | |
void | destruct (const context &ctx) |
destruct the render buffer | |
![]() | |
vertex_buffer_base () | |
initialize members | |
![]() | |
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 | |
Protected Attributes | |
size_t | size_in_bytes |
Additional Inherited Members | |
![]() | |
VertexBufferType | type |
buffer type defaults to VBT_VERTICES | |
VertexBufferUsage | usage |
usage defaults to VBU_STATIC_DRAW | |
![]() | |
void * | handle |
void * | internal_format |
void * | user_data |
const context * | ctx_ptr |
keep pointer to my context | |
std::string | last_error |
a string that contains the last error | |
a vertex buffer is an unstructured memory block on the GPU.
Definition at line 12 of file vertex_buffer.h.
cgv::render::vertex_buffer::vertex_buffer | ( | VertexBufferType | _type = VBT_VERTICES , |
VertexBufferUsage | _usage = VBU_STATIC_DRAW |
||
) |
construct from description of component format, where the default format specifies a color buffer with alpha channel
Definition at line 7 of file vertex_buffer.cxx.
References cgv::render::vertex_buffer_base::type, and cgv::render::vertex_buffer_base::usage.
cgv::render::vertex_buffer::~vertex_buffer | ( | ) |
calls the destruct method if necessary
Definition at line 15 of file vertex_buffer.cxx.
References cgv::render::render_component::ctx_ptr, destruct(), and cgv::render::context::make_current().
void cgv::render::vertex_buffer::bind | ( | context & | ctx, |
unsigned | index | ||
) | const |
Bind this buffer to the appropriate indexed buffer target.
ctx | The CGV rendering context. |
index | Which index of the binding target to use. |
This function will use the type information given to vertex_buffer::vertex_buffer() to determine the correct binding target.
Definition at line 47 of file vertex_buffer.cxx.
References cgv::render::vertex_buffer_base::type.
void cgv::render::vertex_buffer::bind | ( | context & | ctx, |
VertexBufferType | type, | ||
unsigned | index | ||
) | const |
Bind this buffer to the appropriate indexed buffer target.
ctx | The CGV rendering context. |
type | Will bind according to the given type. |
index | Which index of the binding target to use. |
Definition at line 52 of file vertex_buffer.cxx.
void cgv::render::vertex_buffer::bind | ( | context & | ctx, |
VertexBufferType | type = VBT_UNDEF |
||
) | const |
Bind buffer to appropriate target.
ctx | The CGV rendering context. |
type | If cgv::render::VBT_UNDEF, will use type information as given to vertex_buffer::vertex_buffer(). Otherwise will bind according to the given type. |
The explicit type specification allows interpreting the underlying buffer in different ways. One example would be the manipulation of vertex data in a compute shader. Here you would bind your vertex buffer as a simple shader storage buffer before dispatching the compute call.
Definition at line 30 of file vertex_buffer.cxx.
References cgv::render::vertex_buffer_base::type, and cgv::render::VBT_UNDEF.
bool cgv::render::vertex_buffer::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.
ctx | The CGV rendering context. |
src_offset_in_bytes | Offset in bytes from the beginning of the source buffer. |
size_in_bytes | The amount of bytes, which will be copied. |
dst | The buffer in which to copy the bytes into. |
dst_offset_in_bytes | Offset in bytes from the beginning of the destination buffer. |
Definition at line 80 of file vertex_buffer.cxx.
|
inline |
Copy elements from the buffer into the CPU array.
T | the fundamental data type of the CPU array. |
ctx | The CGV rendering context. |
src_offset_in_bytes | Offset in bytes from the beginning of the source buffer. |
array_ptr | The destination array in which to copy the elements. |
nr_elements | How many of the elements to copy into the destination buffer. |
Definition at line 182 of file vertex_buffer.h.
|
inline |
Copy elements from the buffer into the CPU array.
T | A generic array type. |
ctx | The CGV rendering context. |
array | The destination array in which to copy the data. |
src_offset_in_bytes | Offset in bytes from the beginning of the source buffer. |
This function will implicity infer how many bytes to copy from the dimensions of the generic array. Therefore you need to make sure, that your std::vector or cgv::math::vec is appropriately sized beforehand! Otherwise the underlying copy command might cross the boundaries of the GPU buffer and or read unrelated data.
Definition at line 199 of file vertex_buffer.h.
|
inline |
create vertex buffer and copy data from CPU array array
into buffer memory
Definition at line 83 of file vertex_buffer.h.
|
inline |
create vertex buffer and copy data from CPU array array_ptr
into buffer memory
Definition at line 90 of file vertex_buffer.h.
bool cgv::render::vertex_buffer::create | ( | const context & | ctx, |
size_t | size_in_bytes | ||
) |
create empty vertex buffer of size size
given in bytes
Definition at line 58 of file vertex_buffer.cxx.
Referenced by cgv::render::build_render_info(), cgv::render::mesh_render_info::construct_element_vbo(), create_or_resize(), cgv::plot::plot_base::init(), cgv::render::gl::image_drawable::init(), and cgv::render::gl::gl_context::prepare_attributes().
|
inline |
Convenience wrapper to either create() or resize() the buffer.
T | A generic array type. |
ctx | The CGV rendering context. |
array | The array which will be copied into the buffer. |
Definition at line 138 of file vertex_buffer.h.
|
inline |
Convenience wrapper to either create() or resize() the buffer.
T | the fundamental data type of the CPU array. |
ctx | The CGV rendering context. |
array_ptr | The array which will be copied into the buffer. |
nr_elements | The count of elements in the array. |
Definition at line 151 of file vertex_buffer.h.
bool cgv::render::vertex_buffer::create_or_resize | ( | const context & | ctx, |
size_t | size_in_bytes | ||
) |
Convenience wrapper to either create() or resize() the buffer.
ctx | The CGV rendering context. |
size_in_bytes | The desired size in bytes of the buffer. |
Definition at line 75 of file vertex_buffer.cxx.
References create(), is_created(), and resize().
void cgv::render::vertex_buffer::destruct | ( | const context & | ctx | ) |
destruct the render buffer
Definition at line 86 of file vertex_buffer.cxx.
Referenced by cgv::plot::plot_base::clear(), cgv::render::gl::image_drawable::clear(), cgv::render::gl::gl_context::prepare_attributes(), cgv::render::gl::gl_context::release_attributes(), and ~vertex_buffer().
size_t cgv::render::vertex_buffer::get_size_in_bytes | ( | ) | const |
Retrieves the current size of the buffer in bytes.
Definition at line 25 of file vertex_buffer.cxx.
|
overridevirtual |
Check whether the vertex buffer has been created.
Reimplemented from cgv::render::render_component.
Definition at line 64 of file vertex_buffer.cxx.
Referenced by create_or_resize().
|
inline |
replace part (starting at byte offset buffer_offset_in_bytes
) or whole vertex buffer content from nr_elements
of CPU array array_ptr
Definition at line 157 of file vertex_buffer.h.
Referenced by cgv::render::mesh_render_info::construct_element_vbo(), and cgv::render::gl::gl_context::prepare_attributes().
|
inline |
resize vertex buffer and copy data from CPU array array
into buffer memory
Definition at line 110 of file vertex_buffer.h.
|
inline |
resize vertex buffer and copy data from CPU array array_ptr
into buffer memory
Definition at line 117 of file vertex_buffer.h.
bool cgv::render::vertex_buffer::resize | ( | const context & | ctx, |
size_t | size_in_bytes | ||
) |
resize vertex buffer to size size
given in bytes clearing all data
Definition at line 69 of file vertex_buffer.cxx.
Referenced by create_or_resize().
void cgv::render::vertex_buffer::unbind | ( | context & | ctx, |
unsigned | index | ||
) | const |
Unbind this buffer from the appropriate indexed binding target.
ctx | The CGV rendering context. |
index | Which slot of the target to unbind from. |
Definition at line 40 of file vertex_buffer.cxx.
References cgv::render::vertex_buffer_base::type.
void cgv::render::vertex_buffer::unbind | ( | context & | ctx, |
VertexBufferType | type, | ||
unsigned | index | ||
) | const |
Unbind from the choosen binding target.
ctx | The CGV rendering context. |
type | If cgv::render::VBT_UNDEF, will use type information as given to vertex_buffer::vertex_buffer(). Otherwise will unbind according to the given type. |
index | Which slot of the target to unbind from. |
Definition at line 42 of file vertex_buffer.cxx.
References cgv::render::vertex_buffer_base::type.
void cgv::render::vertex_buffer::unbind | ( | context & | ctx, |
VertexBufferType | type = VBT_UNDEF |
||
) | const |
Unbind buffer from the appropriate target.
ctx | The CGV rendering context. |
type | If cgv::render::VBT_UNDEF, will use type information as given to vertex_buffer::vertex_buffer(). Otherwise will unbind according to the given type. |
index | The index to unbind from, on an index binding target. |
Definition at line 35 of file vertex_buffer.cxx.
References cgv::render::vertex_buffer_base::type, and cgv::render::VBT_UNDEF.
|
protected |
Definition at line 15 of file vertex_buffer.h.