cgv
Loading...
Searching...
No Matches
surface_render_data.h
1#pragma once
2
3#include "surface_renderer.h"
4#include "render_data_base.h"
5
6namespace cgv {
7namespace render {
8
11template <typename ColorType = rgb>
12class surface_render_data : public render_data_base<surface_renderer, surface_render_style, ColorType> {
13private:
14 // Base class we're going to use virtual functions from
16
17 surface_renderer& ref_renderer_singleton(context& ctx, int ref_count_change = 0) override {
18 return ref_surface_renderer(ctx, ref_count_change);
19 }
20
21protected:
23 bool transfer(context& ctx, surface_renderer& r) override {
24 if(super::transfer(ctx, r)) {
25 CGV_RDB_TRANSFER_ARRAY(normal, normals);
26 CGV_RDB_TRANSFER_ARRAY(texcoord, texcoords);
27 return true;
28 }
29 return false;
30 }
31
32public:
34 std::vector<cgv::vec3> normals;
36 std::vector<cgv::vec2> texcoords;
37
38 void clear() {
40 normals.clear();
41 texcoords.clear();
42 }
43
44 void add_normal(const cgv::vec3& normal) {
45 normals.push_back(normal);
46 }
47
48 void add_texcoord(const cgv::vec2& texcoord) {
49 texcoords.push_back(texcoord);
50 }
51
52 void add_triangle(const vec3& position0, const vec3& position1, const vec3& position2) {
53 super::add_position(position0);
54 super::add_position(position1);
55 super::add_position(position2);
56 }
57
58 void add_triangle_color(const ColorType& color) {
59 super::add_color(color);
60 super::add_color(color);
61 super::add_color(color);
62 }
63
64 void add_triangle_colors(const ColorType& color0, const ColorType& color1, const ColorType& color2) {
65 super::add_color(color0);
66 super::add_color(color1);
67 super::add_color(color2);
68 }
69
70 void add_triangle_normal(const vec3& normal) {
71 add_normal(normal);
72 add_normal(normal);
73 add_normal(normal);
74 }
75
76 void add_triangle_normals(const vec3& normal0, const vec3& normal1, const vec3& normal2) {
77 add_normal(normal0);
78 add_normal(normal1);
79 add_normal(normal2);
80 }
81
82 void add_triangle_texcoord(const vec2& texcoord) {
83 add_texcoord(texcoord);
84 add_texcoord(texcoord);
85 add_texcoord(texcoord);
86 }
87
88 void add_triangle_texcoords(const vec2& texcoord0, const vec2& texcoord1, const vec2& texcoord2) {
89 add_texcoord(texcoord0);
90 add_texcoord(texcoord1);
91 add_texcoord(texcoord2);
92 }
93
94 // Explicitly use add from the base class since it is shadowed by the overloaded versions
95 using super::add;
96
97 void add(const vec3& position, const cgv::vec3& normal) {
98 super::add_position(position);
99 add_normal(normal);
100 }
101
102 void add(const vec3& position, const ColorType& color, const cgv::vec3& normal) {
103 super::add(position, color);
104 add_normal(normal);
105 }
106
107 void add(const vec3& position, const ColorType& color, const cgv::vec2& texcoord) {
108 super::add(position, color);
109 add_texcoord(texcoord);
110 }
111
112 void fill_normals(const cgv::vec3& normal) {
113 super::fill(normals, normal);
114 }
115
116 void fill_texcoords(const cgv::vec2& texcoord) {
117 super::fill(texcoords, texcoord);
118 }
119};
120
121}
122}
base class for all drawables, which is independent of the used rendering API.
Definition context.h:670
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.
Render data for triangular surface geometry with support for the surface_renderer.
std::vector< cgv::vec2 > texcoords
array of texture coordinates
std::vector< cgv::vec3 > normals
array of normals
bool transfer(context &ctx, surface_renderer &r) override
See render_data_base::transfer.
base classes for renderers that support surface rendering
surface_renderer & ref_surface_renderer(context &ctx, int ref_count_change)
reference to a singleton surface renderer that can be shared among drawables
this header is dependency free
Definition print.h:11
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors
Definition fvec.h:692
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
Definition fvec.h:694