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
8
14
15 group_renderer::group_renderer()
16 {
17 has_group_indices = false;
18 has_group_colors = false;
19 has_group_translations = false;
20 has_group_rotations = false;
21 }
24 {
26 if (has_attribute(ctx, "group_index"))
27 has_group_indices = true;
28 }
31 {
33 has_group_indices = false;
34 }
35
36 void group_renderer::set_group_index_array(const context& ctx, const std::vector<unsigned>& group_indices)
37 {
38 has_group_indices = true;
39 set_attribute_array(ctx, "group_index", group_indices);
40 }
42 void group_renderer::set_group_index_array(const context& ctx, const unsigned* group_indices, size_t nr_elements)
43 {
44 has_group_indices = true;
45 set_attribute_array(ctx, "group_index", group_indices, nr_elements, 0);
46 }
48 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)
49 {
50 has_group_indices = true;
51 set_attribute_array(ctx, "group_index", element_type, vbo, offset_in_bytes, nr_elements, stride_in_bytes);
52 }
54 has_group_indices = false;
55 remove_attribute_array(ctx, "group_index");
56 }
58 {
59 // validate set attributes
60 bool res = renderer::validate_attributes(ctx);
61 if (!res)
62 return false;
63 if (!get_style_ptr())
64 return false;
65 const group_render_style& grs = get_style<group_render_style>();
66 if (!has_group_indices && (grs.use_group_color || grs.use_group_transformation)) {
67 ctx.error("group_renderer::enable() group_index attribute not set while using group colors or group transformations");
68 res = false;
69 }
70 if (!has_group_colors && grs.use_group_color) {
71 ctx.error("group_renderer::enable() group_colors not set");
72 res = false;
73 }
74 if (!has_group_translations && grs.use_group_transformation) {
75 ctx.error("group_renderer::enable() group_translations not set");
76 res = false;
77 }
78 if (!has_group_rotations && grs.use_group_transformation) {
79 ctx.error("group_renderer::enable() group_rotations not set");
80 res = false;
81 }
82 return res;
83 }
84
86 {
87 bool res = renderer::enable(ctx);
88 const group_render_style& grs = get_style<group_render_style>();
89 if (ref_prog().is_linked()) {
90 ref_prog().set_uniform(ctx, "use_group_color", grs.use_group_color);
91 ref_prog().set_uniform(ctx, "use_group_transformation", grs.use_group_transformation);
92 }
93 else
94 res = false;
95 return res;
96 }
98 {
99 bool res = renderer::disable(ctx);
100 if (!attributes_persist())
101 has_group_indices = false;
102 return res;
103 }
104
105 bool group_render_style_reflect::self_reflect(cgv::reflect::reflection_handler& rh)
106 {
107 return
108 rh.reflect_member("use_group_color", use_group_color) &&
109 rh.reflect_member("use_group_transformation", use_group_transformation);
110 }
111
113 {
115 }
116 }
117}
118
119//namespace cgv {
120// namespace reflect {
121// namespace render {
122// }
123// }
124//}
125
126#include <cgv/gui/provider.h>
127
128namespace cgv {
129 namespace gui {
130
132 {
134 bool create(provider* p, const std::string& label,
135 void* value_ptr, const std::string& value_type,
136 const std::string& gui_type, const std::string& options, bool*)
137 {
139 return false;
140 cgv::render::group_render_style* grs_ptr = reinterpret_cast<cgv::render::group_render_style*>(value_ptr);
141 cgv::base::base* b = dynamic_cast<cgv::base::base*>(p);
142
143 p->add_member_control(b, "Use Group Color", grs_ptr->use_group_color);
144 p->add_member_control(b, "Use Group Transformation", grs_ptr->use_group_transformation);
145 return true;
146 }
147 };
148
149#include "gl/lib_begin.h"
150
151CGV_API cgv::gui::gui_creator_registration<group_render_style_gui_creator> group_rs_gc_reg("group_render_style_gui_creator");
152
153 }
154}
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:621
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:60
virtual bool enable(context &ctx)
enables renderer
Definition renderer.cxx:203
shader_program & ref_prog()
derived renderer classes have access to shader program
Definition renderer.h:75
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:54
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:63
const render_style * get_style_ptr() const
access to render style
Definition renderer.cxx:158
virtual bool validate_attributes(const context &ctx) const
call to validate, whether essential position attribute is defined
Definition renderer.cxx:130
bool attributes_persist() const
return whether attributes persist after a call to disable
Definition renderer.h:66
virtual bool disable(context &ctx)
disable renderer
Definition renderer.cxx:229
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
group_render_style()
set default values
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:47
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54