cgv
Loading...
Searching...
No Matches
sphere_renderer.h
1#pragma once
2
3#include "surface_renderer.h"
4
5#include "gl/lib_begin.h"
6
7namespace 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
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;
54 bool build_shader_program(context& ctx, shader_program& prog, const shader_define_map& defines);
55 public:
59 void enable_attribute_array_manager(const context& ctx, attribute_array_manager& aam);
61 void disable_attribute_array_manager(const context& ctx, attribute_array_manager& aam);
63 void set_y_view_angle(float y_view_angle);
65 template <typename T = float>
66 void set_radius(const context& ctx, const T& radius) { has_radii = true; ref_prog().set_attribute(ctx, ref_prog().get_attribute_location(ctx, "radius"), radius); }
68 template <typename T = float>
69 void set_radius_array(const context& ctx, const std::vector<T>& radii) { has_radii = true; set_attribute_array(ctx, "radius", radii); }
71 template <typename T = float>
72 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, "radius", radii, nr_elements, stride_in_bytes); }
74 void remove_radius_array(const context& ctx);
76 template <typename T = float>
77 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); }
79 template <typename T = float>
80 void set_sphere(const context& ctx, const cgv::math::fvec<T, 4>& sphere) {
81 ref_prog().set_attribute(ctx, ref_prog().get_attribute_location(ctx, "position"), (const cgv::math::fvec<T, 3>&)sphere);
82 ref_prog().set_attribute(ctx, ref_prog().get_attribute_location(ctx, "radius"), sphere[3]);
83 has_positions = true;
84 has_radii = true;
85 }
87 template <typename T = float>
88 void set_sphere_array(const context& ctx, const std::vector<cgv::math::fvec<T, 4> >& spheres) {
89 set_composed_attribute_array(ctx, "position", &spheres.front(), spheres.size(), reinterpret_cast<const cgv::math::fvec<T, 3>&>(spheres.front()));
90 ref_composed_attribute_array(ctx, "radius", "position", &spheres.front(), spheres.size(), spheres[0][3]);
91 has_positions = true;
92 has_radii = true;
93 }
95 bool validate_attributes(const context& ctx) const;
97 bool enable(context& ctx);
99 bool disable(context& ctx);
101 void draw(context& ctx, size_t start, size_t count,
102 bool use_strips = false, bool use_adjacency = false, uint32_t strip_restart_index = -1);
103 };
104
106 {
107 bool self_reflect(cgv::reflect::reflection_handler& rh);
108 };
110 }
111}
112
113
114#include <cgv/config/lib_end.h>
A vector with zero based index.
Definition fvec.h:26
represent a color with components of given type and color and alpha model as specified.
Definition color.h:574
the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base.
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
a shader program combines several shader code fragments to a complete definition of the shading pipel...
renderer that supports splatting of spheres
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
base classes for renderers that support surface rendering
std::map< std::string, std::string > shader_define_map
typedef for shader define map data structure
Definition shader_code.h:52
sphere_renderer & ref_sphere_renderer(context &ctx, int ref_count_change)
reference to a singleton sphere renderer that can be shared among drawables
the cgv namespace
Definition print.h:11
this reflection traits implementation is used for external self_reflect implementations of instances ...
base class for all render styles
Definition renderer.h:16
render style for sphere rendere
float radius
default value assigned to radius attribute in enable method of sphere renderer, set to 1 in construct...
cgv::media::color< float, cgv::media::RGB, cgv::media::OPACITY > halo_color
color of halo with opacity channel
float halo_width_in_pixel
set to 0 in constructor
bool use_group_radius
whether to use the group radius
float percentual_halo_width
set to 0 in constructor
float radius_scale
multiplied to the sphere radii, initialized to 1
float halo_color_strength
strength in [0,1] of halo color with respect to color of primitive
float blend_width_in_pixel
set to 1 in constructor