cgv
sphere_renderer.h
1 #pragma once
2 
3 #include "surface_renderer.h"
4 
5 #include "gl/lib_begin.h"
6 
7 namespace cgv { // @<
8  namespace render { // @<
9  class CGV_API sphere_renderer;
10 
12 
15  extern CGV_API sphere_renderer& ref_sphere_renderer(context& ctx, int ref_count_change = 0);
16 
18  struct CGV_API sphere_render_style : public surface_render_style
19  {
20  /*@name sphere rendering attributes*/
22  float radius_scale;
25  float radius;
39 
42  };
43 
45  class CGV_API sphere_renderer : public surface_renderer
46  {
47  protected:
48  bool has_radii;
49  bool has_group_radii;
50  float y_view_angle;
52  render_style* create_render_style() const;
53  public:
57  void enable_attribute_array_manager(const context& ctx, attribute_array_manager& aam);
59  void disable_attribute_array_manager(const context& ctx, attribute_array_manager& aam);
61  bool init(context& ctx);
63  void set_y_view_angle(float y_view_angle);
65  template <typename T = float>
66  void set_radius_array(const context& ctx, const std::vector<T>& radii) { has_radii = true; set_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "radius"), radii); }
68  template <typename T = float>
69  void set_radius_array(const context& ctx, const T* radii, size_t nr_elements, unsigned stride_in_bytes = 0) { has_radii = true; set_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "radius"), radii, nr_elements, stride_in_bytes); }
71  template <typename T = float>
72  void set_group_radii(const context& ctx, const std::vector<T>& group_radii) { has_group_radii = true; ref_prog().set_uniform_array(ctx, "group_radii", group_radii); }
74  template <typename T = float>
75  void set_sphere_array(const context& ctx, const std::vector<cgv::math::fvec<T, 4> >& spheres) {
76  set_composed_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "position"),
77  &spheres.front(), spheres.size(), reinterpret_cast<const cgv::math::fvec<T, 3>&>(spheres.front()));
78  ref_composed_attribute_array(ctx, ref_prog().get_attribute_location(ctx, "radius"),
79  ref_prog().get_attribute_location(ctx, "position"), &spheres.front(), spheres.size(), spheres[0][3]);
80  has_positions = true;
81  has_radii = true;
82  }
84  bool validate_attributes(const context& ctx) const;
86  bool enable(context& ctx);
88  bool disable(context& ctx);
90  void draw(context& ctx, size_t start, size_t count,
91  bool use_strips = false, bool use_adjacency = false, uint32_t strip_restart_index = -1);
92  };
93 
94  struct CGV_API sphere_render_style_reflect : public sphere_render_style
95  {
96  bool self_reflect(cgv::reflect::reflection_handler& rh);
97  };
98  extern CGV_API cgv::reflect::extern_reflection_traits<sphere_render_style, sphere_render_style_reflect> get_reflection_traits(const sphere_render_style&);
99  }
100 }
101 
102 
103 #include <cgv/config/lib_end.h>
cgv::render::render_style
base class for all render styles
Definition: renderer.h:16
cgv::render::sphere_render_style::blend_width_in_pixel
float blend_width_in_pixel
set to 1 in constructor
Definition: sphere_renderer.h:29
cgv::render::ref_sphere_renderer
sphere_renderer & ref_sphere_renderer(context &ctx, int ref_count_change)
reference to a singleton sphere renderer that can be shared among drawables
Definition: sphere_renderer.cxx:7
cgv::render::sphere_render_style
Definition: sphere_renderer.h:19
cgv::math::fvec< T, 4 >
cgv::render::surface_render_style
Definition: surface_renderer.h:26
cgv::render::sphere_render_style::halo_color_strength
float halo_color_strength
strength in [0,1] of halo color with respect to color of primitive
Definition: sphere_renderer.h:37
cgv::render::attribute_array_manager
attribute array manager used to upload arrays to gpu
Definition: renderer.h:21
cgv::render::sphere_render_style::radius
float radius
default value assigned to radius attribute in enable method of sphere renderer, set to 1 in construct...
Definition: sphere_renderer.h:25
cgv::media::color< float, cgv::media::RGB, cgv::media::OPACITY >
cgv::reflect::reflection_handler
Definition: reflection_handler.h:63
cgv::render::sphere_render_style::use_group_radius
bool use_group_radius
whether to use the group radius
Definition: sphere_renderer.h:27
cgv::render::surface_renderer
base classes for renderers that support surface rendering
Definition: surface_renderer.h:43
cgv::render::sphere_render_style::percentual_halo_width
float percentual_halo_width
set to 0 in constructor
Definition: sphere_renderer.h:33
cgv::reflect::extern_reflection_traits
this reflection traits implementation is used for external self_reflect implementations of instances ...
Definition: reflect_extern.h:28
cgv::render::sphere_render_style::halo_color
cgv::media::color< float, cgv::media::RGB, cgv::media::OPACITY > halo_color
color of halo with opacity channel
Definition: sphere_renderer.h:35
cgv::render::sphere_renderer::set_sphere_array
void set_sphere_array(const context &ctx, const std::vector< cgv::math::fvec< T, 4 > > &spheres)
use this function if you store spheres in vec4 with the 4th component the radius
Definition: sphere_renderer.h:75
cgv::render::sphere_renderer
renderer that supports splatting of spheres
Definition: sphere_renderer.h:46
cgv::render::sphere_render_style::halo_width_in_pixel
float halo_width_in_pixel
set to 0 in constructor
Definition: sphere_renderer.h:31
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::render::context
Definition: context.h:525