cgv
Loading...
Searching...
No Matches
normal_renderer.cxx
1#include "normal_renderer.h"
2#include <cgv_gl/gl/gl.h>
3#include <cgv_gl/gl/gl_tools.h>
4
5namespace cgv {
6 namespace render {
7 normal_renderer& ref_normal_renderer(context& ctx, int ref_count_change)
8 {
9 static int ref_count = 0;
10 static normal_renderer r;
11 r.manage_singleton(ctx, "normal_renderer", ref_count, ref_count_change);
12 return r;
13 }
14
15 normal_render_style::normal_render_style()
16 {
17 normal_length = 1.0f;
18 }
19
20 normal_renderer::normal_renderer()
21 {
22 normal_scale = 1.0f;
23 }
25 void normal_renderer::set_normal_scale(float _normal_scale)
26 {
27 normal_scale = _normal_scale;
28 }
29
35 {
36 // validate set attributes
38 if (!has_normals) {
39 ctx.error("normal_renderer::enable() normal attribute not set");
40 res = false;
41 }
42 return res;
43 }
45 {
46 return prog.build_program(ctx, "normal.glpr", true, defines);
47 }
48
50 {
51 const normal_render_style& nrs = get_style<normal_render_style>();
52 if (!line_renderer::enable(ctx))
53 return false;
54 ref_prog().set_uniform(ctx, "normal_length", nrs.normal_length * normal_scale);
55 return true;
56 }
57
58 void normal_renderer::draw(context& ctx, size_t start, size_t count, bool use_strips, bool use_adjacency, uint32_t strip_restart_index)
59 {
60 draw_impl(ctx, PT_POINTS, start, count, false, false, -1);
61 }
62
63 bool normal_render_style_reflect::self_reflect(cgv::reflect::reflection_handler& rh)
64 {
65 return
66 rh.reflect_base(*static_cast<line_render_style*>(this)) &&
67 rh.reflect_member("normal_length", normal_length);
68 }
69
71 {
73 }
74 }
75}
76
77#include <cgv/gui/provider.h>
78
79namespace cgv {
80 namespace gui {
81
83 {
85 bool create(provider* p, const std::string& label,
86 void* value_ptr, const std::string& value_type,
87 const std::string& gui_type, const std::string& options, bool*)
88 {
90 return false;
91 cgv::render::normal_render_style* nrs_ptr = reinterpret_cast<cgv::render::normal_render_style*>(value_ptr);
92 cgv::base::base* b = dynamic_cast<cgv::base::base*>(p);
93 p->add_member_control(b, "Normal Length", nrs_ptr->normal_length, "value_slider", "min=0.0001;step=0.0000001;max=10;log=true;ticks=true");
94 p->add_gui("line render style", *static_cast<cgv::render::line_render_style*>(nrs_ptr));
95 return true;
96 }
97 };
98
99#include "gl/lib_begin.h"
100
101CGV_API cgv::gui::gui_creator_registration<normal_render_style_gui_creator> normal_rs_gc_reg("normal_render_style_gui_creator");
102
103 }
104}
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.
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
bool validate_attributes(const context &ctx) const
check additionally the group attributes
bool enable(context &ctx)
overload to activate group style
renderer that supports rendering point normals
void set_normal_scale(float _normal_scale)
the normal scale is multiplied to the normal length of the normal render style
bool enable(context &ctx)
enable normal renderer
float normal_scale
scaling of normal length
bool validate_attributes(const context &ctx) const
check additionally the group attributes
render_style * create_render_style() const
overload to allow instantiation of box_wire_renderer
bool build_shader_program(context &ctx, shader_program &prog, const shader_define_map &defines)
build normal program
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
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
shader_program & ref_prog()
derived renderer classes have access to shader program
Definition renderer.h:75
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:253
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 build_program(const context &ctx, const std::string &file_name, bool show_error=false, const shader_define_map &defines=shader_define_map())
successively calls create, attach_program and link.
std::map< std::string, std::string > shader_define_map
typedef for shader define map data structure
Definition shader_code.h:52
normal_renderer & ref_normal_renderer(context &ctx, int ref_count_change)
reference to a singleton normal renderer that can be shared among drawables
the cgv namespace
Definition print.h:11
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
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54