Easy3D 2.5.3
state.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_RENDERER_STATE_H
28#define EASY3D_RENDERER_STATE_H
29
30#include <string>
31
32#include <easy3d/core/types.h>
33
34
35namespace easy3d {
36
37 class Texture;
38
45 class State {
46 public:
47
64 enum Method {
65 UNIFORM_COLOR, COLOR_PROPERTY, SCALAR_FIELD, TEXTURED
66 };
67
72 enum Location {
73 VERTEX, FACE, EDGE, HALFEDGE
74 };
75
79 struct Material {
80 Material() = default;
81 Material(const vec4 &ambi, const vec4 &spec, float shin);
82
83 vec4 ambient;
84 //vec3 diffuse; // we have per face/point/line color!
85 vec4 specular;
86 float shininess; // specular power
87 };
88
89 public:
90 State();
91 State(const State& s);
93 State& operator=(const State& rhs);
94
95 virtual ~State() = default;
96
97 bool is_visible() const { return visible_; }
98 void set_visible(bool v) { visible_ = v; }
99
100 bool is_selected() const { return selected_; }
101 void set_selected(bool b) { selected_ = b; }
102
104
109 void set_uniform_coloring(const vec4 &color);
110
116 void set_property_coloring(Location color_location, const std::string &color_name = "");
117
126 void set_texture_coloring(Location texcoord_location, const std::string &texcoord_name,
127 const Texture *texture = nullptr, float repeat = 1.0f,
128 float repeat_fraction = 0.0f);
129
138 void set_scalar_coloring(Location scalar_location, const std::string &scalar_name,
139 const Texture *texture = nullptr, float clamp_lower = 0.05f,
140 float clamp_upper = 0.05f);
141
149 void set_coloring(Method method, Location location, const std::string &name);
150
157 void set_coloring_method(Method method) { coloring_method_ = method; }
158
160 Method coloring_method() const { return coloring_method_; }
161
166 const vec4 &color() const { return color_; }
167 void set_color(const vec4& c) { color_ = c; }
168
170 Location property_location() const { return property_location_; }
171
173 const std::string &property_name() const { return property_name_; }
174
176 bool lighting() const { return lighting_; }
178 void set_lighting(bool l) { lighting_ = l; }
179
181 bool lighting_two_sides() const { return lighting_two_sides_; }
183 void set_lighting_two_sides(bool b) { lighting_two_sides_ = b; }
184
187 bool distinct_back_color() const { return distinct_back_color_; }
190 void set_distinct_back_color(bool b) { distinct_back_color_ = b; }
191
195 const vec4 &back_color() const { return back_color_; }
199 void set_back_color(const vec4 &c) { back_color_ = c; }
200
202 const Texture *texture() const { return texture_; }
203 void set_texture(Texture *tex) { texture_ = tex; }
204
206 float texture_repeat() const { return texture_repeat_; };
207 void set_texture_repeat(float r) { texture_repeat_ = r; };
208
210 float texture_fractional_repeat() const { return texture_fractional_repeat_; };
211 void set_texture_fractional_repeat(float fr) { texture_fractional_repeat_ = fr; };
212
213 // \todo: reuse the texture() and set_texture()
214 bool is_ssao_enabled() const { return ssao_enabled_; }
215 void enable_ssao(bool b) { ssao_enabled_ = b; }
216 void set_ssao_texture(unsigned int tex) { ssao_texture_ = tex; }
217
219 bool clamp_range() const { return clamp_range_; }
220 void set_clamp_range(bool b) { clamp_range_ = b; }
221
223 float clamp_lower() const { return clamp_lower_; }
224 void set_clamp_lower(float v) { clamp_lower_ = v; }
225
227 float clamp_upper() const { return clamp_upper_; }
228 void set_clamp_upper(float v) { clamp_upper_ = v; }
229
230 Material &material() { return material_; }
231 const Material &material() const { return material_; }
232 void set_material(const Material &m) { material_ = m; }
233
242 bool plane_clip_discard_primitive() const { return plane_clip_discard_primitive_; };
243 void set_plane_clip_discard_primitive(bool b) { plane_clip_discard_primitive_ = b; };
244
255 bool highlight() const { return highlight_; };
256 void set_highlight(bool b) { highlight_ = b; }
257 void set_highlight_range(const std::pair<int, int> &range) { highlight_range_ = range; }
258 const std::pair<int, int> &highlight_range() const { return highlight_range_; }
259
260 protected:
261 bool visible_;
262 bool selected_;
263
264 Method coloring_method_;
265 vec4 color_; // valid when color method is UNIFORM_COLOR
266 Location property_location_;
267 std::string property_name_;
268
269 bool lighting_;
270
271 bool lighting_two_sides_;
272 bool distinct_back_color_;
273 vec4 back_color_;
274
275 // texture
276 const Texture *texture_;
277 // How many times do you want to repeat the texture?
278 float texture_repeat_;
279 // Control at a finer level: 100 fractional repeat == repeat.
280 float texture_fractional_repeat_;
281
282 bool ssao_enabled_;
283 unsigned int ssao_texture_;
284
285 bool clamp_range_;
286 float clamp_lower_;
287 float clamp_upper_;
288
289 Material material_;
290
291 // Clipping plane behavior.
292 // - true: completely discard a primitive if one of its vertices has a negative clip distance
293 // - false: linearly interpolated (standard plane clipping behavior)
294 bool plane_clip_discard_primitive_;
295
296 // highlight the primitives within the range [highlight_id_low_, highlight_id_high_]
297 bool highlight_;
298 std::pair<int, int> highlight_range_;
299 };
300
301}
302
303
304#endif // EASY3D_RENDERER_STATE_H
Class representing the rendering state of a drawable.
Definition: state.h:45
void set_lighting(bool l)
enables/disables lighting.
Definition: state.h:178
Location property_location() const
Definition: state.h:170
Method
Definition: state.h:64
void set_scalar_coloring(Location scalar_location, const std::string &scalar_name, const Texture *texture=nullptr, float clamp_lower=0.05f, float clamp_upper=0.05f)
Definition: state.cpp:115
Method coloring_method() const
Definition: state.h:160
float clamp_lower() const
Definition: state.h:223
State & operator=(const State &rhs)
assign rhs to *this. performs a deep copy of all member variables.
Definition: state.cpp:64
const vec4 & color() const
Definition: state.h:166
float clamp_upper() const
Definition: state.h:227
bool distinct_back_color() const
Definition: state.h:187
void set_uniform_coloring(const vec4 &color)
Definition: state.cpp:89
float texture_repeat() const
Definition: state.h:206
bool highlight() const
Definition: state.h:255
void set_texture_coloring(Location texcoord_location, const std::string &texcoord_name, const Texture *texture=nullptr, float repeat=1.0f, float repeat_fraction=0.0f)
Definition: state.cpp:104
float texture_fractional_repeat() const
Definition: state.h:210
const vec4 & back_color() const
Definition: state.h:195
void set_back_color(const vec4 &c)
Definition: state.h:199
const std::string & property_name() const
Definition: state.h:173
void set_coloring(Method method, Location location, const std::string &name)
Definition: state.cpp:128
bool lighting() const
returns whether lighting is enabled.
Definition: state.h:176
bool plane_clip_discard_primitive() const
Controls the behavior for vertex clipping.
Definition: state.h:242
void set_property_coloring(Location color_location, const std::string &color_name="")
Definition: state.cpp:97
const Texture * texture() const
Definition: state.h:202
bool lighting_two_sides() const
returns whether double-sided lighting is enabled.
Definition: state.h:181
bool clamp_range() const
Definition: state.h:219
void set_distinct_back_color(bool b)
Definition: state.h:190
void set_coloring_method(Method method)
Definition: state.h:157
Location
Definition: state.h:72
void set_lighting_two_sides(bool b)
enables/disables double-sided lighting.
Definition: state.h:183
OpenGL texture.
Definition: texture.h:44
Definition: collider.cpp:182
Vec< 4, float > vec4
A 4D point/vector of float type.
Definition: types.h:47
Definition: state.h:79