cgv
Loading...
Searching...
No Matches
point_renderer.cxx
1#include "point_renderer.h"
2#include <cgv_reflect_types/media/color.h>
3#include <cgv_gl/gl/gl.h>
4#include <cgv_gl/gl/gl_tools.h>
5
6namespace cgv {
7 namespace render {
8 point_renderer& ref_point_renderer(context& ctx, int ref_count_change)
9 {
10 static int ref_count = 0;
11 static point_renderer r;
12 r.manage_singleton(ctx, "point_renderer", ref_count, ref_count_change);
13 return r;
14 }
15
20
21 point_render_style::point_render_style() : halo_color(1, 1, 1, 1)
22 {
23 point_size = 1.0f;
26 screen_aligned = true;
27
28 blend_points = true;
34 }
35
36 point_renderer::point_renderer()
37 {
38 has_point_sizes = false;
39 has_group_point_sizes = false;
40 has_indexed_colors = false;
41 has_depth_offsets = false;
43 reference_point_size = 0.01f;
44 y_view_angle = 45;
45 }
48 {
50 if (has_attribute(ctx, "point_size"))
51 has_point_sizes = true;
52 if (has_attribute(ctx, "color_index"))
53 has_indexed_colors = true;
54 if (has_attribute(ctx, "depth_offset"))
55 has_depth_offsets = true;
56 }
59 {
61 has_point_sizes = false;
62 has_indexed_colors = false;
63 has_depth_offsets = false;
64 }
66 has_point_sizes = false;
67 remove_attribute_array(ctx, "point_size");
68 }
70 has_depth_offsets = false;
71 remove_attribute_array(ctx, "depth_offset");
72 }
74 has_indexed_colors = false;
75 remove_attribute_array(ctx, "indexed_color");
76 }
78 void point_renderer::set_reference_point_size(float _reference_point_size)
79 {
80 reference_point_size = _reference_point_size;
81 }
83 void point_renderer::set_y_view_angle(float _y_view_angle)
84 {
85 y_view_angle = _y_view_angle;
86 }
88 {
89 return prog.build_program(ctx, "point.glpr", true, defines);
90 }
92 {
93 const point_render_style& prs = get_style<point_render_style>();
94 bool res;
95 if (!prs.use_group_color) {
96 if (has_indexed_colors) {
97 if (has_colors)
98 ctx.error("point_renderer::validate_attributes() both point color and color index attributes set, using color index");
99 bool tmp = has_colors;
100 has_colors = true;
102 has_colors = tmp;
103 }
104 else
106 }
107 else
109 if (!has_group_point_sizes && prs.use_group_point_size) {
110 ctx.error("point_renderer::validate_attributes() group_point_sizes not set");
111 res = false;
112 }
113 return res;
114 }
116 {
117 const point_render_style& prs = get_style<point_render_style>();
118
119 bool res;
120 if (!prs.use_group_color && has_indexed_colors) {
121 bool tmp = has_colors;
122 has_colors = true;
123 res = group_renderer::enable(ctx);
124 has_colors = tmp;
125 }
126 else
127 res = group_renderer::enable(ctx);
128
129 glPointSize(prs.point_size);
130 if (prs.blend_points) {
131 glEnable(GL_BLEND);
132 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
133 }
134 if (ref_prog().is_linked()) {
135 if (!has_point_sizes)
136 ref_prog().set_attribute(ctx, "point_size", prs.point_size);
137 if (!has_depth_offsets)
138 ref_prog().set_attribute(ctx, "depth_offset", prs.default_depth_offset);
139 ref_prog().set_uniform(ctx, "use_color_index", has_indexed_colors);
140 ref_prog().set_uniform(ctx, "measure_point_size_in_pixel", prs.measure_point_size_in_pixel);
141 ref_prog().set_uniform(ctx, "screen_aligned", prs.screen_aligned);
142 ref_prog().set_uniform(ctx, "reference_point_size", reference_point_size);
143 ref_prog().set_uniform(ctx, "use_group_point_size", prs.use_group_point_size);
144 ref_prog().set_uniform(ctx, "viewport_height", (float)ctx.get_height());
145 ref_prog().set_uniform(ctx, "blend_width_in_pixel", prs.blend_width_in_pixel);
146 ref_prog().set_uniform(ctx, "percentual_halo_width", 0.01f*prs.percentual_halo_width);
147 ref_prog().set_uniform(ctx, "halo_width_in_pixel", prs.halo_width_in_pixel);
148 ref_prog().set_uniform(ctx, "halo_color", prs.halo_color);
149 ref_prog().set_uniform(ctx, "halo_color_strength", prs.halo_color_strength);
150 }
151 return res;
152 }
153
155 {
156 const point_render_style& prs = get_style<point_render_style>();
157 if (prs.blend_points) {
158 glDisable(GL_BLEND);
159 }
160 if (!attributes_persist()) {
161 has_indexed_colors = false;
162 has_point_sizes = false;
163 has_depth_offsets = false;
164 }
165 return group_renderer::disable(ctx);
166 }
167
168 void point_renderer::draw(context& ctx, size_t start, size_t count, bool use_strips, bool use_adjacency, uint32_t strip_restart_index)
169 {
170 draw_impl(ctx, PT_POINTS, start, count, false, false, -1);
171 }
172
173 bool point_render_style_reflect::self_reflect(cgv::reflect::reflection_handler& rh)
174 {
175 return
176 rh.reflect_base(*static_cast<group_render_style*>(this)) &&
177 rh.reflect_member("point_size", point_size) &&
178 rh.reflect_member("use_group_point_size", use_group_point_size) &&
179 rh.reflect_member("measure_point_size_in_pixel", measure_point_size_in_pixel) &&
180 rh.reflect_member("screen_aligned", screen_aligned) &&
181 rh.reflect_member("default_depth_offset", default_depth_offset) &&
182 rh.reflect_member("blend_points", blend_points) &&
183 rh.reflect_member("blend_width_in_pixel", blend_width_in_pixel) &&
184 rh.reflect_member("halo_width_in_pixel", halo_width_in_pixel) &&
185 rh.reflect_member("halo_color", halo_color) &&
186 rh.reflect_member("halo_color_strength", halo_color_strength) &&
187 rh.reflect_member("percentual_halo_width", percentual_halo_width);
188 }
190 {
192 }
193 }
194}
195
196#include <cgv/gui/provider.h>
197
198namespace cgv {
199 namespace gui {
200
202 {
204 bool create(provider* p, const std::string& label,
205 void* value_ptr, const std::string& value_type,
206 const std::string& gui_type, const std::string& options, bool*)
207 {
209 return false;
210 cgv::render::point_render_style* prs_ptr = reinterpret_cast<cgv::render::point_render_style*>(value_ptr);
211 cgv::base::base* b = dynamic_cast<cgv::base::base*>(p);
212
213 p->add_member_control(b, "Screen Aligned", prs_ptr->screen_aligned, "toggle");
214 p->add_member_control(b, "Point Size", prs_ptr->point_size, "value_slider", "label='';w=130;min=0.01;max=50;log=true;ticks=true", "");
215 p->add_member_control(b, "px", prs_ptr->measure_point_size_in_pixel, "toggle", "w=16", "");
216 p->add_member_control(b, "Blend", prs_ptr->blend_points, "toggle", "w=50");
217 p->add_member_control(b, "Default Depth Offset", prs_ptr->default_depth_offset, "value_slider", "min=0.000001;max=0.1;step=0.0000001;log=true;ticks=true");
218 bool show = p->begin_tree_node("Halo", prs_ptr->halo_color, false, "options='w=120';level=3;align=''");
219 p->add_member_control(b, "Color", prs_ptr->halo_color, "", "w=50");
220 if (show) {
221 p->align("\a");
222 p->add_member_control(b, "Halo Color Strength", prs_ptr->halo_color_strength, "value_slider", "min=0;max=1;ticks=true");
223 p->add_member_control(b, "Halo Width in Pixel", prs_ptr->halo_width_in_pixel, "value_slider", "min=-10;max=10;ticks=true");
224 p->add_member_control(b, "Percentual Halo Width", prs_ptr->percentual_halo_width, "value_slider", "min=-100;max=100;ticks=true");
225 p->add_member_control(b, "Blend Width in Pixel", prs_ptr->blend_width_in_pixel, "value_slider", "min=0;max=3;ticks=true");
226 p->align("\b");
227 p->end_tree_node(prs_ptr->halo_color);
228 }
229 if (p->begin_tree_node("Use of Group Information", prs_ptr->use_group_color, false, "level=3")) {
230 p->align("\a");
231 p->add_gui("group_render_style", *static_cast<cgv::render::group_render_style*>(prs_ptr));
232 p->align("\b");
233 p->end_tree_node(prs_ptr->use_group_color);
234 }
235 return true;
236 }
237 };
238
239#include "gl/lib_begin.h"
240
241CGV_API cgv::gui::gui_creator_registration<point_render_style_gui_creator> point_rs_gc_reg("point_render_style_gui_creator");
242
243 }
244}
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
void align(const std::string &_align)
send pure alignment information
Definition provider.cxx:36
bool begin_tree_node(const std::string &label, const T &value, bool initial_visibility=false, const std::string &options="", gui_group_ptr ggp=gui_group_ptr())
Begin a sub tree of a tree structured gui.
Definition provider.h:212
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
void end_tree_node(const T &value)
template specialization that allows to specify value reference plus node_instance by using the result...
Definition provider.h:222
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:621
virtual void error(const std::string &message, const render_component *rc=0) const
error handling
Definition context.cxx:219
virtual unsigned int get_height() const =0
return the height of the window
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
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
renderer that supports point splatting
bool build_shader_program(context &ctx, shader_program &prog, const shader_define_map &defines)
build point program
void remove_indexed_color_array(const context &ctx)
remove the indexed color 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
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 remove_depth_offset_array(const context &ctx)
remove the depth offset attribute
bool validate_attributes(const context &ctx) const
check additionally the group attributes
bool disable(context &ctx)
disable renderer
render_style * create_render_style() const
overload to allow instantiation of point_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
bool enable(context &ctx)
overload to activate group style
void remove_point_size_array(const context &ctx)
remove the point size attribute
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 has_colors
track whether color attribute is defined
Definition renderer.h:83
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: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 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, 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
point_renderer & ref_point_renderer(context &ctx, int ref_count_change)
reference to a singleton point 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 ...
render style used for group information
bool use_group_color
whether to use group colors indexed through group index, defaults to false
float blend_width_in_pixel
set to 1 in constructor
rgba halo_color
color of halo with opacity channel
bool use_group_point_size
whether to use the
float default_depth_offset
default value for depth offset used to support layering
float halo_width_in_pixel
set to 0 in constructor
bool measure_point_size_in_pixel
whether to measure point size in pixels or in world space relative to reference_pixel_size passed to ...
float halo_color_strength
strength in [0,1] of halo color with respect to color of primitive
bool screen_aligned
whether to span point splat in screen aligned coordinate system
float percentual_halo_width
set to 0 in constructor
bool blend_points
set to true in constructor
float point_size
default value assigned to point size attribute in enable method of point renderer,...
point_render_style()
construct with default values
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