cgv
Loading...
Searching...
No Matches
attribute_array_binding.h
1#pragma once
2
3#include "element_traits.h"
4
5#include "lib_begin.h"
6
7namespace cgv {
8 namespace render {
9
10 class CGV_API vertex_buffer;
11
20{
21 int get_attribute_location(const context& ctx, const shader_program& prog, const std::string& attr_name) const;
22public:
26 static bool is_global_array_enabled(const context& ctx, int loc);
28 static bool enable_global_array(const context& ctx, int loc);
30 static bool disable_global_array(const context& ctx, int loc);
32 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);
34 template <typename T>
35 static bool set_global_attribute_array(const context& ctx, int loc, const T& array) {
37 }
39 template <typename T>
40 static bool set_global_attribute_array(const context& ctx, int loc, const T* array_ptr, size_t nr_elements, unsigned stride = 0) {
41 return ctx.set_attribute_array_void(0, loc, element_descriptor_traits<T>::get_type_descriptor(*array_ptr), 0, array_ptr, nr_elements, stride);
42 }
44 static bool 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 = 0);
46 static bool set_global_element_array(const context& ctx, const vertex_buffer& vbe);
48
53 bool create(const context& ctx);
55 void destruct(const context& ctx);
57 bool enable(context& ctx);
59 bool disable(context& ctx);
61 bool enable_array(const context& ctx, int loc);
63 bool is_array_enabled(const context& ctx, int loc) const;
65 bool disable_array(const context& ctx, int loc);
67 template <typename T>
68 bool set_attribute_array(const context& ctx, int loc, const T& array) {
70 }
72 template <typename T>
73 bool set_attribute_array(const context& ctx, int loc, const T* value_ptr, unsigned nr_elements, unsigned stride = 0) {
74 return ctx.set_attribute_array_void(this, loc, get_element_type(*value_ptr), 0, value_ptr, nr_elements, stride);
75 }
77 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 = 0);
79 template <typename T>
80 bool bind_attribute_array(const context& ctx, const shader_program& prog, const std::string& attribute_name, const T& array) {
81 int loc = get_attribute_location(ctx, prog, attribute_name);
82 if (loc == -1)
83 return false;
85 }
87 template <typename T>
88 bool bind_attribute_array(const context& ctx, const shader_program& prog, const std::string& attribute_name, const T* value_ptr, unsigned nr_elements, unsigned stride = 0) {
89 int loc = get_attribute_location(ctx, prog, attribute_name);
90 if (loc == -1)
91 return false;
92 return ctx.set_attribute_array_void(this, loc, get_element_type(*value_ptr), 0, value_ptr, nr_elements, stride);
93 }
95 bool bind_attribute_array(const context& ctx,
96 const shader_program& prog, const std::string& attribute_name,
97 type_descriptor element_type, const vertex_buffer& vbo,
98 size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes = 0);
100 bool set_element_array(const context& ctx, const vertex_buffer& vbe);
101};
102
103 }
104}
105
106#include <cgv/config/lib_end.h>
base class for attribute_array_bindings
Definition context.h:403
the attribute_array_binding allows to define vertex attributes (i.e.
bool set_attribute_array(const context &ctx, int loc, const T *value_ptr, unsigned nr_elements, unsigned stride=0)
set a vertex attribute to a single value or an array of values through the cgv::math::vec or std::vec...
bool bind_attribute_array(const context &ctx, const shader_program &prog, const std::string &attribute_name, const T *value_ptr, unsigned nr_elements, unsigned stride=0)
convenience function that determines attribute location in program by name and then uses set_attribut...
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...
static bool set_global_attribute_array(const context &ctx, int loc, const T *array_ptr, size_t nr_elements, unsigned stride=0)
point array of vertex attribute at location loc to array with nr_elements elements pointed to by arra...
static bool set_global_attribute_array(const context &ctx, int loc, const T &array)
point array of vertex attribute at location loc to array array stored in CPU memory; in case of succe...
bool set_attribute_array(const context &ctx, int loc, const T &array)
set vertex attribute location to given array and enable array
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
a shader program combines several shader code fragments to a complete definition of the shading pipel...
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