cgv
Loading...
Searching...
No Matches
attribute_array_binding.cxx
1#include <cgv/base/base.h>
2#include "attribute_array_binding.h"
3#include "shader_program.h"
4#include <cgv/render/vertex_buffer.h>
5
6namespace cgv {
7 namespace render {
8
9bool attribute_array_binding::set_global_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)
10{
11 return ctx.set_attribute_array_void(0, loc, element_type, &vbo, reinterpret_cast<const void*>(offset_in_bytes), nr_elements, stride_in_bytes);
12}
13
16{
17 return ctx.set_element_array(0, &vbe);
18}
19
21bool attribute_array_binding::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)
22{
23 return ctx.set_attribute_array_void(this, loc, element_type, &vbo, reinterpret_cast<const void*>(offset_in_bytes), nr_elements, stride_in_bytes);
24}
25
26int attribute_array_binding::get_attribute_location(const context& ctx, const shader_program& prog, const std::string& attr_name) const
27{
28 return prog.get_attribute_location(ctx, attr_name);
29}
30
32bool attribute_array_binding::bind_attribute_array(const context& ctx, const shader_program& prog, const std::string& attribute_name, type_descriptor element_type, const vertex_buffer& vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes)
33{
34 int loc = prog.get_attribute_location(ctx, attribute_name);
35 if (loc == -1)
36 return false;
37 return set_attribute_array(ctx, loc, element_type, vbo, offset_in_bytes, nr_elements, stride_in_bytes);
38}
39
42{
43 return ctx.set_element_array(this, &vbe);
44}
45
48{
49 return ctx.is_attribute_array_enabled(0, loc);
50}
51
54{
55 return ctx.enable_attribute_array(0, loc, true);
56}
59{
60 return ctx.enable_attribute_array(0, loc, false);
61}
62
64bool attribute_array_binding::set_global_attribute_array(const context& ctx, int loc, const vertex_buffer& vbo, type_descriptor td, size_t size, size_t offset, unsigned stride)
65{
66 const void* ptr = 0;
67 reinterpret_cast<size_t&>(ptr) = offset;
68 return ctx.set_attribute_array_void(0, loc, td, &vbo, ptr, size, stride);
69}
70
86
89{
90 return ctx.attribute_array_binding_create(*this);
91}
92
95{
96 if (handle)
97 ctx.attribute_array_binding_destruct(*this);
98}
99
102{
103 if (!is_created()) {
104 ctx.error("attribute_array_binding::enable() attribute array binding must be created before enable", this);
105 return false;
106 }
107 return ctx.attribute_array_binding_enable(*this);
108}
109
112{
113 return ctx.attribute_array_binding_disable(*this);
114}
115
118{
119 return ctx.enable_attribute_array(this, loc, true);
120}
123{
124 if (loc < 0)
125 return false;
126 return ctx.is_attribute_array_enabled(this, loc);
127}
130{
131 return ctx.enable_attribute_array(this, loc, false);
132}
133
134 }
135}
bool set_element_array(const context &ctx, const vertex_buffer &vbe)
set the elment array to the given vertex buffer object which must me of type VBT_INDICES
bool enable(context &ctx)
enable whole the attribute array binding object
static bool enable_global_array(const context &ctx, int loc)
enable attribute array of given location
bool create(const context &ctx)
create the attribute array binding object
void destruct(const context &ctx)
destruct attribute array binding object
static bool set_global_attribute_array(const context &ctx, int loc, const vertex_buffer &vbo, type_descriptor td, size_t size, size_t offset, unsigned stride=0)
point array of vertex attribute at location loc to vertex buffer array array stored in CPU memory; in...
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
static bool is_global_array_enabled(const context &ctx, int loc)
check whether an attribute array is enabled
static bool set_global_element_array(const context &ctx, const vertex_buffer &vbe)
set the global elment array to the given vertex buffer object which must me of type VBT_INDICES
static bool disable_global_array(const context &ctx, int loc)
disable attribute array of given location
~attribute_array_binding()
destruct attribute array binding object
bool enable_array(const context &ctx, int loc)
enable array for vertex attribute at location loc
bool disable_array(const context &ctx, int loc)
disable array for attribute at location loc
bool bind_attribute_array(const context &ctx, const shader_program &prog, const std::string &attribute_name, const T &array)
convenience function that determines attribute location in program by name and then uses set_attribut...
bool set_attribute_array(const context &ctx, int loc, const T &array)
set vertex attribute location to given array and enable array
attribute_array_binding()
default constructor does not create attribute array binding
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
virtual void error(const std::string &message, const render_component *rc=0) const
error handling
Definition context.cxx:219
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 shader program combines several shader code fragments to a complete definition of the shading pipel...
int get_attribute_location(const context &ctx, const std::string &name) const
query location index of an attribute
a vertex buffer is an unstructured memory block on the GPU.
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