3#include <cgv/render/context.h>
4#include <cgv/render/element_traits.h>
50 void unbind(
context& ctx,
unsigned index)
const;
68 void bind(
context& ctx,
unsigned index)
const;
80 bool create(
const context& ctx,
size_t size_in_bytes);
90 bool create(
const context& ctx,
const T* array_ptr,
size_t nr_elements) {
91 size_in_bytes = nr_elements *
sizeof(T);
92 return ctx.vertex_buffer_create(*
this, array_ptr, size_in_bytes);
99 bool is_created()
const override;
105 size_t get_size_in_bytes()
const;
107 bool resize(
const context& ctx,
size_t size_in_bytes);
109 template <typename T, typename = std::enable_if_t<std::is_class<T>::value,
bool>>
116 template <
typename T>
118 size_in_bytes = nr_elements *
sizeof(T);
119 return ctx.vertex_buffer_resize(*
this, array_ptr, size_in_bytes);
128 bool create_or_resize(
const context& ctx,
size_t size_in_bytes);
137 template <typename T, typename = std::enable_if_t<std::is_class<T>::value,
bool>>
140 return !is_created() ? create(ctx, array) : resize(ctx, array);
153 return !is_created() ? create(ctx, array_ptr, nr_elements) : resize(ctx, array_ptr, nr_elements);
156 template <
typename T>
157 bool replace(
const context& ctx,
size_t buffer_offset_in_bytes,
const T* array_ptr,
size_t nr_elements) {
158 return ctx.vertex_buffer_replace(*
this, buffer_offset_in_bytes, nr_elements*
sizeof(T), array_ptr);
170 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;
181 template <
typename T>
182 bool copy(
const context& ctx,
size_t src_offset_in_bytes, T* array_ptr,
size_t nr_elements) {
183 return ctx.vertex_buffer_copy_back(*
this, src_offset_in_bytes,
sizeof(T)*nr_elements, array_ptr);
198 template <typename T, typename = std::enable_if_t<std::is_class<T>::value,
bool>>
199 bool copy(
const context& ctx, T& array,
size_t src_offset_in_bytes = 0)
202 return ctx.vertex_buffer_copy_back(*
this, src_offset_in_bytes, size_in_bytes,
206 void destruct(
const context& ctx);
212#include <cgv/config/lib_end.h>
base class for all drawables, which is independent of the used rendering API.
base interface for a vertex buffer
a vertex buffer is an unstructured memory block on the GPU.
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(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 copy(const context &ctx, T &array, size_t src_offset_in_bytes=0)
Copy elements from the buffer into the CPU array.
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 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.
bool create_or_resize(const context &ctx, const T &array)
Convenience wrapper to either create() or resize() the buffer.
bool create(const context &ctx, const T &array)
create vertex buffer and copy data from CPU array array into buffer memory
bool resize(const context &ctx, const T &array)
resize vertex buffer and copy data from CPU array array into buffer memory
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_...
VertexBufferUsage
Provides vertex buffer usage hints as defined in OpenGL.
@ VBU_STATIC_DRAW
Modified once and used many times; Modified by the application, and used as the source for GL drawing...
VertexBufferType
Provides vertex buffer types to allow implicit binding.
@ VBT_VERTICES
The buffer contains vertices and will be bound to GL_ARRAY_BUFFER.
@ VBT_UNDEF
The buffer has no type.