cgv
Loading...
Searching...
No Matches
cone_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
10 class CGV_API cone_renderer;
11
13
16 extern CGV_API cone_renderer& ref_cone_renderer(context& ctx, int ref_count_change = 0);
17
18 struct CGV_API cone_render_style : public surface_render_style {
20 float radius_scale = 1.0f;
22 float radius = 1.0f;
23
24 bool show_caps = true;
25 bool rounded_caps = false;
26
27 bool enable_texturing = false;
28 enum TextureBlendMode {
29 TBM_MIX = 0,
30 TBM_TINT = 1,
31 TBM_MULTIPLY = 2,
32 TBM_INVERSE_MULTIPLY = 3,
33 TBM_ADD = 4,
34 } texture_blend_mode = TextureBlendMode::TBM_MIX;
35 float texture_blend_factor = 1.0f;
36 bool texture_tile_from_center = false;
37 vec2 texture_offset = { 0.0f };
38 vec2 texture_tiling = { 1.0f };
39 bool texture_use_reference_length = false;
40 float texture_reference_length = 1.0f;
41
42 bool enable_ambient_occlusion = false;
43 float ao_offset = 0.04f;
44 float ao_distance = 0.8f;
45 float ao_strength = 1.0f;
46
47 vec3 tex_offset = { 0.0f };
48 vec3 tex_scaling = { 1.0f };
49 vec3 tex_coord_scaling = { 1.0f };
50 float texel_size = 1.0f;
51 float cone_angle_factor = 1.0f;
52 std::vector<vec3> sample_dirs = std::vector<vec3>(3, { 0.0f, 1.0f, 0.0f });
53 };
54
56 class CGV_API cone_renderer : public surface_renderer {
57 protected:
58 bool has_radii = false;
60 std::string get_default_prog_name() const override { return "cone.glpr"; }
62 render_style* create_render_style() const override { return new cone_render_style(); }
64 void update_shader_program_options(shader_compile_options& options) const override;
65
66 texture* albedo_texture = nullptr;
67 texture* density_texture = nullptr;
68
69 public:
71 void enable_attribute_array_manager(const context& ctx, attribute_array_manager& aam) override;
73 void disable_attribute_array_manager(const context& ctx, attribute_array_manager& aam) override;
74 bool set_albedo_texture(texture* tex);
75 bool set_density_texture(texture* tex);
77 bool enable(context& ctx) override;
79 template <typename T = float>
80 void set_radius_array(const context& ctx, const std::vector<T>& radii) { has_radii = true; set_attribute_array(ctx, "radius", radii); }
82 template <typename T = float>
83 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); }
85 void remove_radius_array(const context& ctx);
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 override;
96
97 bool disable(context& ctx) override;
99 void draw(context& ctx, size_t start, size_t count,
100 bool use_strips = false, bool use_adjacency = false, uint32_t strip_restart_index = -1) override;
102 void clear(const context& ctx) override;
103 };
104
106 bool self_reflect(cgv::reflect::reflection_handler& rh);
107 };
108
110 }
111}
112
113#include <cgv/config/lib_end.h>
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
renderer that supports raycasting of cones
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
std::string get_default_prog_name() const override
return the default shader program name
render_style * create_render_style() const override
create and return the default render style
base class for all drawables, which is independent of the used rendering API.
Definition context.h:627
Stores preprocessor options used for conditionally compiling shader programs.
Definition shader_code.h:73
base classes for renderers that support surface rendering
the texture class encapsulates all functionality independent of the rendering api.
Definition texture.h:15
cone_renderer & ref_cone_renderer(context &ctx, int ref_count_change)
reference to a singleton cone renderer that is shared among drawables
the cgv namespace
Definition print.h:11
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
Definition fvec.h:670
this reflection traits implementation is used for external self_reflect implementations of instances ...
base class for all render styles
Definition renderer.h:16