cgv
Loading...
Searching...
No Matches
box_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 box_renderer;
10
12
15 extern CGV_API box_renderer& ref_box_renderer(context& ctx, int ref_count_change = 0);
16
18 struct CGV_API box_render_style : public surface_render_style
19 {
21 vec3 default_extent = { 1.0f };
23 vec3 relative_anchor = { 0.0f };
25 bool rounding = false;
27 float default_radius = 0.01f;
28 };
29
31 class CGV_API box_renderer : public surface_renderer
32 {
33 protected:
35 bool has_extents = false;
37 bool has_radii = false;
39 bool has_secondary_colors = false;
41 bool has_translations = false;
43 bool has_rotations = false;
45 bool position_is_center = true;
46
48 std::string get_default_prog_name() const override { return "box.glpr"; }
50 render_style* create_render_style() const override { return new box_render_style(); }
52 void update_shader_program_options(shader_compile_options& options) const override;
53 public:
55 void enable_attribute_array_manager(const context& ctx, attribute_array_manager& aam) override;
57 void disable_attribute_array_manager(const context& ctx, attribute_array_manager& aam) override;
59 void set_position_is_center(bool _position_is_center);
61 bool enable(context& ctx) override;
63 template <typename T>
64 void set_extent(const context& ctx, const T& extent) { has_extents = true; ref_prog().set_attribute(ctx, get_prog_attribute_location(ctx, "extent"), extent); }
66 template <typename T>
67 void set_extent_array(const context& ctx, const std::vector<T>& extents) { has_extents = true; set_attribute_array(ctx, "extent", extents); }
69 template <typename T>
70 void set_extent_array(const context& ctx, const T* extents, size_t nr_elements, unsigned stride_in_bytes = 0) { has_extents = true; set_attribute_array(ctx, "extent", extents, nr_elements, stride_in_bytes); }
72 void remove_extent_array(const context& ctx);
74 template <typename T = float>
75 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); }
77 template <typename T = float>
78 void set_radius_array(const context& ctx, const std::vector<T>& radii) { has_radii = true; set_attribute_array(ctx, "radius", radii); }
80 template <typename T = float>
81 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); }
83 void remove_radius_array(const context& ctx);
85 template <typename T>
86 void set_secondary_color(const context& ctx, const T& color) { has_secondary_colors = true; ref_prog().set_attribute(ctx, "secondary_color", color); }
88 template <typename T>
89 void set_secondary_color_array(const context& ctx, const std::vector<T>& colors) { has_secondary_colors = true; set_attribute_array(ctx, "secondary_color", colors); }
91 template <typename T>
92 void set_secondary_color_array(const context& ctx, const T* colors, size_t nr_elements, unsigned stride_in_bytes = 0) { has_secondary_colors = true; set_attribute_array(ctx, "secondary_color", colors, nr_elements, stride_in_bytes); }
94 void set_secondary_color_array(const context& ctx, type_descriptor element_type, const vertex_buffer& vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes = 0);
96 template <typename T>
97 void set_secondary_color_array(const context& ctx, const vertex_buffer& vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes = 0) { set_secondary_color_array(ctx, type_descriptor(element_descriptor_traits<T>::get_type_descriptor(T()), true), vbo, offset_in_bytes, nr_elements, stride_in_bytes); }
99 void remove_secondary_color_array(const context& ctx);
101 template <typename T>
103 set_position(ctx, box.get_min_pnt());
104 set_extent(ctx, box.get_max_pnt());
105 set_position_is_center(false);
106 }
108 template <typename T>
109 void set_box_array(const context& ctx, const std::vector<cgv::media::axis_aligned_box<T, 3> >& boxes) {
110 set_composed_attribute_array(ctx, "position", &boxes.front(), boxes.size(), boxes[0].get_min_pnt());
111 ref_composed_attribute_array(ctx, "extent", "position", &boxes.front(), boxes.size(), boxes[0].get_max_pnt());
112 has_positions = true;
113 has_extents = true;
114 set_position_is_center(false);
115 }
117 template <typename T>
118 void set_box_array(const context& ctx, const cgv::media::axis_aligned_box<T, 3>* boxes, size_t count) {
119 set_composed_attribute_array(ctx, "position", boxes, count, boxes[0].get_min_pnt());
120 ref_composed_attribute_array(ctx, "extent", "position", boxes, count, boxes[0].get_max_pnt());
121 has_positions = true;
122 has_extents = true;
123 set_position_is_center(false);
124 }
126 template <typename T>
127 void set_translation_array(const context& ctx, const std::vector<T>& translations) { has_translations = true; set_attribute_array(ctx, "translation", translations); }
129 template <typename T>
130 void set_translation_array(const context& ctx, const T* translations, size_t nr_elements, unsigned stride_in_bytes = 0) { has_translations = true; set_attribute_array(ctx, "translation", translations, nr_elements, stride_in_bytes); }
132 void remove_translation_array(const context& ctx);
134 template <typename T>
135 void set_rotation_array(const context& ctx, const std::vector<T>& rotations) { has_rotations = true; set_attribute_array(ctx, "rotation", rotations); }
137 template <typename T>
138 void set_rotation_array(const context& ctx, const T* rotations, size_t nr_elements, unsigned stride_in_bytes = 0) { has_rotations = true; set_attribute_array(ctx, "rotation", rotations, nr_elements, stride_in_bytes); }
140 void remove_rotation_array(const context& ctx);
142 bool disable(context& ctx) override;
144 void draw(context& ctx, size_t start, size_t count,
145 bool use_strips = false, bool use_adjacency = false, uint32_t strip_restart_index = -1) override;
146 };
148 {
149 bool self_reflect(cgv::reflect::reflection_handler& rh);
150 };
152 }
153}
154
155#include <cgv/config/lib_end.h>
An axis aligned box, defined by to points: min and max.
const fpnt_type & get_max_pnt() const
return a const reference to corner 7
const fpnt_type & get_min_pnt() const
return a const reference to corner 0
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 point splatting
void set_translation_array(const context &ctx, const std::vector< T > &translations)
template method to set the translations from a vector of vectors of type T, which should have 3 compo...
void set_extent_array(const context &ctx, const std::vector< T > &extents)
extent array specifies box extends in case of position_is_center=true, otherwise the maximum point of...
void set_rotation_array(const context &ctx, const std::vector< T > &rotations)
template method to set the rotation from a vector of quaternions of type T, which should have 4 compo...
void set_secondary_color_array(const context &ctx, const vertex_buffer &vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes=0)
template method to set the secondary color attribute from a vertex buffer object, the element type mu...
void set_box(const context &ctx, const cgv::media::axis_aligned_box< T, 3 > &box)
specify a single box. This sets position_is_center to false as well as position and extent attributes
void set_secondary_color_array(const context &ctx, const T *colors, size_t nr_elements, unsigned stride_in_bytes=0)
template method to set the secondary color attribute from a vector of colors of type T
void set_secondary_color_array(const context &ctx, type_descriptor element_type, const vertex_buffer &vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes=0)
method to set the secondary color attribute from a vertex buffer object, the element type must be giv...
void set_secondary_color(const context &ctx, const T &color)
templated method to set the secondary color attribute from a single color of type T
void set_rotation_array(const context &ctx, const T *rotations, size_t nr_elements, unsigned stride_in_bytes=0)
template method to set the rotation from a vector of quaternions of type T, which should have 4 compo...
void set_extent(const context &ctx, const T &extent)
specify a single extent for all boxes
void set_translation_array(const context &ctx, const T *translations, size_t nr_elements, unsigned stride_in_bytes=0)
template method to set the translations from a vector of vectors of type T, which should have 3 compo...
void set_secondary_color_array(const context &ctx, const std::vector< T > &colors)
template method to set the secondary color attribute from a vector of colors of type T
render_style * create_render_style() const override
create and return the default render style
std::string get_default_prog_name() const override
return the default shader program name
void set_extent_array(const context &ctx, const T *extents, size_t nr_elements, unsigned stride_in_bytes=0)
extent array specifies box extends in case of position_is_center=true, otherwise the maximum point of...
void set_box_array(const context &ctx, const std::vector< cgv::media::axis_aligned_box< T, 3 > > &boxes)
specify box array directly. This sets position_is_center to false as well as position and extent arra...
void set_box_array(const context &ctx, const cgv::media::axis_aligned_box< T, 3 > *boxes, size_t count)
specify box array directly. This sets position_is_center to false as well as position and extent arra...
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
a vertex buffer is an unstructured memory block on the GPU.
box_renderer & ref_box_renderer(context &ctx, int ref_count_change)
reference to a singleton box renderer that is shared among drawables
the cgv namespace
Definition print.h:11
this reflection traits implementation is used for external self_reflect implementations of instances ...
boxes use surface render styles
base class for all render styles
Definition renderer.h:16
compact type description of data that can be sent to the context; convertible to int
Definition context.h:56