3#include <cgv/render/context.h>
4#include <cgv/render/element_traits.h>
15 size_t size_in_bytes = 0;
73 void bind(
const context& ctx,
unsigned index)
const;
95 bool create(
const context& ctx,
const T* array_ptr,
size_t nr_elements) {
96 size_in_bytes = nr_elements *
sizeof(T);
97 return ctx.vertex_buffer_create(*
this, array_ptr, size_in_bytes);
104 bool is_created()
const override;
110 size_t get_size_in_bytes()
const;
112 bool resize(
const context& ctx,
size_t size_in_bytes);
114 template <typename T, typename = std::enable_if_t<std::is_class<T>::value,
bool>>
121 template <
typename T>
124 size_in_bytes = nr_elements *
sizeof(T);
125 return ctx.vertex_buffer_resize(*
this, array_ptr, size_in_bytes);
134 bool create_or_resize(
const context& ctx,
size_t size_in_bytes);
143 template <typename T, typename = std::enable_if_t<std::is_class<T>::value,
bool>>
168 return ctx.vertex_buffer_clear(*
this, 0, size_in_bytes);
171 template <
typename T>
172 bool replace(
const context& ctx,
size_t buffer_offset_in_bytes,
const T* array_ptr,
size_t nr_elements)
174 return ctx.vertex_buffer_replace(*
this, buffer_offset_in_bytes, nr_elements*
sizeof(T), array_ptr);
186 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;
197 template <
typename T>
198 bool copy(
const context& ctx,
size_t src_offset_in_bytes, T* array_ptr,
size_t nr_elements)
const
200 return ctx.vertex_buffer_copy_back(*
this, src_offset_in_bytes,
sizeof(T)*nr_elements, array_ptr);
215 template <typename T, typename = std::enable_if_t<std::is_class<T>::value,
bool>>
216 bool copy(
const context& ctx, T& array,
size_t src_offset_in_bytes = 0)
const
219 return ctx.vertex_buffer_copy_back(*
this, src_offset_in_bytes, size_in_bytes,
223 void destruct(
const context& ctx);
229#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
VertexBufferType type
buffer type defaults to VBT_VERTICES
VertexBufferUsage usage
usage defaults to VBU_STATIC_DRAW
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
vertex_buffer(VertexBufferType type=VBT_VERTICES, VertexBufferUsage usage=VBU_STATIC_DRAW)
Construct a vertex buffer of the given type and usage.
bool copy(const context &ctx, T &array, size_t src_offset_in_bytes=0) const
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 clear(const context &ctx)
Clear the entire buffer to zeros.
bool resize(const context &ctx, size_t size_in_bytes)
resize vertex buffer to size size given in bytes clearing all data
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.
bool create(const context &ctx, size_t size_in_bytes)
create empty vertex buffer of size size given in bytes
void unbind(const context &ctx, VertexBufferType type=VBT_UNDEF) const
Unbind buffer from the appropriate target.
bool create_or_resize(const context &ctx, const T &array)
Convenience wrapper to either create() or resize() the buffer.
bool is_created() const override
Check whether the vertex buffer has been created.
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
void bind(const context &ctx, VertexBufferType type=VBT_UNDEF) const
Bind buffer to appropriate target.
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_...
namespace for api independent GPU programming
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.
this header is dependency free