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];
95 if(vbo_ptr->get_size_in_bytes() == nr_elements *
sizeof(T))
96 res = vbo_ptr->replace(ctx, 0, array_ptr, nr_elements);
98 vbo_ptr->destruct(ctx);
99 res = vbo_ptr->create(ctx, array_ptr, nr_elements);
102 vbo_ptr =
new vertex_buffer(VBT_VERTICES, default_usage);
103 res = vbo_ptr->create(ctx, array_ptr, nr_elements);
106 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);
110 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);
112 template <
typename C,
typename T>
113 bool set_composed_attribute_array(
const context& ctx,
int loc,
const C* array_ptr,
size_t nr_elements,
const T& elem) {
115 vertex_buffer*& vbo_ptr = vbos[loc];
117 if(vbo_ptr->get_size_in_bytes() == nr_elements *
sizeof(C))
118 res = vbo_ptr->replace(ctx, 0, array_ptr, nr_elements);
120 vbo_ptr->destruct(ctx);
121 res = vbo_ptr->create(ctx, array_ptr, nr_elements);
124 vbo_ptr =
new vertex_buffer(VBT_VERTICES, default_usage);
125 res = vbo_ptr->create(ctx, array_ptr, nr_elements);
128 res = ctx.set_attribute_array_void(&aab, loc,
129 type_descriptor(element_descriptor_traits<T>::get_type_descriptor(elem),
true),
132 nr_elements,
sizeof(C));
135 template <
typename C,
typename T>
136 bool ref_composed_attribute_array(
const context& ctx,
int loc,
int loc_ref,
const C* array_ptr,
size_t nr_elements,
const T& elem) {
137 vertex_buffer*& vbo_ptr = vbos[loc_ref];
140 return ctx.set_attribute_array_void(&aab, loc,
141 type_descriptor(element_descriptor_traits<T>::get_type_descriptor(elem),
true),
144 nr_elements,
sizeof(C));
146 void remove_attribute_array(
const context& ctx,
int loc);
149 attribute_array_manager(VertexBufferUsage _default_usage = VBU_STREAM_DRAW);
151 ~attribute_array_manager();
153 bool has_attribute(
const context& ctx,
int loc)
const;
156 auto it = vbos.find(loc);
162 bool is_created()
const;
170 void destruct(
const context& ctx);
base class for all drawables, which is independent of the used rendering API.