cgv
Loading...
Searching...
No Matches
rectangle_render_data.h
1#pragma once
2
3#include "rectangle_renderer.h"
4#include "render_data_base.h"
5
6namespace cgv {
7namespace render {
8
11template <typename ColorType = rgb>
12class rectangle_render_data : public render_data_base<rectangle_renderer, rectangle_render_style, ColorType> {
13private:
14 // Base class we're going to use virtual functions from
16
17 rectangle_renderer& ref_renderer_singleton(context& ctx, int ref_count_change = 0) override {
18 return ref_rectangle_renderer(ctx, ref_count_change);
19 }
20
21protected:
23 bool transfer(context& ctx, rectangle_renderer& r) override {
24 if(super::transfer(ctx, r)) {
25 CGV_RDB_TRANSFER_ARRAY(secondary_color, secondary_colors);
26 CGV_RDB_TRANSFER_ARRAY(border_color, border_colors);
27 CGV_RDB_TRANSFER_ARRAY(extent, extents);
28 CGV_RDB_TRANSFER_ARRAY(translation, translations);
29 CGV_RDB_TRANSFER_ARRAY(rotation, rotations);
30 CGV_RDB_TRANSFER_ARRAY(texcoord, texcoords);
31 return true;
32 }
33 return false;
34 }
35
43 if(extents.empty() && const_extent)
44 r.set_extent(ctx, const_extent.value());
45 if(translations.empty() && const_translation)
46 r.set_translation(ctx, const_translation.value());
47 if(rotations.empty() && const_rotation)
48 r.set_rotation(ctx, const_rotation.value());
49 if(texcoords.empty() && const_texcoord)
50 r.set_texcoord(ctx, const_texcoord.value());
51 }
52
53public:
55 std::vector<ColorType> secondary_colors;
57 std::vector<ColorType> border_colors;
59 std::vector<vec2> extents;
61 std::vector<vec3> translations;
63 std::vector<quat> rotations;
65 std::vector<vec4> texcoords;
66
79
80 void clear() {
82 secondary_colors.clear();
83 border_colors.clear();
84 extents.clear();
85 translations.clear();
86 rotations.clear();
87 texcoords.clear();
88 }
89
90 void add_secondary_color(const ColorType& color) {
91 secondary_colors.push_back(color);
92 }
93
94 void add_border_color(const ColorType& color) {
95 border_colors.push_back(color);
96 }
97
98 void add_extent(const vec2& extent) {
99 extents.push_back(extent);
100 }
101
102 void add_translation(const vec3& translation) {
103 translations.push_back(translation);
104 }
105
106 void add_rotation(const quat& rotation) {
107 rotations.push_back(rotation);
108 }
109
110 void add_texcoord(const vec4& texcoord) {
111 texcoords.push_back(texcoord);
112 }
113
114 // Explicitly use add from the base class since it is shadowed by the overloaded versions
115 using super::add;
116
117 void add(const vec3& position, const vec2& extent) {
118 super::add_position(position);
119 add_extent(extent);
120 }
121
122 void add(const vec3& position, const vec4& texcoord) {
123 super::add_position(position);
124 add_texcoord(texcoord);
125 }
126
127 void add(const vec3& position, const ColorType& color, const vec2& extent) {
128 super::add(position, color);
129 add_extent(extent);
130 }
131
132 void add(const vec3& position, const vec2& extent, const quat& rotation) {
133 super::add_position(position);
134 add_extent(extent);
135 add_rotation(rotation);
136 }
137
138 void add(const vec3& translation, const quat& rotation) {
139 add_translation(translation);
140 add_rotation(rotation);
141 }
142
143 void fill_secondary_colors(const ColorType& color) {
145 }
146
147 void fill_border_colors(const ColorType& color) {
149 }
150
151 void fill_extents(const vec2& extent) {
152 super::fill(extents, extent);
153 }
154
155 void fill_translations(const vec3& translation) {
156 super::fill(translations, translation);
157 }
158
159 void fill_rotations(const quat& rotation) {
160 super::fill(rotations, rotation);
161 }
162
163 void fill_texcoords(const vec4& texcoord) {
164 super::fill(texcoords, texcoord);
165 }
166};
167
168}
169}
A simple and naiive implementation of an optional value.
Definition optional.h:22
base class for all drawables, which is independent of the used rendering API.
Definition context.h:626
Render data for rectangle geometry with support for the rectangle_renderer.
cgv::data::optional< ColorType > const_border_color
optional constant border color used for all elements
bool transfer(context &ctx, rectangle_renderer &r) override
See render_data_base::transfer.
std::vector< ColorType > border_colors
array of border colors
cgv::data::optional< vec4 > const_texcoord
optional constant texcoord used for all elements
cgv::data::optional< vec2 > const_extent
optional constant extent used for all elements
std::vector< vec4 > texcoords
array of texcoords
cgv::data::optional< ColorType > const_secondary_color
optional constant secondary color used for all elements
cgv::data::optional< quat > const_rotation
optional constant rotation used for all elements
std::vector< vec2 > extents
array of extents
std::vector< quat > rotations
array of rotations
std::vector< ColorType > secondary_colors
array of secondary colors
void set_const_attributes(context &ctx, rectangle_renderer &r) override
See render_data_base::set_const_attributes.
std::vector< vec3 > translations
array of translations
cgv::data::optional< vec3 > const_translation
optional constant translation used for all elements
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_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_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_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_extent(const context &ctx, const cgv::math::fvec< T, 2U > &extent)
specify a single extent for all boxes
A base class for storing render data and style usable with the default renderers provided in the cgv:...
virtual bool transfer(context &ctx, RendererType &r)
Transfers the data stored in members to the attribute array.
void clear()
Clear the stored data and set state out of date.
void fill(std::vector< T > &vector, const T &value)
Template for filling a member array to the size of the render data.
virtual void set_const_attributes(context &ctx, RendererType &r)
Set constant vertex attributes if present.
void set_texcoord(const context &ctx, const T &texcoord)
templated method to set the texcoord attribute without array
rectangle_renderer & ref_rectangle_renderer(context &ctx, int ref_count_change)
reference to a singleton plane renderer that can be shared among drawables
the cgv namespace
Definition print.h:11
cgv::math::fvec< float, 4 > vec4
declare type of 4d single precision floating point vectors (used for homogeneous coordinates)
Definition fvec.h:672
cgv::math::quaternion< float > quat
declare type of quaternion
Definition quaternion.h:370
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors
Definition fvec.h:668
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
Definition fvec.h:670