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/base.h>
29#include <vclib/space/core/bit_set.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 VERT_TANGENT,
69
70 TRIANGLES,
71 TRI_NORMALS,
72 TRI_COLORS,
73 WEDGE_TEXCOORDS,
74
75 WIREFRAME,
76
77 EDGES,
78 EDGE_COLORS,
79 EDGE_NORMALS,
80
81 TEXTURES,
82
83 MESH_UNIFORMS,
84
85 COUNT,
86 };
87
91 enum class Primitive {
92 POINTS = 0,
93 SURFACE,
94 WIREFRAME,
95 EDGES,
96
97 COUNT
98 };
99
100private:
101 using BuffersBitSetUnderlyingType = ushort;
102
103 static_assert(
104 sizeof(BuffersBitSetUnderlyingType) < (uint) Buffers::COUNT,
105 "BuffersBitSet is not able to store all enum Buffers values");
106
107 bool mVisible;
108
109 // settings for each primitive
110 std::array<BitSet16, toUnderlying(Primitive::COUNT)> mSettings;
111
112public:
113 using BuffersBitSet = vcl::BitSet<BuffersBitSetUnderlyingType>;
114
115private:
116 static BuffersBitSet buffersAll()
117 {
118 BuffersBitSet all;
119 all.set();
120 return all;
121 }
122
123public:
124 static const inline BuffersBitSet BUFFERS_NONE = BuffersBitSet();
125
126 static const inline BuffersBitSet BUFFERS_ALL = buffersAll();
127
131 enum class Points {
132 VISIBLE = VCL_MRS_DRAW_POINTS,
133 SHAPE_PIXEL = VCL_MRS_POINTS_PIXEL,
134 SHAPE_CIRCLE = VCL_MRS_POINTS_CIRCLE,
135 SHAPE_SPHERE = VCL_MRS_POINTS_SPHERE,
136 SHADING_NONE = VCL_MRS_POINTS_SHADING_NONE,
137 SHADING_VERT = VCL_MRS_POINTS_SHADING_VERT,
138 COLOR_VERTEX = VCL_MRS_POINTS_COLOR_VERTEX,
139 COLOR_MESH = VCL_MRS_POINTS_COLOR_MESH,
140 COLOR_USER = VCL_MRS_POINTS_COLOR_USER,
141
142 COUNT
143 };
144
148 enum class Surface {
149 VISIBLE = VCL_MRS_DRAW_SURF,
150 SHADING_NONE = VCL_MRS_SURF_SHADING_NONE,
151 SHADING_FLAT = VCL_MRS_SURF_SHADING_FLAT,
152 SHADING_SMOOTH = VCL_MRS_SURF_SHADING_SMOOTH,
153 COLOR_VERTEX = VCL_MRS_SURF_COLOR_VERTEX,
154 COLOR_FACE = VCL_MRS_SURF_COLOR_FACE,
155 COLOR_VERTEX_TEX = VCL_MRS_SURF_TEX_VERTEX,
156 COLOR_WEDGE_TEX = VCL_MRS_SURF_TEX_WEDGE,
157 COLOR_MESH = VCL_MRS_SURF_COLOR_MESH,
158 COLOR_USER = VCL_MRS_SURF_COLOR_USER,
159
160 COUNT
161 };
162
166 enum class Wireframe {
167 VISIBLE = VCL_MRS_DRAW_WIREFRAME,
168 SHADING_NONE = VCL_MRS_WIREFRAME_SHADING_NONE,
169 SHADING_VERT = VCL_MRS_WIREFRAME_SHADING_VERT,
170 COLOR_VERTEX = VCL_MRS_WIREFRAME_COLOR_VERT,
171 COLOR_MESH = VCL_MRS_WIREFRAME_COLOR_MESH,
172 COLOR_USER = VCL_MRS_WIREFRAME_COLOR_USER,
173
174 COUNT
175 };
176
180 enum class Edges {
181 VISIBLE = VCL_MRS_DRAW_EDGES,
182 SHADING_NONE = VCL_MRS_EDGES_SHADING_NONE,
183 SHADING_FLAT = VCL_MRS_EDGES_SHADING_FLAT,
184 SHADING_SMOOTH = VCL_MRS_EDGES_SHADING_SMOOTH,
185 COLOR_VERTEX = VCL_MRS_EDGES_COLOR_VERTEX,
186 COLOR_EDGE = VCL_MRS_EDGES_COLOR_EDGE,
187 COLOR_MESH = VCL_MRS_EDGES_COLOR_MESH,
188 COLOR_USER = VCL_MRS_EDGES_COLOR_USER,
189
190 COUNT
191 };
192
197 bool visible() const { return mVisible; }
198
203 bool& visible() { return mVisible; }
204
210 template<Primitive PRIMITIVE>
212 {
213 return mSettings[toUnderlying(PRIMITIVE)];
214 }
215
221 template<Primitive PRIMITIVE>
223 {
224 return mSettings[toUnderlying(PRIMITIVE)];
225 }
226
232
238
244
250
256
262
268
274
278 void reset()
279 {
280 mVisible = false;
281 for (auto& s : mSettings)
282 s.reset();
283 }
284
285 bool operator==(const MeshRenderInfo& o) const
286 {
287 return mVisible == o.mVisible && mSettings == o.mSettings;
288 }
289
290 MeshRenderInfo& operator&=(const MeshRenderInfo& o)
291 {
292 mVisible &= o.mVisible;
293 for (const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
294 s &= os;
295 }
296 return *this;
297 }
298
299 MeshRenderInfo& operator|=(const MeshRenderInfo& o)
300 {
301 mVisible |= o.mVisible;
302 for (const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
303 s |= os;
304 }
305 return *this;
306 }
307
308 MeshRenderInfo& operator^=(const MeshRenderInfo& o)
309 {
310 mVisible ^= o.mVisible;
311 for (const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
312 s ^= os;
313 }
314 return *this;
315 }
316
336 template<Primitive PRIMITIVE>
337 constexpr static auto exclusiveRange(auto value)
338 {
339 const auto& ranges = exclusiveRanges<PRIMITIVE>();
340 return getExclusiveRange(value, ranges);
341 }
342
359 constexpr static auto pointsExclusiveRange(auto value)
360 {
362 }
363
380 constexpr static auto surfaceExclusiveRange(auto value)
381 {
383 }
384
401 constexpr static auto wireframeExclusiveRange(auto value)
402 {
404 }
405
422 constexpr static auto edgesExclusiveRange(auto value)
423 {
425 }
426
427private:
428 inline static constexpr const auto POINTS_EXCLUSIVE_RANGES =
429 detail::makeExclusiveReangesArray<Points>(
430 Points::SHAPE_PIXEL, // first
431 Points::SHAPE_SPHERE, // last
432 Points::SHADING_NONE, // first
433 Points::SHADING_VERT, // last
434 Points::COLOR_VERTEX, // first
435 Points::COLOR_USER); // last
436
437 inline static constexpr const auto SURFACE_EXCLUSIVE_RANGES =
438 detail::makeExclusiveReangesArray<Surface>(
439 Surface::SHADING_NONE, // first
440 Surface::SHADING_SMOOTH, // last
441 Surface::COLOR_VERTEX, // first
442 Surface::COLOR_USER); // last
443
444 inline static constexpr const auto WIREFRAME_EXCLUSIVE_RANGES =
445 detail::makeExclusiveReangesArray<Wireframe>(
446 Wireframe::SHADING_NONE, // first
447 Wireframe::SHADING_VERT, // last
448 Wireframe::COLOR_VERTEX, // first
449 Wireframe::COLOR_USER); // last
450
451 inline static constexpr const auto EDGES_EXCLUSIVE_RANGES =
452 detail::makeExclusiveReangesArray<Edges>(
453 Edges::SHADING_NONE, // first
454 Edges::SHADING_SMOOTH, // last
455 Edges::COLOR_VERTEX, // first
456 Edges::COLOR_USER); // last
457
458 template<Primitive PRIMITIVE>
459 inline static constexpr auto& exclusiveRanges()
460 {
461 if constexpr (PRIMITIVE == Primitive::POINTS) {
462 return POINTS_EXCLUSIVE_RANGES;
463 }
464 else if constexpr (PRIMITIVE == Primitive::SURFACE) {
465 return SURFACE_EXCLUSIVE_RANGES;
466 }
467 else if constexpr (PRIMITIVE == Primitive::WIREFRAME) {
468 return WIREFRAME_EXCLUSIVE_RANGES;
469 }
470 else if constexpr (PRIMITIVE == Primitive::EDGES) {
471 return EDGES_EXCLUSIVE_RANGES;
472 }
473 else {
474 static_assert(PRIMITIVE, "Unknown Primitive");
475 }
476 }
477
478 constexpr static auto getExclusiveRange(auto value, const auto& array)
479 {
480 for (uint i = 0; i < array.size(); i += 2) {
481 if (toUnderlying(value) >= toUnderlying(array[i]) &&
482 toUnderlying(value) <= toUnderlying(array[i + 1])) {
483 return std::pair(
484 toUnderlying(array[i]), toUnderlying(array[i + 1]));
485 }
486 }
487 return std::pair(toUnderlying(value), toUnderlying(value));
488 }
489};
490
491} // namespace vcl
492
493#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:203
Primitive
List of primitives for which settings can be stored.
Definition mesh_render_info.h:91
Wireframe
List of possible settings for the wireframe primitive.
Definition mesh_render_info.h:166
BitSet16 edges() const
Returns the settings for the edges primitive.
Definition mesh_render_info.h:267
BitSet16 & wireframe()
Returns the settings for the wireframe primitive.
Definition mesh_render_info.h:261
BitSet16 surface() const
Returns the settings for the surface primitive.
Definition mesh_render_info.h:243
BitSet16 settings() const
Returns the settings for a given primitive.
Definition mesh_render_info.h:211
BitSet16 points() const
Returns the settings for the points primitive.
Definition mesh_render_info.h:231
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:380
Surface
List of possible settings for the surface primitive.
Definition mesh_render_info.h:148
bool visible() const
Returns the visibility status of the mesh.
Definition mesh_render_info.h:197
BitSet16 & edges()
Returns the settings for the edges primitive.
Definition mesh_render_info.h:273
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:422
BitSet16 & points()
Returns the settings for the points primitive.
Definition mesh_render_info.h:237
BitSet16 wireframe() const
Returns the settings for the wireframe primitive.
Definition mesh_render_info.h:255
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:359
BitSet16 & surface()
Returns the settings for the surface primitive.
Definition mesh_render_info.h:249
BitSet16 & settings()
Returns the settings for a given primitive.
Definition mesh_render_info.h:222
void reset()
Resets all the settings of the mesh.
Definition mesh_render_info.h:278
Edges
List of possible settings for the edges primitive.
Definition mesh_render_info.h:180
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:401
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:337
Points
List of possible settings for the points primitive.
Definition mesh_render_info.h:131
BitSet< short > BitSet16
BitSet16 is a BitSet of 16 bits.
Definition bit_set.h:408