3#include "surface_renderer.h"
4#include <cgv/reflect/reflect_enum.h>
5#include <cgv/render/textured_rectangle.h>
7#include "gl/lib_begin.h"
11 class CGV_API rectangle_renderer;
25 RTM_MULTIPLY_SECONDARY_COLOR,
26 RTM_MULTIPLY_BORDER_COLOR,
27 RTM_MIX_COLOR_AND_SECONDARY_COLOR,
28 RTM_MIX_COLOR_AND_BORDER_COLOR,
29 RTM_MIX_SECONDARY_COLOR_AND_COLOR,
30 RTM_MIX_BORDER_COLOR_AND_COLOR,
31 RTM_RED_MIX_COLOR_AND_SECONDARY_COLOR,
32 RTM_RED_MIX_COLOR_AND_BORDER_COLOR,
33 RTM_RED_MIX_SECONDARY_COLOR_AND_COLOR,
34 RTM_RED_MIX_BORDER_COLOR_AND_COLOR
60 mutable bool position_is_center =
true;
62 rgba default_secondary_color = { 0.5f, 0.5f, 0.5f, 1.0f };
64 rgba default_border_color = { 0.0f, 0.0f, 0.0f, 1.0f };
66 float border_width_in_pixel = 0.0f;
68 float percentual_border_width = 0.0f;
72 float pixel_blend = 0.0f;
78 float default_depth_offset = 0.0f;
80 bool blend_rectangles =
false;
88 bool has_extents =
false;
90 bool has_secondary_colors =
false;
92 bool has_border_colors =
false;
94 bool has_border_infos =
false;
96 bool has_translations =
false;
98 bool has_rotations =
false;
100 bool has_depth_offsets =
false;
101 float y_view_angle = 45.0f;
108 void set_y_view_angle(
float y_view_angle);
114 bool init(
context& ctx)
override;
116 void set_position_is_center(
bool _position_is_center);
118 template <
typename T>
121 template <
typename T>
124 template <
typename T>
127 void remove_extent_array(
const context& ctx);
129 template <
typename T>
131 has_positions =
true;
133 set_position_is_center(
false);
134 ref_prog().set_attribute(ctx,
"position", box.
get_min_pnt());
135 ref_prog().set_attribute(ctx,
"extent", box.
get_max_pnt());
138 template <
typename T>
140 set_composed_attribute_array(ctx,
"position", &boxes.front(), boxes.size(), boxes[0].get_min_pnt());
141 ref_composed_attribute_array(ctx,
"extent",
"position", &boxes.front(), boxes.size(), boxes[0].get_max_pnt());
142 has_positions =
true;
144 set_position_is_center(
false);
147 template <
typename T>
149 set_composed_attribute_array(ctx,
"position", boxes, count, boxes[0].get_min_pnt());
150 ref_composed_attribute_array(ctx,
"extent",
"position", boxes, count, boxes[0].get_max_pnt());
151 has_positions =
true;
153 set_position_is_center(
false);
159 set_composed_attribute_array(ctx,
"position", &tc_rects.front(), tc_rects.size(), tc_rects[0].rectangle.get_min_pnt());
160 ref_composed_attribute_array(ctx,
"extent",
"position", &tc_rects.front(), tc_rects.size(), tc_rects[0].rectangle.get_max_pnt());
161 ref_composed_attribute_array(ctx,
"texcoord",
"position", &tc_rects.front(), tc_rects.size(), tc_rects[0].texcoords);
162 has_positions =
true;
164 has_texcoords =
true;
165 set_position_is_center(
false);
169 set_composed_attribute_array(ctx,
"position", tc_rects, count, tc_rects[0].rectangle.get_min_pnt());
170 ref_composed_attribute_array(ctx,
"extent",
"position", tc_rects, count, tc_rects[0].rectangle.get_max_pnt());
171 ref_composed_attribute_array(ctx,
"texcoord",
"position", tc_rects, count, tc_rects[0].texcoords);
172 has_positions =
true;
174 has_texcoords =
true;
175 set_position_is_center(
false);
178 template <
typename T>
179 void set_secondary_color(
const context& ctx,
const T& color) { has_secondary_colors =
true; ref_prog().set_attribute(ctx,
"secondary_color", color); }
181 template <
typename T>
184 template <
typename T>
185 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); }
187 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);
189 template <
typename T>
190 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); }
192 void remove_secondary_color_array(
const context& ctx);
195 template <
typename T>
196 void set_border_color(
const context& ctx,
const T& color) { has_border_colors =
true; ref_prog().set_attribute(ctx, get_prog_attribute_location(ctx,
"border_color"), color); }
198 template <
typename T>
199 void set_border_color_array(
const context& ctx,
const std::vector<T>& colors) { has_border_colors =
true; set_attribute_array(ctx,
"border_color", colors); }
201 template <
typename T>
202 void set_border_color_array(
const context& ctx,
const T* colors,
size_t nr_elements,
unsigned stride_in_bytes = 0) { has_border_colors =
true; set_attribute_array(ctx,
"border_color", colors, nr_elements, stride_in_bytes); }
204 void set_border_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);
206 template <
typename T>
207 void set_border_color_array(
const context& ctx,
const vertex_buffer& vbo,
size_t offset_in_bytes,
size_t nr_elements,
unsigned stride_in_bytes = 0) {
set_border_color_array(ctx,
type_descriptor(
element_descriptor_traits<T>::get_type_descriptor(T()),
true), vbo, offset_in_bytes, nr_elements, stride_in_bytes); }
209 void remove_border_color_array(
const context& ctx);
211 template <
typename T>
214 template <
typename T>
215 void set_border_info_array(
const context& ctx,
const std::vector<T>& border_infos) { has_border_infos =
true; set_attribute_array(ctx,
"border_info", border_infos); }
217 template <
typename T>
218 void set_border_info_array(
const context& ctx,
const T* border_infos,
size_t nr_elements,
unsigned stride_in_bytes = 0) { has_border_infos =
true; set_attribute_array(ctx,
"border_info", border_infos, nr_elements, stride_in_bytes); }
222 template <
typename T>
223 void set_border_info_array(
const context& ctx,
const vertex_buffer& vbo,
size_t offset_in_bytes,
size_t nr_elements,
unsigned stride_in_bytes = 0) {
set_border_info_array(ctx,
type_descriptor(
element_descriptor_traits<T>::get_type_descriptor(T()),
true), vbo, offset_in_bytes, nr_elements, stride_in_bytes); }
225 void remove_border_info_array(
const context& ctx);
228 template <
typename T>
229 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); }
231 template <
typename T =
float>
232 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); }
234 void remove_depth_offset_array(
const context& ctx);
236 template <
typename T>
237 void set_translation(
const context& ctx,
const T& translation) { has_translations =
true; ref_prog().set_attribute(ctx, get_prog_attribute_location(ctx,
"translation"), translation); }
239 template <
typename T>
240 void set_translation_array(
const context& ctx,
const std::vector<T>& translations) { has_translations =
true; set_attribute_array(ctx,
"translation", translations); }
242 template <
typename T>
243 void set_translation_array(
const context& ctx,
const T* translations,
size_t nr_elements,
unsigned stride) { has_translations =
true; set_attribute_array(ctx,
"translation", translations, nr_elements, stride); }
245 void remove_translation_array(
const context& ctx);
247 template <
typename T>
248 void set_rotation(
const context& ctx,
const T& rotation) { has_rotations =
true; ref_prog().set_attribute(ctx, get_prog_attribute_location(ctx,
"rotation"), rotation); }
250 template <
typename T>
251 void set_rotation_array(
const context& ctx,
const std::vector<T>& rotations) { has_rotations =
true; set_attribute_array(ctx,
"rotation", rotations); }
253 template <
typename T>
254 void set_rotation_array(
const context& ctx,
const T* rotations,
size_t nr_elements,
unsigned stride = 0) { has_rotations =
true; set_attribute_array(ctx,
"rotation", rotations, nr_elements, stride); }
256 void remove_rotation_array(
const context& ctx);
258 bool validate_attributes(
const context& ctx)
const override;
260 bool enable(
context& ctx)
override;
262 bool disable(
context& ctx)
override;
264 void draw(
context& ctx,
size_t start,
size_t count,
265 bool use_strips =
false,
bool use_adjacency =
false, uint32_t strip_restart_index = -1)
override;
275#include <cgv/config/lib_end.h>
A vector with zero based index.
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.
renderer that supports plane rendering
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_border_color_array(const context &ctx, const T *colors, size_t nr_elements, unsigned stride_in_bytes=0)
template method to set the border color attribute from a vector of colors of type T
void set_depth_offset_array(const context &ctx, const std::vector< T > &depth_offsets)
set per rectangle depth offsets
void set_border_color_array(const context &ctx, const std::vector< T > &colors)
template method to set the border color attribute from a vector of colors of type T
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_translation_array(const context &ctx, const T *translations, size_t nr_elements, unsigned stride)
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 cgv::math::fvec< T, 2U > *extents, size_t nr_elements, unsigned stride_in_bytes=0)
extent array specifies plane side lengths from origin to edge
void set_textured_rectangle_array(const context &ctx, const std::vector< textured_rectangle > &tc_rects)
specify rectangle array directly. This sets position_is_center to false as well as position and exten...
render_style * create_render_style() const override
create and return the default render style
void set_rectangle(const context &ctx, const cgv::media::axis_aligned_box< T, 2 > &box)
specify a single rectangle without array. This sets position_is_center to false as well as position a...
void set_border_info_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 border_info attribute from a vertex buffer object, the element type must b...
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_textured_rectangle_array(const context &ctx, const textured_rectangle *tc_rects, size_t count)
specify ractangle array directly. This sets position_is_center to false as well as position and exten...
void set_rectangle_array(const context &ctx, const cgv::media::axis_aligned_box< T, 2 > *boxes, size_t count)
specify ractangle array directly. This sets position_is_center to false as well as position and exten...
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_border_info_array(const context &ctx, const std::vector< T > &border_infos)
templated method to set the border_info attribute array from a vector of border_infos of type T,...
void set_rotation(const context &ctx, const T &rotation)
set single rotation for all rectangles from a quaternion of type T, which has 4 components
void set_border_info_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 border_info attribute from a vertex buffer object, the element type must be given a...
void set_border_info(const context &ctx, const cgv::math::fvec< T, 3 > &border_info)
specify a single border_info for all lines
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_border_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 border color attribute from a vertex buffer object, the element type must ...
void set_translation(const context &ctx, const T &translation)
template method to set translation for all rectangles from a vector type T, which should have 3 compo...
void set_rotation_array(const context &ctx, const T *rotations, size_t nr_elements, unsigned stride=0)
template method to set the rotation from a vector of quaternions of type T, which should have 4 compo...
void set_depth_offset(const context &ctx, const T &depth_offset)
specify a single depth_offset for all lines
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_extent_array(const context &ctx, const std::vector< cgv::math::fvec< T, 2U > > &extents)
extent array specifies plane side lengths from origin to edge
void set_border_color(const context &ctx, const T &color)
templated method to set the border color attribute from a single color of type T
void set_border_info_array(const context &ctx, const T *border_infos, size_t nr_elements, unsigned stride_in_bytes=0)
templated method to set the border_info attribute from an array of border_infos of type T,...
void set_extent(const context &ctx, const cgv::math::fvec< T, 2U > &extent)
specify a single extent for all boxes
std::string get_default_prog_name() const override
return the default shader program name
void set_rectangle_array(const context &ctx, const std::vector< cgv::media::axis_aligned_box< T, 2 > > &boxes)
specify rectangle array directly. This sets position_is_center to false as well as position and exten...
base classes for renderers that support surface rendering
a vertex buffer is an unstructured memory block on the GPU.
rectangle_renderer & ref_rectangle_renderer(context &ctx, int ref_count_change)
reference to a singleton plane renderer that can be shared among drawables
RectangleTextureMode
different modes to use texture during rectangle rendering
RectangleBoderMode
different modes to compute relative border with for rectangle rendering
this type specific reflection traits class is used by the reflect_enum function to reflect enum types
this reflection traits implementation is used for external self_reflect implementations of instances ...
configuration of rectangle renderer
base class for all render styles
This type provides a simple helper class to store rectangles with texture coordinates.
compact type description of data that can be sent to the context; convertible to int