Visual Computing Library  devel
Loading...
Searching...
No Matches
mesh_render_info.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_INFO_H
24#define VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_INFO_H
25
26#include "mesh_render_info_macros.h"
27
28#include <vclib/space/core/bit_set.h>
29#include <vclib/base.h>
30
31#include <array>
32
33namespace vcl {
34
35namespace detail {
36
37template<typename Enum>
38auto constexpr makeExclusiveReangesArray(auto... args)
39{
40 std::array<Enum, sizeof...(args)> array;
41
42 std::size_t i = 0;
43 ((array[i++] = args), ...);
44
45 return array;
46};
47
48} // namespace detail
49
61{
62public:
63 enum class Buffers : uint {
64 VERTICES,
65 VERT_NORMALS,
66 VERT_COLORS,
67 VERT_TEXCOORDS,
68
69 TRIANGLES,
70 TRI_NORMALS,
71 TRI_COLORS,
72 WEDGE_TEXCOORDS,
73
74 WIREFRAME,
75
76 EDGES,
77 EDGE_COLORS,
78 EDGE_NORMALS,
79
80 TEXTURES,
81
82 MESH_UNIFORMS,
83
84 COUNT,
85 };
86
90 enum class Primitive {
91 POINTS = 0,
92 SURFACE,
93 WIREFRAME,
94 EDGES,
95
96 COUNT
97 };
98
99private:
100 using BuffersBitSetUnderlyingType = ushort;
101
102 static_assert(
103 sizeof(BuffersBitSetUnderlyingType) < (uint) Buffers::COUNT,
104 "BuffersBitSet is not able to store all enum Buffers values");
105
106 bool mVisible;
107
108 // settings for each primitive
109 std::array<BitSet16, toUnderlying(Primitive::COUNT)> mSettings;
110
111public:
112 using BuffersBitSet = vcl::BitSet<BuffersBitSetUnderlyingType>;
113
114private:
115 static BuffersBitSet buffersAll()
116 {
117 BuffersBitSet all;
118 all.set();
119 return all;
120 }
121
122public:
123 static const inline BuffersBitSet BUFFERS_NONE = BuffersBitSet();
124
125 static const inline BuffersBitSet BUFFERS_ALL = buffersAll();
126
130 enum class Points {
131 VISIBLE = VCL_MRS_DRAW_POINTS,
132 SHAPE_PIXEL = VCL_MRS_POINTS_PIXEL,
133 SHAPE_CIRCLE = VCL_MRS_POINTS_CIRCLE,
134 SHAPE_SPHERE = VCL_MRS_POINTS_SPHERE,
135 SHADING_NONE = VCL_MRS_POINTS_SHADING_NONE,
136 SHADING_VERT = VCL_MRS_POINTS_SHADING_VERT,
137 COLOR_VERTEX = VCL_MRS_POINTS_COLOR_VERTEX,
138 COLOR_MESH = VCL_MRS_POINTS_COLOR_MESH,
139 COLOR_USER = VCL_MRS_POINTS_COLOR_USER,
140
141 COUNT
142 };
143
147 enum class Surface {
148 VISIBLE = VCL_MRS_DRAW_SURF,
149 SHADING_NONE = VCL_MRS_SURF_SHADING_NONE,
150 SHADING_FLAT = VCL_MRS_SURF_SHADING_FLAT,
151 SHADING_SMOOTH = VCL_MRS_SURF_SHADING_SMOOTH,
152 COLOR_VERTEX = VCL_MRS_SURF_COLOR_VERTEX,
153 COLOR_FACE = VCL_MRS_SURF_COLOR_FACE,
154 COLOR_VERTEX_TEX = VCL_MRS_SURF_TEX_VERTEX,
155 COLOR_WEDGE_TEX = VCL_MRS_SURF_TEX_WEDGE,
156 COLOR_MESH = VCL_MRS_SURF_COLOR_MESH,
157 COLOR_USER = VCL_MRS_SURF_COLOR_USER,
158
159 COUNT
160 };
161
165 enum class Wireframe {
166 VISIBLE = VCL_MRS_DRAW_WIREFRAME,
167 SHADING_NONE = VCL_MRS_WIREFRAME_SHADING_NONE,
168 SHADING_VERT = VCL_MRS_WIREFRAME_SHADING_VERT,
169 COLOR_VERTEX = VCL_MRS_WIREFRAME_COLOR_VERT,
170 COLOR_MESH = VCL_MRS_WIREFRAME_COLOR_MESH,
171 COLOR_USER = VCL_MRS_WIREFRAME_COLOR_USER,
172
173 COUNT
174 };
175
179 enum class Edges {
180 VISIBLE = VCL_MRS_DRAW_EDGES,
181 SHADING_NONE = VCL_MRS_EDGES_SHADING_NONE,
182 SHADING_FLAT = VCL_MRS_EDGES_SHADING_FLAT,
183 SHADING_SMOOTH = VCL_MRS_EDGES_SHADING_SMOOTH,
184 COLOR_VERTEX = VCL_MRS_EDGES_COLOR_VERTEX,
185 COLOR_EDGE = VCL_MRS_EDGES_COLOR_EDGE,
186 COLOR_MESH = VCL_MRS_EDGES_COLOR_MESH,
187 COLOR_USER = VCL_MRS_EDGES_COLOR_USER,
188
189 COUNT
190 };
191
196 bool visible() const { return mVisible; }
197
202 bool& visible() { return mVisible; }
203
209 template<Primitive PRIMITIVE>
211 {
212 return mSettings[toUnderlying(PRIMITIVE)];
213 }
214
220 template<Primitive PRIMITIVE>
222 {
223 return mSettings[toUnderlying(PRIMITIVE)];
224 }
225
231
237
243
249
255
261
267
273
277 void reset()
278 {
279 mVisible = false;
280 for (auto& s : mSettings)
281 s.reset();
282 }
283
284 bool operator==(const MeshRenderInfo& o) const
285 {
286 return mVisible == o.mVisible && mSettings == o.mSettings;
287 }
288
289 MeshRenderInfo& operator&=(const MeshRenderInfo& o)
290 {
291 mVisible &= o.mVisible;
292 for (const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
293 s &= os;
294 }
295 return *this;
296 }
297
298 MeshRenderInfo& operator|=(const MeshRenderInfo& o)
299 {
300 mVisible |= o.mVisible;
301 for (const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
302 s |= os;
303 }
304 return *this;
305 }
306
307 MeshRenderInfo& operator^=(const MeshRenderInfo& o)
308 {
309 mVisible ^= o.mVisible;
310 for (const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
311 s ^= os;
312 }
313 return *this;
314 }
315
335 template<Primitive PRIMITIVE>
336 constexpr static auto exclusiveRange(auto value)
337 {
338 const auto& ranges = exclusiveRanges<PRIMITIVE>();
339 return getExclusiveRange(value, ranges);
340 }
341
358 constexpr static auto pointsExclusiveRange(auto value)
359 {
361 }
362
379 constexpr static auto surfaceExclusiveRange(auto value)
380 {
382 }
383
400 constexpr static auto wireframeExclusiveRange(auto value)
401 {
403 }
404
421 constexpr static auto edgesExclusiveRange(auto value)
422 {
424 }
425
426private:
427 inline static constexpr const auto POINTS_EXCLUSIVE_RANGES =
428 detail::makeExclusiveReangesArray<Points>(
429 Points::SHAPE_PIXEL, // first
430 Points::SHAPE_SPHERE, // last
431 Points::SHADING_NONE, // first
432 Points::SHADING_VERT, // last
433 Points::COLOR_VERTEX, // first
434 Points::COLOR_USER); // last
435
436 inline static constexpr const auto SURFACE_EXCLUSIVE_RANGES =
437 detail::makeExclusiveReangesArray<Surface>(
438 Surface::SHADING_NONE, // first
439 Surface::SHADING_SMOOTH, // last
440 Surface::COLOR_VERTEX, // first
441 Surface::COLOR_USER); // last
442
443 inline static constexpr const auto WIREFRAME_EXCLUSIVE_RANGES =
444 detail::makeExclusiveReangesArray<Wireframe>(
445 Wireframe::SHADING_NONE, // first
446 Wireframe::SHADING_VERT, // last
447 Wireframe::COLOR_VERTEX, // first
448 Wireframe::COLOR_USER); // last
449
450 inline static constexpr const auto EDGES_EXCLUSIVE_RANGES =
451 detail::makeExclusiveReangesArray<Edges>(
452 Edges::SHADING_NONE, // first
453 Edges::SHADING_SMOOTH, // last
454 Edges::COLOR_VERTEX, // first
455 Edges::COLOR_USER); // last
456
457 template<Primitive PRIMITIVE>
458 inline static constexpr auto& exclusiveRanges()
459 {
460 if constexpr (PRIMITIVE == Primitive::POINTS) {
461 return POINTS_EXCLUSIVE_RANGES;
462 }
463 else if constexpr (PRIMITIVE == Primitive::SURFACE) {
464 return SURFACE_EXCLUSIVE_RANGES;
465 }
466 else if constexpr (PRIMITIVE == Primitive::WIREFRAME) {
467 return WIREFRAME_EXCLUSIVE_RANGES;
468 }
469 else if constexpr (PRIMITIVE == Primitive::EDGES) {
470 return EDGES_EXCLUSIVE_RANGES;
471 }
472 else {
473 static_assert(PRIMITIVE, "Unknown Primitive");
474 }
475 }
476
477 constexpr static auto getExclusiveRange(auto value, const auto& array)
478 {
479 for (uint i = 0; i < array.size(); i += 2) {
480 if (toUnderlying(value) >= toUnderlying(array[i]) &&
481 toUnderlying(value) <= toUnderlying(array[i + 1])) {
482 return std::pair(
483 toUnderlying(array[i]), toUnderlying(array[i + 1]));
484 }
485 }
486 return std::pair(toUnderlying(value), toUnderlying(value));
487 }
488};
489
490} // namespace vcl
491
492#endif // VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_INFO_H
A class representing a box in N-dimensional space.
Definition box.h:46
The MeshRenderInfo class is a collection of rendering settings for a Mesh.
Definition mesh_render_info.h:61
bool & visible()
Sets the visibility status of the mesh.
Definition mesh_render_info.h:202
Primitive
List of primitives for which settings can be stored.
Definition mesh_render_info.h:90
Wireframe
List of possible settings for the wireframe primitive.
Definition mesh_render_info.h:165
BitSet16 edges() const
Returns the settings for the edges primitive.
Definition mesh_render_info.h:266
BitSet16 & wireframe()
Returns the settings for the wireframe primitive.
Definition mesh_render_info.h:260
BitSet16 surface() const
Returns the settings for the surface primitive.
Definition mesh_render_info.h:242
BitSet16 settings() const
Returns the settings for a given primitive.
Definition mesh_render_info.h:210
BitSet16 points() const
Returns the settings for the points primitive.
Definition mesh_render_info.h:230
static constexpr auto surfaceExclusiveRange(auto value)
Returns pair representing the range in the Surface enumeration of the mutual exclusive settings for t...
Definition mesh_render_info.h:379
Surface
List of possible settings for the surface primitive.
Definition mesh_render_info.h:147
bool visible() const
Returns the visibility status of the mesh.
Definition mesh_render_info.h:196
BitSet16 & edges()
Returns the settings for the edges primitive.
Definition mesh_render_info.h:272
static constexpr auto edgesExclusiveRange(auto value)
Returns pair representing the range in the Edges enumeration of the mutual exclusive settings for the...
Definition mesh_render_info.h:421
BitSet16 & points()
Returns the settings for the points primitive.
Definition mesh_render_info.h:236
BitSet16 wireframe() const
Returns the settings for the wireframe primitive.
Definition mesh_render_info.h:254
static constexpr auto pointsExclusiveRange(auto value)
Returns pair representing the range in the Points enumeration of the mutual exclusive settings for th...
Definition mesh_render_info.h:358
BitSet16 & surface()
Returns the settings for the surface primitive.
Definition mesh_render_info.h:248
BitSet16 & settings()
Returns the settings for a given primitive.
Definition mesh_render_info.h:221
void reset()
Resets all the settings of the mesh.
Definition mesh_render_info.h:277
Edges
List of possible settings for the edges primitive.
Definition mesh_render_info.h:179
static constexpr auto wireframeExclusiveRange(auto value)
Returns pair representing the range in the Wireframe enumeration of the mutual exclusive settings for...
Definition mesh_render_info.h:400
static constexpr auto exclusiveRange(auto value)
Given a primitive and a setting, returns pair representing the range in the primitive enumeration of ...
Definition mesh_render_info.h:336
Points
List of possible settings for the points primitive.
Definition mesh_render_info.h:130
BitSet< short > BitSet16
BitSet16 is a BitSet of 16 bits.
Definition bit_set.h:397