21 std::map<int, vertex_buffer*>
vbos;
27 bool set_indices(
const context& ctx,
const T& array) {
32 res = vbo_ptr->
replace(ctx, 0, array_descriptor_traits <T>::get_address(array), array_descriptor_traits < T>::get_nr_elements(array));
35 res = vbo_ptr->
create(ctx, array);
38 vbo_ptr =
new vertex_buffer(VBT_INDICES, default_usage);
39 res = vbo_ptr->
create(ctx, array);
42 res = ctx.set_element_array(&aab, vbo_ptr);
47 bool set_indices(
const context& ctx,
const T* array,
size_t count) {
49 vertex_buffer*& vbo_ptr = vbos[-1];
52 res = vbo_ptr->
replace(ctx, 0, array, count);
54 vbo_ptr->destruct(ctx);
55 res = vbo_ptr->create(ctx, array, count);
58 vbo_ptr =
new vertex_buffer(VBT_INDICES, default_usage);
59 res = vbo_ptr->create(ctx, array, count);
62 res = ctx.set_element_array(&aab, vbo_ptr);
66 bool has_index_buffer()
const;
68 void remove_indices(
const context& ctx);
71 bool set_attribute_array(
const context& ctx,
int loc,
const T& array) {
73 vertex_buffer*& vbo_ptr = vbos[loc];
75 if(vbo_ptr->get_size_in_bytes() == array_descriptor_traits <T>::get_size(array))
76 res = vbo_ptr->replace(ctx, 0, array_descriptor_traits <T>::get_address(array), array_descriptor_traits < T>::get_nr_elements(array));
78 vbo_ptr->destruct(ctx);
79 res = vbo_ptr->create(ctx, array);
82 vbo_ptr =
new vertex_buffer(VBT_VERTICES, default_usage);
83 res = vbo_ptr->create(ctx, array);
86 res = ctx.set_attribute_array_void(&aab, loc, array_descriptor_traits <T>::get_type_descriptor(array), vbo_ptr, 0, array_descriptor_traits < T>::get_nr_elements(array));
91 bool set_attribute_array(
const context& ctx,
int loc,
const T* array_ptr,
size_t nr_elements,
unsigned stride) {
93 vertex_buffer*& vbo_ptr = vbos[loc];
94 size_t buffer_size = nr_elements*std::max(
sizeof(T),
size_t(stride));
96 if(vbo_ptr->get_size_in_bytes() == buffer_size)
97 res = vbo_ptr->replace(ctx, 0,
reinterpret_cast<const uint8_t*
>(array_ptr), buffer_size);
99 vbo_ptr->destruct(ctx);
100 res = vbo_ptr->create(ctx,
reinterpret_cast<const uint8_t*
>(array_ptr), buffer_size);
103 vbo_ptr =
new vertex_buffer(VBT_VERTICES, default_usage);
104 res = vbo_ptr->create(ctx,
reinterpret_cast<const uint8_t*
>(array_ptr), buffer_size);
107 res = ctx.set_attribute_array_void(&aab, loc, type_descriptor(element_descriptor_traits<T>::get_type_descriptor(*array_ptr),
true), vbo_ptr, 0, nr_elements, stride);
111 bool set_attribute_array(
const context& ctx,
int loc, type_descriptor element_type,
const vertex_buffer& vbo,
size_t offset_in_bytes,
size_t nr_elements,
unsigned stride_in_bytes);
113 template <
typename C,
typename T>
114 bool set_composed_attribute_array(
const context& ctx,
int loc,
const C* array_ptr,
size_t nr_elements,
const T& elem) {
116 vertex_buffer*& vbo_ptr = vbos[loc];
118 if(vbo_ptr->get_size_in_bytes() == nr_elements *
sizeof(C))
119 res = vbo_ptr->replace(ctx, 0, array_ptr, nr_elements);
121 vbo_ptr->destruct(ctx);
122 res = vbo_ptr->create(ctx, array_ptr, nr_elements);
125 vbo_ptr =
new vertex_buffer(VBT_VERTICES, default_usage);
126 res = vbo_ptr->create(ctx, array_ptr, nr_elements);
129 res = ctx.set_attribute_array_void(&aab, loc,
130 type_descriptor(element_descriptor_traits<T>::get_type_descriptor(elem),
true),
133 nr_elements,
sizeof(C));
136 template <
typename C,
typename T>
137 bool ref_composed_attribute_array(
const context& ctx,
int loc,
int loc_ref,
const C* array_ptr,
size_t nr_elements,
const T& elem) {
138 vertex_buffer*& vbo_ptr = vbos[loc_ref];
141 return ctx.set_attribute_array_void(&aab, loc,
142 type_descriptor(element_descriptor_traits<T>::get_type_descriptor(elem),
true),
145 nr_elements,
sizeof(C));
147 void remove_attribute_array(
const context& ctx,
int loc);
150 attribute_array_manager(VertexBufferUsage _default_usage = VBU_STREAM_DRAW);
152 ~attribute_array_manager();
154 bool has_attribute(
const context& ctx,
int loc)
const;
157 auto it = vbos.find(loc);
163 bool is_created()
const;
171 void destruct(
const context& ctx);
base class for all drawables, which is independent of the used rendering API.