cgv
Loading...
Searching...
No Matches
box_wire_renderer.cxx
1#include "box_wire_renderer.h"
2#include <cgv_reflect_types/math/fvec.h>
3#include <cgv_gl/gl/gl.h>
4#include <cgv_gl/gl/gl_tools.h>
5
6namespace cgv {
7 namespace render {
8 box_wire_renderer& ref_box_wire_renderer(context& ctx, int ref_count_change)
9 {
10 static int ref_count = 0;
11 static box_wire_renderer r;
12 r.manage_singleton(ctx, "box_wire_renderer", ref_count, ref_count_change);
13 return r;
14 }
15
18 {
20 if (has_attribute(ctx, "extent"))
21 has_extents = true;
22 if (has_attribute(ctx, "translation"))
23 has_translations = true;
24 if (has_attribute(ctx, "rotation"))
25 has_rotations = true;
26 }
36 has_extents = false;
37 remove_attribute_array(ctx, "extent");
38 }
40 has_translations = false;
41 remove_attribute_array(ctx, "translation");
42 }
44 has_rotations = false;
45 remove_attribute_array(ctx, "rotation");
46 }
48 void box_wire_renderer::set_position_is_center(bool _position_is_center)
49 {
50 position_is_center = _position_is_center;
51 }
54 {
55 if (!line_renderer::enable(ctx))
56 return false;
57 ref_prog().set_uniform(ctx, "position_is_center", position_is_center);
58 ref_prog().set_uniform(ctx, "has_rotations", has_rotations);
59 ref_prog().set_uniform(ctx, "has_translations", has_translations);
60 const auto& brs = get_style<box_wire_render_style>();
61 ref_prog().set_uniform(ctx, "relative_anchor", brs.relative_anchor);
62 if (!has_extents)
63 ref_prog().set_attribute(ctx, "extent", brs.default_extent);
64 return true;
65 }
68 {
69 if (!attributes_persist()) {
70 has_extents = false;
71 position_is_center = true;
72 has_rotations = false;
73 has_translations = false;
74 }
75
76 return line_renderer::disable(ctx);
77 }
78
79 void box_wire_renderer::draw(context& ctx, size_t start, size_t count, bool use_strips, bool use_adjacency, uint32_t strip_restart_index)
80 {
81 draw_impl(ctx, PT_POINTS, start, count, false, false, -1);
82 }
83 bool box_wire_render_style_reflect::self_reflect(cgv::reflect::reflection_handler& rh)
84 {
85 return
86 rh.reflect_base(*static_cast<line_render_style*>(this)) &&
87 rh.reflect_member("default_extent", default_extent) &&
88 rh.reflect_member("relative_anchor", relative_anchor);
89 }
90
91
93 {
95 }
96 }
97}
98
99#include <cgv/gui/provider.h>
100
101namespace cgv {
102 namespace gui {
103
105 {
107 bool create(provider* p, const std::string& label,
108 void* value_ptr, const std::string& value_type,
109 const std::string& gui_type, const std::string& options, bool*)
110 {
112 return false;
113 cgv::render::box_wire_render_style* brs_ptr = reinterpret_cast<cgv::render::box_wire_render_style*>(value_ptr);
114 cgv::base::base* b = dynamic_cast<cgv::base::base*>(p);
115 p->add_member_control(b, "Default Eextent X", brs_ptr->default_extent[0], "value_slider", "min=0.001;max=1000;log=true;ticks=true");
116 p->add_member_control(b, "Default Eextent Y", brs_ptr->default_extent[1], "value_slider", "min=0.001;max=1000;log=true;ticks=true");
117 p->add_member_control(b, "Default Eextent Z", brs_ptr->default_extent[2], "value_slider", "min=0.001;max=1000;log=true;ticks=true");
118 p->add_member_control(b, "Relative Anchor X", brs_ptr->relative_anchor[0], "value_slider", "min=-1;max=1;ticks=true");
119 p->add_member_control(b, "Relative Anchor Y", brs_ptr->relative_anchor[1], "value_slider", "min=-1;max=1;ticks=true");
120 p->add_member_control(b, "Relative Anchor Z", brs_ptr->relative_anchor[2], "value_slider", "min=-1;max=1;ticks=true");
121 p->add_gui("line_render_style", *static_cast<cgv::render::line_render_style*>(brs_ptr));
122 return true;
123 }
124 };
125
126#include "gl/lib_begin.h"
127
128 CGV_API cgv::gui::gui_creator_registration<box_wire_render_style_gui_creator> box_wire_rs_gc_reg("box_wire_render_style_gui_creator");
129 }
130}
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 remove_rotation_array(const context &ctx)
remove the rotation attribute
void set_position_is_center(bool _position_is_center)
set the flag, whether the position is interpreted as the box center
bool enable(context &ctx) override
enable box wire renderer
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 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.
bool has_translations
whether array with per box translations has been specified
bool has_rotations
whether array with per box rotations has been specified
void remove_extent_array(const context &ctx)
remove the extent attribute
bool position_is_center
whether position is box center, if not it is lower left bottom corner
void remove_translation_array(const context &ctx)
remove the translation attribute
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 disable(context &ctx) override
disable renderer
base class for all drawables, which is independent of the used rendering API.
Definition context.h:627
bool enable(context &ctx) override
overload to activate group style
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...
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 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
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...
box_wire_renderer & ref_box_wire_renderer(context &ctx, int ref_count_change)
reference to a singleton box_wire renderer that can be 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 ...
box wires extend line 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,...
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54