cgv
Loading...
Searching...
No Matches
attribute_array_manager.cxx
1#include "attribute_array_manager.h"
2
3namespace cgv {
4namespace render {
5
9bool attribute_array_manager::has_attribute(const context& ctx, int loc) const {
10 return aab.is_array_enabled(ctx, loc);
11}
16bool attribute_array_manager::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) {
17 return ctx.set_attribute_array_void(&aab, loc, element_type, &vbo, reinterpret_cast<const void*>(offset_in_bytes), nr_elements, stride_in_bytes);
18}
21 auto iter = vbos.find(-1);
22 if(iter == vbos.end())
23 return false;
24 return iter->second != 0;
25}
27void attribute_array_manager::remove_indices(const context& ctx) {
28 vertex_buffer*& vbo_ptr = vbos[-1];
29 if(vbo_ptr) {
30 vbo_ptr->destruct(ctx);
31 delete vbo_ptr;
32 vbos[-1] = 0;
33 }
34}
35void attribute_array_manager::remove_attribute_array(const context& ctx, int loc) {
36 vertex_buffer*& vbo_ptr = vbos[loc];
37 if(vbo_ptr) {
38 vbo_ptr->destruct(ctx);
39 delete vbo_ptr;
40 vbos.erase(loc);
41 ctx.enable_attribute_array(&aab, loc, false);
42 }
43}
44bool attribute_array_manager::is_created() const {
45 return aab.is_created();
46}
47bool attribute_array_manager::init(context& ctx) {
48 return aab.create(ctx);
49}
50bool attribute_array_manager::enable(context& ctx) {
51 return aab.enable(ctx);
52}
53bool attribute_array_manager::disable(context& ctx) {
54 return aab.disable(ctx);
55}
57void attribute_array_manager::destruct(const context& ctx) {
58 for(auto& p : vbos) {
59 if (p.second) {
60 p.second->destruct(ctx);
61 delete p.second;
62 p.second = 0;
63 }
64 }
65 vbos.clear();
66 aab.destruct(ctx);
67}
68
69}
70}
bool enable(context &ctx)
enable whole the attribute array binding object
bool create(const context &ctx)
create the attribute array binding object
void destruct(const context &ctx)
destruct attribute array binding object
bool disable(context &ctx)
disable whole attribute array binding object
bool is_array_enabled(const context &ctx, int loc) const
check if array of vertex attribute at location loc is enabled
std::map< int, vertex_buffer * > vbos
store vertex buffers generated per attribute location
attribute_array_manager(VertexBufferUsage _default_usage=VBU_STREAM_DRAW)
default initialization
bool has_index_buffer() const
whether aam contains an index buffer
bool has_attribute(const context &ctx, int loc) const
check whether the given attribute is available
attribute_array_binding aab
attribue array binding used to store array pointers
~attribute_array_manager()
destructor calls destruct
VertexBufferUsage default_usage
store default buffer usage
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
virtual bool make_current() const =0
make the current context current if possible
virtual bool is_created() const
return whether component has been created
Definition context.cxx:2046
const context * ctx_ptr
keep pointer to my context
Definition context.h:307
a vertex buffer is an unstructured memory block on the GPU.
void destruct(const context &ctx)
destruct the render buffer
VertexBufferUsage
Provides vertex buffer usage hints as defined in OpenGL.
Definition context.h:427
the cgv namespace
Definition print.h:11
compact type description of data that can be sent to the context; convertible to int
Definition context.h:47