cgv
Loading...
Searching...
No Matches
spline_tube_renderer.cxx
1#include "spline_tube_renderer.h"
2#include <cgv_gl/gl/gl.h>
3#include <cgv_gl/gl/gl_tools.h>
4
5namespace cgv {
6 namespace render {
8 {
9 static int ref_count = 0;
10 static spline_tube_renderer r;
11 r.manage_singleton(ctx, "spline_tube_renderer", ref_count, ref_count_change);
12 return r;
13 }
14
19
25
33 {
35 if (has_attribute(ctx, "radius"))
36 has_radii = true;
37 if (has_attribute(ctx, "tangent"))
38 has_tangents = true;
39 }
48 has_radii = false;
49 remove_attribute_array(ctx, "radii");
50 }
52 has_tangents = false;
53 remove_attribute_array(ctx, "tangent");
54 }
56 {
57 const spline_tube_render_style& strs = get_style<spline_tube_render_style>();
59 return res;
60 }
62 {
63 return prog.build_program(ctx, "spline_tube.glpr", options, true);
64 }
66 {
67 const spline_tube_render_style& strs = get_style<spline_tube_render_style>();
68
70 return false;
71
72 if(!ref_prog().is_linked())
73 return false;
74
75 if(!has_radii)
76 ref_prog().set_attribute(ctx, "radius", strs.radius);
77
78 if(!has_tangents)
79 ref_prog().set_attribute(ctx, "tangent", vec4(0.0));
80
81 ref_prog().set_uniform(ctx, "radius_scale", strs.radius_scale);
82 ref_prog().set_uniform(ctx, "eye_pos", eye_pos);
83
84 return true;
85 }
88 {
89 if(!attributes_persist()) {
90 has_radii = false;
91 has_tangents = false;
92 }
93 return surface_renderer::disable(ctx);
94 }
95
96 bool spline_tube_render_style_reflect::self_reflect(cgv::reflect::reflection_handler& rh)
97 {
98 return
99 rh.reflect_base(*static_cast<spline_tube_render_style*>(this)) &&
100 rh.reflect_member("radius", radius) &&
101 rh.reflect_member("radius_scale", radius_scale);
102 }
103
104 void spline_tube_renderer::draw(context& ctx, size_t start, size_t count, bool use_strips, bool use_adjacency, uint32_t strip_restart_index)
105 {
106 draw_impl(ctx, PT_LINES, start, count, use_strips, use_adjacency, strip_restart_index);
107 }
108
110 {
112 }
113 }
114}
115
116#include <cgv/gui/provider.h>
117
118namespace cgv {
119 namespace gui {
120
123 bool create(provider* p, const std::string& label,
124 void* value_ptr, const std::string& value_type,
125 const std::string& gui_type, const std::string& options, bool*) {
127 return false;
129 cgv::base::base* b = dynamic_cast<cgv::base::base*>(p);
130
131 p->add_member_control(b, "default radius", strs_ptr->radius, "value_slider", "min=0.001;step=0.0001;max=10.0;log=true;ticks=true");
132 p->add_member_control(b, "radius scale", strs_ptr->radius_scale, "value_slider", "min=0.01;step=0.0001;max=100.0;log=true;ticks=true");
133
134 p->add_gui("surface_render_style", *static_cast<cgv::render::surface_render_style*>(strs_ptr));
135 return true;
136 }
137 };
138
139#include "gl/lib_begin.h"
140
141 CGV_API cgv::gui::gui_creator_registration<spline_tube_render_style_gui_creator> spline_tube_rs_gc_reg("spline_tube_render_style_gui_creator");
142 }
143}
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
base class for all drawables, which is independent of the used rendering API.
Definition context.h:626
bool validate_attributes(const context &ctx) const
check additionally the group attributes
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:23
bool has_attribute(const context &ctx, const std::string &name)
check for attribute
Definition renderer.h:60
shader_program & ref_prog()
derived renderer classes have access to shader program
Definition renderer.h:75
bool attributes_persist() const
return whether attributes persist after a call to disable
Definition renderer.h:66
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:257
a shader program combines several shader code fragments to a complete definition of the shading pipel...
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...
bool build_program(const context &ctx, const std::string &file_name, bool show_error=false)
successively calls create, attach_program and link.
renderer that supports point splatting
bool has_tangents
whether tangents are specified
void remove_radius_array(const context &ctx)
remove the radius attribute
void remove_tangent_array(const context &ctx)
remove the tangent attribute
void draw(context &ctx, size_t start, size_t count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1)
convenience function to render with default settings
bool enable(context &ctx)
overload to activate group style
bool has_radii
whether radii are specified
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 build_shader_program(context &ctx, shader_program &prog, const shader_compile_options &options)
build spline tube program
spline_tube_renderer()
initializes position_is_center to true
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
bool disable(context &ctx)
disable renderer
render_style * create_render_style() const
overload to allow instantiation of spline_tube_renderer
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...
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
bool disable(context &ctx)
disable renderer
bool enable(context &ctx)
overload to activate group style
spline_tube_renderer & ref_spline_tube_renderer(context &ctx, int ref_count_change)
reference to a singleton spline tube renderer that is shared among drawables
the cgv namespace
Definition print.h:11
cgv::math::fvec< float, 4 > vec4
declare type of 4d single precision floating point vectors (used for homogeneous coordinates)
Definition fvec.h:672
interface for gui creators
Definition gui_creator.h:14
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
this reflection traits implementation is used for external self_reflect implementations of instances ...
base class for all render styles
Definition renderer.h:16
holds options applied before and during shader compilation, such as preprocessor defines and code sni...
Definition shader_code.h:87
float radius
default tube radius, initialized to 1
spline_tube_render_style()
construct with default values
float radius_scale
multiplied to the tube radius, initialized to 1
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54