cgv
Loading...
Searching...
No Matches
group_renderer.cxx
1#include "group_renderer.h"
2#include <cgv_gl/gl/gl.h>
3#include <cgv_gl/gl/gl_tools.h>
4
5namespace cgv {
6 namespace render {
7
10 {
12 if (has_attribute(ctx, "group_index"))
13 has_group_indices = true;
14 }
17 {
19 has_group_indices = false;
20 }
21
22 void group_renderer::set_group_index_array(const context& ctx, const std::vector<unsigned>& group_indices)
23 {
24 has_group_indices = true;
25 set_attribute_array(ctx, "group_index", group_indices);
26 }
28 void group_renderer::set_group_index_array(const context& ctx, const unsigned* group_indices, size_t nr_elements)
29 {
30 has_group_indices = true;
31 set_attribute_array(ctx, "group_index", group_indices, nr_elements, 0);
32 }
34 void group_renderer::set_group_index_array(const context& ctx, type_descriptor element_type, const vertex_buffer& vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes)
35 {
36 has_group_indices = true;
37 set_attribute_array(ctx, "group_index", element_type, vbo, offset_in_bytes, nr_elements, stride_in_bytes);
38 }
40 has_group_indices = false;
41 remove_attribute_array(ctx, "group_index");
42 }
44 {
45 // validate set attributes
46 bool res = renderer::validate_attributes(ctx);
47 if (!res)
48 return false;
49 if (!get_style_ptr())
50 return false;
51 const group_render_style& grs = get_style<group_render_style>();
52 if (!has_group_indices && (grs.use_group_color || grs.use_group_transformation)) {
53 ctx.error("group_renderer::enable() group_index attribute not set while using group colors or group transformations");
54 res = false;
55 }
56 if (!has_group_colors && grs.use_group_color) {
57 ctx.error("group_renderer::enable() group_colors not set");
58 res = false;
59 }
60 if (!has_group_translations && grs.use_group_transformation) {
61 ctx.error("group_renderer::enable() group_translations not set");
62 res = false;
63 }
64 if (!has_group_rotations && grs.use_group_transformation) {
65 ctx.error("group_renderer::enable() group_rotations not set");
66 res = false;
67 }
68 return res;
69 }
70
72 {
73 bool res = renderer::enable(ctx);
74 const group_render_style& grs = get_style<group_render_style>();
75 if (ref_prog().is_linked()) {
76 ref_prog().set_uniform(ctx, "use_group_color", grs.use_group_color);
77 ref_prog().set_uniform(ctx, "use_group_transformation", grs.use_group_transformation);
78 }
79 else
80 res = false;
81 return res;
82 }
84 {
85 bool res = renderer::disable(ctx);
86 if (!attributes_persist())
87 has_group_indices = false;
88 return res;
89 }
90
91 bool group_render_style_reflect::self_reflect(cgv::reflect::reflection_handler& rh)
92 {
93 return
94 rh.reflect_member("use_group_color", use_group_color) &&
95 rh.reflect_member("use_group_transformation", use_group_transformation);
96 }
97
99 {
101 }
102 }
103}
104
105//namespace cgv {
106// namespace reflect {
107// namespace render {
108// }
109// }
110//}
111
112#include <cgv/gui/provider.h>
113
114namespace cgv {
115 namespace gui {
116
118 {
120 bool create(provider* p, const std::string& label,
121 void* value_ptr, const std::string& value_type,
122 const std::string& gui_type, const std::string& options, bool*)
123 {
125 return false;
126 cgv::render::group_render_style* grs_ptr = reinterpret_cast<cgv::render::group_render_style*>(value_ptr);
127 cgv::base::base* b = dynamic_cast<cgv::base::base*>(p);
128
129 p->add_member_control(b, "Use Group Color", grs_ptr->use_group_color);
130 p->add_member_control(b, "Use Group Transformation", grs_ptr->use_group_transformation);
131 return true;
132 }
133 };
134
135#include "gl/lib_begin.h"
136
137CGV_API cgv::gui::gui_creator_registration<group_render_style_gui_creator> group_rs_gc_reg("group_render_style_gui_creator");
138
139 }
140}
base class for all classes that can be registered with support for dynamic properties (see also secti...
Definition base.h:75
helper template for registration of gui creators
Definition gui_creator.h:32
derive from this class to provide a gui to the current viewer
Definition provider.h:64
data::ref_ptr< control< T > > add_member_control(cgv::base::base *base_ptr, const std::string &label, T &value, const std::string &gui_type="", const std::string &options="", const std::string &align="\n")
add control with callback to cgv::base::on_set method on cgv::gui::control::value_change
Definition provider.h:137
the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base.
bool reflect_member(const std::string &member_name, T &member_ref, bool hard_cast=false)
call this to reflect a member by member name and reference to the member.
attribute array manager used to upload arrays to gpu
base class for all drawables, which is independent of the used rendering API.
Definition context.h:627
virtual void error(const std::string &message, const render_component *rc=0) const
error handling
Definition context.cxx:219
void set_group_index_array(const context &ctx, const std::vector< unsigned > &group_indices)
method to set the group index attribute
bool disable(context &ctx)
disable renderer
void enable_attribute_array_manager(const context &ctx, attribute_array_manager &aam)
call this before setting attribute arrays to manage attribute array in given manager
void remove_group_index_array(const context &ctx)
remove the group index attribute
bool validate_attributes(const context &ctx) const
check additionally the group attributes
void disable_attribute_array_manager(const context &ctx, attribute_array_manager &aam)
call this after last render/draw call to ensure that no other users of renderer change attribute arra...
bool enable(context &ctx)
overload to activate group style
bool has_attribute(const context &ctx, const std::string &name)
check for attribute
Definition renderer.h:62
virtual bool enable(context &ctx)
enables renderer
Definition renderer.cxx:198
shader_program & ref_prog()
derived renderer classes have access to shader program
Definition renderer.h:79
virtual void enable_attribute_array_manager(const context &ctx, attribute_array_manager &aam)
call this before setting attribute arrays to manage attribute array in given manager
Definition renderer.cxx:48
virtual void disable_attribute_array_manager(const context &ctx, attribute_array_manager &aam)
call this after last render/draw call to ensure that no other users of renderer change attribute arra...
Definition renderer.cxx:57
const render_style * get_style_ptr() const
access to render style
Definition renderer.cxx:152
virtual bool validate_attributes(const context &ctx) const
call to validate, whether essential position attribute is defined
Definition renderer.cxx:124
bool attributes_persist() const
return whether attributes persist after a call to disable
Definition renderer.h:70
virtual bool disable(context &ctx)
disable renderer
Definition renderer.cxx:224
bool set_uniform(const context &ctx, const std::string &name, const T &value, bool generate_error=false)
Set the value of a uniform by name, where the type can be any of int, unsigned, float,...
a vertex buffer is an unstructured memory block on the GPU.
the cgv namespace
Definition print.h:11
bool create(provider *p, const std::string &label, void *value_ptr, const std::string &value_type, const std::string &gui_type, const std::string &options, bool *)
attempt to create a gui and return whether this was successful
interface for gui creators
Definition gui_creator.h:14
this reflection traits implementation is used for external self_reflect implementations of instances ...
render style used for group information
bool use_group_transformation
whether to use group translation and rotation indexed through group index, defaults to false
bool use_group_color
whether to use group colors indexed through group index, defaults to false
compact type description of data that can be sent to the context; convertible to int
Definition context.h:56
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54