23#ifndef VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_INFO_H
24#define VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_INFO_H
26#include "mesh_render_info_macros.h"
28#include <vclib/base.h>
29#include <vclib/space/core/bit_set.h>
37template<
typename Enum>
38auto constexpr makeExclusiveReangesArray(
auto... args)
40 std::array<Enum,
sizeof...(args)> array;
43 ((array[i++] = args), ...);
63 enum class Buffers :
uint {
101 using BuffersBitSetUnderlyingType =
ushort;
104 sizeof(BuffersBitSetUnderlyingType) < (uint) Buffers::COUNT,
105 "BuffersBitSet is not able to store all enum Buffers values");
110 std::array<
BitSet16, toUnderlying(Primitive::COUNT)> mSettings;
116 static BuffersBitSet buffersAll()
124 static const inline BuffersBitSet BUFFERS_NONE = BuffersBitSet();
126 static const inline BuffersBitSet BUFFERS_ALL = buffersAll();
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,
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,
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,
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,
210 template<Primitive PRIMITIVE>
213 return mSettings[toUnderlying(PRIMITIVE)];
221 template<Primitive PRIMITIVE>
224 return mSettings[toUnderlying(PRIMITIVE)];
281 for (
auto& s : mSettings)
287 return mVisible ==
o.mVisible && mSettings ==
o.mSettings;
290 MeshRenderInfo& operator&=(
const MeshRenderInfo& o)
292 mVisible &= o.mVisible;
293 for (
const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
299 MeshRenderInfo& operator|=(
const MeshRenderInfo& o)
301 mVisible |= o.mVisible;
302 for (
const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
308 MeshRenderInfo& operator^=(
const MeshRenderInfo& o)
310 mVisible ^= o.mVisible;
311 for (
const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
336 template<Primitive PRIMITIVE>
340 return getExclusiveRange(value, ranges);
428 inline static constexpr const auto POINTS_EXCLUSIVE_RANGES =
429 detail::makeExclusiveReangesArray<Points>(
431 Points::SHAPE_SPHERE,
432 Points::SHADING_NONE,
433 Points::SHADING_VERT,
434 Points::COLOR_VERTEX,
437 inline static constexpr const auto SURFACE_EXCLUSIVE_RANGES =
438 detail::makeExclusiveReangesArray<Surface>(
439 Surface::SHADING_NONE,
440 Surface::SHADING_SMOOTH,
441 Surface::COLOR_VERTEX,
442 Surface::COLOR_USER);
444 inline static constexpr const auto WIREFRAME_EXCLUSIVE_RANGES =
445 detail::makeExclusiveReangesArray<Wireframe>(
446 Wireframe::SHADING_NONE,
447 Wireframe::SHADING_VERT,
448 Wireframe::COLOR_VERTEX,
449 Wireframe::COLOR_USER);
451 inline static constexpr const auto EDGES_EXCLUSIVE_RANGES =
452 detail::makeExclusiveReangesArray<Edges>(
454 Edges::SHADING_SMOOTH,
458 template<Primitive PRIMITIVE>
459 inline static constexpr auto& exclusiveRanges()
461 if constexpr (PRIMITIVE == Primitive::POINTS) {
462 return POINTS_EXCLUSIVE_RANGES;
464 else if constexpr (PRIMITIVE == Primitive::SURFACE) {
465 return SURFACE_EXCLUSIVE_RANGES;
467 else if constexpr (PRIMITIVE == Primitive::WIREFRAME) {
468 return WIREFRAME_EXCLUSIVE_RANGES;
470 else if constexpr (PRIMITIVE == Primitive::EDGES) {
471 return EDGES_EXCLUSIVE_RANGES;
474 static_assert(PRIMITIVE,
"Unknown Primitive");
478 constexpr static auto getExclusiveRange(
auto value,
const auto& array)
480 for (uint i = 0; i < array.size(); i += 2) {
481 if (toUnderlying(value) >= toUnderlying(array[i]) &&
482 toUnderlying(value) <= toUnderlying(array[i + 1])) {
484 toUnderlying(array[i]), toUnderlying(array[i + 1]));
487 return std::pair(toUnderlying(value), toUnderlying(value));
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