cgv
Loading...
Searching...
No Matches
line_renderer.h
1#pragma once
2
3#include "group_renderer.h"
4#include <cgv/media/color.h>
5
6#include "gl/lib_begin.h"
7
8namespace cgv { // @<
9 namespace render { // @<
10
12 struct CGV_API line_render_style : public group_render_style
13 {
14 // default values for program attributes
15
17 vec3 default_normal = { 0.0f, 0.0f, 1.0f };
19 rgba default_color = { 1.0f };
21 float default_depth_offset = 0.0f;
23 float default_line_width = 1.0f;
24
26 bool blend_lines = false;
27
28 // vertex shader uniforms
29
31 rgba halo_color = { 0.0f, 0.0f, 0.0f, 1.0f };
33 float halo_width_in_pixel = 0.0f;
35 float percentual_halo_width = 0.0f;
37 bool screen_aligned = true;
38
39 // geometry shader uniforms
40
42 bool measure_line_width_in_pixel = true;
44 float reference_line_width = 0.001f;
46 float blend_width_in_pixel = 0.0f;
47
48 // fragment shader uniforms
49
51 float halo_color_strength = 1.0f;
52 };
53
55 class CGV_API line_renderer : public group_renderer
56 {
57 protected:
58 bool has_normals = false;
59 bool has_line_widths = false;
60 bool has_depth_offsets = false;
62 std::string get_default_prog_name() const override { return "line.glpr"; }
64 render_style* create_render_style() const override { return new line_render_style(); }
65 public:
67 bool enable(context& ctx) override;
69 bool disable(context& ctx) override;
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;
75 bool init(context& ctx) override;
77 template <typename T>
78 void set_normal(const context& ctx, const cgv::math::fvec<T,3>& normal) { has_normals = true; ref_prog().set_attribute(ctx, get_prog_attribute_location(ctx, "normal"), normal); }
80 template <typename T>
81 void set_normal_array(const context& ctx, const std::vector<T>& normals) { has_normals = true; set_attribute_array(ctx, "normal", normals); }
83 template <typename T>
84 void set_normal_array(const context& ctx, const T* normals, size_t nr_elements, unsigned stride_in_bytes = 0) { has_normals = true; set_attribute_array(ctx, "normal", normals, nr_elements, stride_in_bytes); }
86 void remove_normal_array(const context& ctx);
88 template <typename T>
89 void set_line_width(const context& ctx, const T& line_width) { has_line_widths = true; ref_prog().set_attribute(ctx, get_prog_attribute_location(ctx, "line_width"), line_width); }
91 template <typename T>
92 void set_line_width_array(const context& ctx, const std::vector<T>& line_widths) { has_line_widths = true; set_attribute_array(ctx, "line_width", line_widths); }
94 template <typename T>
95 void set_line_width_array(const context& ctx, const T* line_widths, size_t nr_elements, unsigned stride_in_bytes = 0) { has_line_widths = true; set_attribute_array(ctx, "line_width", line_widths, nr_elements, stride_in_bytes); }
97 void remove_line_width_array(const context& ctx);
99 template <typename T>
100 void set_depth_offset(const context& ctx, const T& depth_offset) { has_depth_offsets = true; ref_prog().set_attribute(ctx, get_prog_attribute_location(ctx, "depth_offset"), depth_offset); }
102 template <typename T>
103 void set_depth_offset_array(const context& ctx, const std::vector<T>& depth_offsets) { has_depth_offsets = true; set_attribute_array(ctx, "depth_offset", depth_offsets); }
105 template <typename T>
106 void set_depth_offset_array(const context& ctx, const T* depth_offsets, size_t nr_elements, unsigned stride_in_bytes = 0) { has_depth_offsets = true; set_attribute_array(ctx, "depth_offset", depth_offsets, nr_elements, stride_in_bytes); }
108 void remove_depth_offset_array(const context& ctx);
110 void draw(context& ctx, size_t start, size_t count,
111 bool use_strips = false, bool use_adjacency = false, uint32_t strip_restart_index = -1) override;
112 };
114 extern CGV_API line_renderer& ref_line_renderer(context& ctx, int ref_count_change = 0);
117 {
118 bool self_reflect(cgv::reflect::reflection_handler& rh);
119 };
121 }
122}
123
124#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
base class for all drawables, which is independent of the used rendering API.
Definition context.h:627
abstract renderer class that provides functionality for grouping primitives
renderer that supports point splatting
void set_depth_offset_array(const context &ctx, const T *depth_offsets, size_t nr_elements, unsigned stride_in_bytes=0)
depth_offset array specifies box extends in case of position_is_center=true, otherwise the maximum po...
void set_normal_array(const context &ctx, const std::vector< T > &normals)
templated method to set the normal attribute from a vector of normals of type T, which should have 3 ...
void set_normal(const context &ctx, const cgv::math::fvec< T, 3 > &normal)
specify a single normal for all lines
void set_line_width_array(const context &ctx, const T *line_widths, size_t nr_elements, unsigned stride_in_bytes=0)
line_width array specifies box extends in case of position_is_center=true, otherwise the maximum poin...
std::string get_default_prog_name() const override
return the default shader program name
void set_line_width(const context &ctx, const T &line_width)
specify a single line_width for all lines
void set_depth_offset(const context &ctx, const T &depth_offset)
specify a single depth_offset for all lines
void set_normal_array(const context &ctx, const T *normals, size_t nr_elements, unsigned stride_in_bytes=0)
templated method to set the normal attribute from an array of normals of type T, which should have 3 ...
render_style * create_render_style() const override
create and return the default render style
void set_depth_offset_array(const context &ctx, const std::vector< T > &depth_offsets)
depth_offset array specifies box extends in case of position_is_center=true, otherwise the maximum po...
void set_line_width_array(const context &ctx, const std::vector< T > &line_widths)
line_width array specifies box extends in case of position_is_center=true, otherwise the maximum poin...
the cgv namespace
Definition print.h:11
this reflection traits implementation is used for external self_reflect implementations of instances ...
render style used for group information
base class for all render styles
Definition renderer.h:16