cgv
Loading...
Searching...
No Matches
box_renderer.cxx
1#include "box_renderer.h"
2#include <cgv_gl/gl/gl.h>
3#include <cgv_gl/gl/gl_tools.h>
4
5namespace cgv {
6 namespace render {
7 box_renderer& ref_box_renderer(context& ctx, int ref_count_change)
8 {
9 static int ref_count = 0;
10 static box_renderer r;
11 r.manage_singleton(ctx, "box_renderer", ref_count, ref_count_change);
12 return r;
13 }
14
17 {
19 if (has_attribute(ctx, "extent"))
20 has_extents = true;
21 if (has_attribute(ctx, "secondary_color"))
23 if (has_attribute(ctx, "radius"))
24 has_radii = true;
25 if (has_attribute(ctx, "translation"))
26 has_translations = true;
27 if (has_attribute(ctx, "rotation"))
28 has_rotations = true;
29 }
41 has_extents = false;
42 remove_attribute_array(ctx, "extent");
43 }
45 has_radii = false;
46 remove_attribute_array(ctx, "radius");
47 }
50 remove_attribute_array(ctx, "secondary_color");
51 }
53 has_translations = false;
54 remove_attribute_array(ctx, "translation");
55 }
57 has_rotations = false;
58 remove_attribute_array(ctx, "rotation");
59 }
61 void box_renderer::set_position_is_center(bool _position_is_center)
62 {
63 position_is_center = _position_is_center;
64 }
67 {
69 return false;
70 ref_prog().set_uniform(ctx, "position_is_center", position_is_center);
71 ref_prog().set_uniform(ctx, "has_rotations", has_rotations);
72 ref_prog().set_uniform(ctx, "has_translations", has_translations);
73 ref_prog().set_uniform(ctx, "has_radii", has_radii);
74 ref_prog().set_uniform(ctx, "has_secondary_colors", has_secondary_colors);
75 const auto& brs = get_style<box_render_style>();
76 if (ref_prog().get_uniform_location(ctx, "default_radius") != -1)
77 ref_prog().set_uniform(ctx, "default_radius", brs.default_radius);
78 if (ref_prog().get_uniform_location(ctx, "relative_anchor") != -1)
79 ref_prog().set_uniform(ctx, "relative_anchor", brs.relative_anchor);
80 if (!has_extents)
81 ref_prog().set_attribute(ctx, "extent", brs.default_extent);
82 return true;
83 }
86 {
87 if (!attributes_persist()) {
88 has_extents = false;
89 has_radii = false;
90 position_is_center = true;
91 has_rotations = false;
92 has_translations = false;
93 }
94
95 return surface_renderer::disable(ctx);
96 }
97
98 void box_renderer::draw(context& ctx, size_t start, size_t count, bool use_strips, bool use_adjacency, uint32_t strip_restart_index)
99 {
100 draw_impl(ctx, PT_POINTS, start, count, false, false, -1);
101 }
102
103 bool box_render_style_reflect::self_reflect(cgv::reflect::reflection_handler& rh)
104 {
105 return
106 rh.reflect_base(*static_cast<surface_render_style*>(this)) &&
107 rh.reflect_member("default_extent", default_extent) &&
108 rh.reflect_member("default_radius", default_radius) &&
109 rh.reflect_member("relative_anchor", relative_anchor);
110 }
111
113 {
114 const box_render_style& brs = get_style<box_render_style>();
115 options.define_macro_if_true(brs.rounding, "ENABLE_ROUNDING");
116 }
118 {
120 }
121 }
122}
123
124#include <cgv/gui/provider.h>
125
126namespace cgv {
127 namespace gui {
128
130 {
132 bool create(provider* p, const std::string& label,
133 void* value_ptr, const std::string& value_type,
134 const std::string& gui_type, const std::string& options, bool*)
135 {
137 return false;
138 cgv::render::box_render_style* brs_ptr = reinterpret_cast<cgv::render::box_render_style*>(value_ptr);
139 cgv::base::base* b = dynamic_cast<cgv::base::base*>(p);
140 p->add_member_control(b, "Default Extent X", brs_ptr->default_extent[0], "value_slider", "min=0.001;max=1000;log=true;ticks=true");
141 p->add_member_control(b, "Default Extent Y", brs_ptr->default_extent[1], "value_slider", "min=0.001;max=1000;log=true;ticks=true");
142 p->add_member_control(b, "Default Extent Z", brs_ptr->default_extent[2], "value_slider", "min=0.001;max=1000;log=true;ticks=true");
143 p->add_member_control(b, "Relative Anchor X", brs_ptr->relative_anchor[0], "value_slider", "min=-1;max=1;ticks=true");
144 p->add_member_control(b, "Relative Anchor Y", brs_ptr->relative_anchor[1], "value_slider", "min=-1;max=1;ticks=true");
145 p->add_member_control(b, "Relative Anchor Z", brs_ptr->relative_anchor[2], "value_slider", "min=-1;max=1;ticks=true");
146 p->add_member_control(b, "Rounding", brs_ptr->rounding, "toggle");
147 p->add_member_control(b, "Default Radius", brs_ptr->default_radius, "value_slider", "min=0.0;max=10;step=0.0001;log=true;ticks=true");
148 p->add_gui("surface_render_style", *static_cast<cgv::render::surface_render_style*>(brs_ptr));
149 return true;
150 }
151 };
152
153#include "gl/lib_begin.h"
154
155 CGV_API cgv::gui::gui_creator_registration<box_render_style_gui_creator> box_rs_gc_reg("box_render_style_gui_creator");
156 }
157}
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
bool add_gui(const std::string &label, T &value, const std::string &gui_type="", const std::string &options="")
Add a composed gui of the given gui_type for the given value.
Definition provider.h:247
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_base(B &base_ref)
reflect a base class with its members
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
renderer that supports point splatting
void update_shader_program_options(shader_compile_options &options) const override
update shader program compile options based on render style
bool has_translations
whether array with per box translations has been specified
void remove_translation_array(const context &ctx)
remove the translation attribute
bool disable(context &ctx) override
disable renderer
void disable_attribute_array_manager(const context &ctx, attribute_array_manager &aam) override
call this after last render/draw call to ensure that no other users of renderer change attribute arra...
bool has_rotations
whether array with per box rotations has been specified
void draw(context &ctx, size_t start, size_t count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1) override
Draw a range of vertices or indexed elements.
void remove_extent_array(const context &ctx)
remove the extent attribute
void remove_secondary_color_array(const context &ctx)
remove the secondary color attribute
bool has_radii
store whether extent array has been specified
void enable_attribute_array_manager(const context &ctx, attribute_array_manager &aam) override
call this before setting attribute arrays to manage attribute array in given manager
bool has_secondary_colors
whether secondary color or color array was set
bool enable(context &ctx) override
enable box renderer
bool position_is_center
whether position is box center, if not it is lower left bottom corner
void set_position_is_center(bool _position_is_center)
set the flag, whether the position is interpreted as the box center, true by default
void remove_rotation_array(const context &ctx)
remove the rotation attribute
void remove_radius_array(const context &ctx)
remove the radius attribute
bool has_extents
store whether extent array has been specified
base class for all drawables, which is independent of the used rendering API.
Definition context.h:627
void manage_singleton(context &ctx, const std::string &renderer_name, int &ref_count, int ref_count_change)
used by derived classes to manage singletons
Definition renderer.cxx:10
bool has_attribute(const context &ctx, const std::string &name)
check for attribute
Definition renderer.h:62
shader_program & ref_prog()
derived renderer classes have access to shader program
Definition renderer.h:79
bool attributes_persist() const
return whether attributes persist after a call to disable
Definition renderer.h:70
void draw_impl(context &ctx, PrimitiveType pt, size_t start, size_t count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1)
default implementation of draw method with support for indexed rendering and different primitive type...
Definition renderer.cxx:248
Stores preprocessor options used for conditionally compiling shader programs.
Definition shader_code.h:73
void define_macro_if_true(bool predicate, const std::string &identifier)
Conditionally define identifier as a macro with replacement text 1.
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,...
bool set_attribute(const context &ctx, const std::string &name, const T &value)
set constant default value of a vertex attribute by attribute name, if name does not specify an attri...
void enable_attribute_array_manager(const context &ctx, attribute_array_manager &aam) override
call this before setting attribute arrays to manage attribute array in given manager
void disable_attribute_array_manager(const context &ctx, attribute_array_manager &aam) override
call this after last render/draw call to ensure that no other users of renderer change attribute arra...
bool enable(context &ctx) override
overload to activate group style
bool disable(context &ctx) override
disable renderer
box_renderer & ref_box_renderer(context &ctx, int ref_count_change)
reference to a singleton box renderer that is shared among drawables
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 ...
boxes use surface render styles
vec3 default_extent
extent used in case extent array is not specified; defaults to (1,1,1)
vec3 relative_anchor
box anchor position relative to center that corresponds to the position attribute; defaults to (0,...
bool rounding
whether to use rounding of edges and corners (enabling re-compiles shader program)
float default_radius
radius used in case radius array is not specified
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54