cgv
Loading...
Searching...
No Matches
uniform_buffer.h
1#pragma once
2
3#include "context.h"
4#include "vertex_buffer.h"
5
6namespace cgv {
7namespace render {
8
11template<class T>
13public:
18
23 bool create(const context& ctx) {
24 return vertex_buffer::create(ctx, sizeof(T));
25 }
26
32 bool create(const context& ctx, size_t array_size) {
33 return vertex_buffer::create(ctx, sizeof(T) * array_size);
34 }
35
41 bool resize(const context& ctx, size_t array_size) {
42 return vertex_buffer::resize(ctx, sizeof(T) * array_size);
43 }
44
50 bool resize(const context& ctx, const T& data) {
51 return vertex_buffer::resize(ctx, reinterpret_cast<const uint8_t*>(&data), sizeof(T));
52 }
53
59 bool resize(const context& ctx, const std::vector<T>& array) {
60 return vertex_buffer::resize(ctx, reinterpret_cast<const uint8_t*>(array.data()), sizeof(T) * array.size());
61 }
62
71 bool replace(const context& ctx, const T& data) {
72 return vertex_buffer::replace(ctx, 0, reinterpret_cast<const uint8_t*>(&data), sizeof(T));
73 }
74
82 bool replace(const context& ctx, const std::vector<T>& array) {
83 return vertex_buffer::replace(ctx, 0, reinterpret_cast<const uint8_t*>(array.data()), sizeof(T) * array.size());
84 }
85
92 bool resize_or_replace(const context& ctx, const T& data) {
93 return size_in_bytes != sizeof(T) ? resize(ctx, data) : replace(ctx, data);
94 }
95
102 bool resize_or_replace(const context& ctx, std::vector<T>& array) {
103 return size_in_bytes != sizeof(T) ? resize(ctx, array) : replace(ctx, array);
104 }
105
107 bool create_or_resize() = delete;
108};
109
110} // namespace render
111} // namespace cgv
base class for all drawables, which is independent of the used rendering API.
Definition context.h:668
Helper class template for handling vertex buffers of type uniform buffer object that explicitly state...
bool create(const context &ctx, size_t array_size)
Create an empty buffer of size array_size * sizeof(T).
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.
bool create(const context &ctx)
Create an empty buffer of size sizeof(T).
bool replace(const context &ctx, const std::vector< T > &array)
Replace the content with the given array.
bool resize(const context &ctx, const T &data)
Resize to sizeof(T) and set the given data.
bool replace(const context &ctx, const T &data)
Replace the content with 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 resize(const context &ctx, size_t array_size)
Resize to array_size * sizeof(T).
uniform_buffer(VertexBufferUsage usage=VertexBufferUsage::VBU_STREAM_COPY)
Construct with the given usage.
bool resize_or_replace(const context &ctx, const T &data)
Resize to sizeof(T) if necessary and set the given data.
VertexBufferUsage usage
usage defaults to VBU_STATIC_DRAW
Definition context.h:513
a vertex buffer is an unstructured memory block on the GPU.
bool resize(const context &ctx, size_t size_in_bytes)
resize vertex buffer to size size given in bytes clearing all data
bool create(const context &ctx, size_t size_in_bytes)
create empty vertex buffer of size size given in bytes
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.
Definition context.h:485
@ VBU_STREAM_COPY
Modified once and used at most a few times; Modified by reading data from the GL, and used as the sou...
Definition context.h:490
VertexBufferType
Provides vertex buffer types to allow implicit binding.
Definition context.h:472
@ VBT_UNIFORM
The buffer contains uniforms and will be bound to GL_UNIFORM_BUFFER.
Definition context.h:477
this header is dependency free
Definition print.h:11