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 {
25 bool rounding = false;
27 float default_radius = 0.01f;
30 };
31
33 class CGV_API box_renderer : public surface_renderer
34 {
35 protected:
49 render_style* create_render_style() const;
51 bool build_shader_program(context& ctx, shader_program& prog, const shader_define_map& defines);
53 void update_defines(shader_define_map& defines);
54 public:
58 void enable_attribute_array_manager(const context& ctx, attribute_array_manager& aam);
60 void disable_attribute_array_manager(const context& ctx, attribute_array_manager& aam);
62 void set_position_is_center(bool _position_is_center);
64 bool enable(context& ctx);
66 template <typename T>
67 void set_extent(const context& ctx, const T& extent) { has_extents = true; ref_prog().set_attribute(ctx, get_prog_attribute_location(ctx, "extent"), extent); }
69 template <typename T>
70 void set_extent_array(const context& ctx, const std::vector<T>& extents) { has_extents = true; set_attribute_array(ctx, "extent", extents); }
72 template <typename T>
73 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); }
75 void remove_extent_array(const context& ctx);
77 template <typename T = float>
78 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); }
80 template <typename T = float>
81 void set_radius_array(const context& ctx, const std::vector<T>& radii) { has_radii = true; set_attribute_array(ctx, "radius", radii); }
83 template <typename T = float>
84 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); }
86 void remove_radius_array(const context& ctx);
88 template <typename T>
89 void set_secondary_color(const context& ctx, const T& color) { has_secondary_colors = true; ref_prog().set_attribute(ctx, "secondary_color", color); }
91 template <typename T>
92 void set_secondary_color_array(const context& ctx, const std::vector<T>& colors) { has_secondary_colors = true; set_attribute_array(ctx, "secondary_color", colors); }
94 template <typename T>
95 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); }
97 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);
99 template <typename T>
100 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); }
102 void remove_secondary_color_array(const context& ctx);
104 template <typename T>
106 set_position(ctx, box.get_min_pnt());
107 set_extent(ctx, box.get_max_pnt());
108 set_position_is_center(false);
109 }
111 template <typename T>
112 void set_box_array(const context& ctx, const std::vector<cgv::media::axis_aligned_box<T, 3> >& boxes) {
113 set_composed_attribute_array(ctx, "position", &boxes.front(), boxes.size(), boxes[0].get_min_pnt());
114 ref_composed_attribute_array(ctx, "extent", "position", &boxes.front(), boxes.size(), boxes[0].get_max_pnt());
115 has_positions = true;
116 has_extents = true;
117 set_position_is_center(false);
118 }
120 template <typename T>
121 void set_box_array(const context& ctx, const cgv::media::axis_aligned_box<T, 3>* boxes, size_t count) {
122 set_composed_attribute_array(ctx, "position", boxes, count, boxes[0].get_min_pnt());
123 ref_composed_attribute_array(ctx, "extent", "position", boxes, count, boxes[0].get_max_pnt());
124 has_positions = true;
125 has_extents = true;
126 set_position_is_center(false);
127 }
129 template <typename T>
130 void set_translation_array(const context& ctx, const std::vector<T>& translations) { has_translations = true; set_attribute_array(ctx, "translation", translations); }
132 template <typename T>
133 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); }
135 void remove_translation_array(const context& ctx);
137 template <typename T>
138 void set_rotation_array(const context& ctx, const std::vector<T>& rotations) { has_rotations = true; set_attribute_array(ctx, "rotation", rotations); }
140 template <typename T>
141 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); }
143 void remove_rotation_array(const context& ctx);
145 bool disable(context& ctx);
147 void draw(context& ctx, size_t start, size_t count,
148 bool use_strips = false, bool use_adjacency = false, uint32_t strip_restart_index = -1);
149 };
151 {
152 bool self_reflect(cgv::reflect::reflection_handler& rh);
153 };
155 }
156}
157
158#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...
bool has_translations
whether array with per box translations has been specified
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
bool has_rotations
whether array with per box rotations has been specified
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
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...
bool has_radii
store whether extent array has been specified
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...
bool has_secondary_colors
whether secondary color or color array was set
bool position_is_center
whether position is box center, if not it is lower left bottom corner
bool has_extents
store whether extent array has been specified
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...
base classes for renderers that support surface rendering
a vertex buffer is an unstructured memory block on the GPU.
std::map< std::string, std::string > shader_define_map
typedef for shader define map data structure
Definition shader_code.h:52
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
vec3 default_extent
extent used in case extent array is not specified
vec3 relative_anchor
box anchor position relative to center that corresponds to the position attribute
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:47