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/space/core/bit_set.h>
29#include <vclib/base.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 {
100 using BuffersBitSetUnderlyingType =
ushort;
103 sizeof(BuffersBitSetUnderlyingType) < (uint) Buffers::COUNT,
104 "BuffersBitSet is not able to store all enum Buffers values");
109 std::array<
BitSet16, toUnderlying(Primitive::COUNT)> mSettings;
115 static BuffersBitSet buffersAll()
123 static const inline BuffersBitSet BUFFERS_NONE = BuffersBitSet();
125 static const inline BuffersBitSet BUFFERS_ALL = buffersAll();
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,
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,
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,
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,
209 template<Primitive PRIMITIVE>
212 return mSettings[toUnderlying(
PRIMITIVE)];
220 template<Primitive PRIMITIVE>
223 return mSettings[toUnderlying(
PRIMITIVE)];
280 for (
auto& s : mSettings)
286 return mVisible ==
o.mVisible && mSettings ==
o.mSettings;
289 MeshRenderInfo& operator&=(
const MeshRenderInfo& o)
291 mVisible &= o.mVisible;
292 for (
const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
298 MeshRenderInfo& operator|=(
const MeshRenderInfo& o)
300 mVisible |= o.mVisible;
301 for (
const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
307 MeshRenderInfo& operator^=(
const MeshRenderInfo& o)
309 mVisible ^= o.mVisible;
310 for (
const auto& [s, os] : std::views::zip(mSettings, o.mSettings)) {
335 template<Primitive PRIMITIVE>
339 return getExclusiveRange(value, ranges);
427 inline static constexpr const auto POINTS_EXCLUSIVE_RANGES =
428 detail::makeExclusiveReangesArray<Points>(
430 Points::SHAPE_SPHERE,
431 Points::SHADING_NONE,
432 Points::SHADING_VERT,
433 Points::COLOR_VERTEX,
436 inline static constexpr const auto SURFACE_EXCLUSIVE_RANGES =
437 detail::makeExclusiveReangesArray<Surface>(
438 Surface::SHADING_NONE,
439 Surface::SHADING_SMOOTH,
440 Surface::COLOR_VERTEX,
441 Surface::COLOR_USER);
443 inline static constexpr const auto WIREFRAME_EXCLUSIVE_RANGES =
444 detail::makeExclusiveReangesArray<Wireframe>(
445 Wireframe::SHADING_NONE,
446 Wireframe::SHADING_VERT,
447 Wireframe::COLOR_VERTEX,
448 Wireframe::COLOR_USER);
450 inline static constexpr const auto EDGES_EXCLUSIVE_RANGES =
451 detail::makeExclusiveReangesArray<Edges>(
453 Edges::SHADING_SMOOTH,
457 template<Primitive PRIMITIVE>
458 inline static constexpr auto& exclusiveRanges()
460 if constexpr (
PRIMITIVE == Primitive::POINTS) {
461 return POINTS_EXCLUSIVE_RANGES;
463 else if constexpr (PRIMITIVE == Primitive::SURFACE) {
464 return SURFACE_EXCLUSIVE_RANGES;
466 else if constexpr (PRIMITIVE == Primitive::WIREFRAME) {
467 return WIREFRAME_EXCLUSIVE_RANGES;
469 else if constexpr (PRIMITIVE == Primitive::EDGES) {
470 return EDGES_EXCLUSIVE_RANGES;
473 static_assert(PRIMITIVE,
"Unknown Primitive");
477 constexpr static auto getExclusiveRange(
auto value,
const auto& array)
479 for (uint i = 0; i < array.size(); i += 2) {
480 if (toUnderlying(value) >= toUnderlying(array[i]) &&
481 toUnderlying(value) <= toUnderlying(array[i + 1])) {
483 toUnderlying(array[i]), toUnderlying(array[i + 1]));
486 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: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