Skip to content

Commit

Permalink
[render] VCL_MRS point visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Feb 12, 2025
1 parent eea3e69 commit b254ebd
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 15 deletions.
50 changes: 46 additions & 4 deletions vclib/render/include/vclib/render/drawable/mesh/mesh_render_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,29 @@

#include "mesh_render_info_macros.h"

#include <vclib/types.h>

#include <array>

namespace vcl {

namespace detail {

template<typename Enum>
auto constexpr makeExclusiveReangesArray(auto... args) {
std::array<Enum, sizeof...(args)> array;

std::size_t i = 0;
((array[i++] = args), ...);

return array;
};

} // namespace detail

struct MeshRenderInfo {
enum class Points {
DRAW = 0,
VISIBLE = 0,
SHAPE_PIXEL,
SHAPE_CIRCLE,
SHADING_NONE,
Expand All @@ -41,8 +59,13 @@ struct MeshRenderInfo {
COUNT
};

constexpr static auto pointsExclusiveRange(auto value)
{
return getExclusiveRange(value, POINTS_EXCLUSIVE_RANGES);
}

enum class Surface {
DRAW = 0,
VISIBLE = 0,
SHADING_NONE,
SHADING_FLAT,
SHADING_SMOOTH,
Expand All @@ -57,7 +80,7 @@ struct MeshRenderInfo {
};

enum class Wireframe {
DRAW = 0,
VISIBLE = 0,
SHADING_NONE,
SHADING_VERT,
COLOR_VERTEX,
Expand All @@ -68,7 +91,7 @@ struct MeshRenderInfo {
};

enum class Edges {
DRAW = 0,
VISIBLE = 0,
SHADING_NONE,
SHADING_FLAT,
SHADING_SMOOTH,
Expand All @@ -79,6 +102,25 @@ struct MeshRenderInfo {

COUNT
};

private:
inline static constexpr auto const POINTS_EXCLUSIVE_RANGES =
detail::makeExclusiveReangesArray<Points>(
Points::SHAPE_PIXEL, Points::SHAPE_CIRCLE,
Points::SHADING_NONE, Points::SHADING_VERT,
Points::COLOR_VERTEX, Points::COLOR_USER);

constexpr static auto getExclusiveRange(auto value, const auto& array)
{
for (uint i = 0; i < array.size(); i+=2) {
if (toUnderlying(value) >= toUnderlying(array[i]) &&
toUnderlying(value) <= toUnderlying(array[i+1])) {
return std::pair(
toUnderlying(array[i]), toUnderlying(array[i + 1]));
}
}
return std::pair(toUnderlying(value), toUnderlying(value));
}
};

} // namespace vcl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/* uint mDrawMode0 */

// points
#define VCL_MRS_DRAW_POINTS uint(1 << 1) // point visibility
//#define VCL_MRS_DRAW_POINTS uint(1 << 1) // point visibility
#define VCL_MRS_POINTS_PIXEL uint(1 << 2) // draw points as pixels
#define VCL_MRS_POINTS_CIRCLE uint(1 << 3) // draw points as circles
#define VCL_MRS_POINTS_SHADING_NONE uint(1 << 4) // no shading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#ifndef VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_SETTINGS_H
#define VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_SETTINGS_H

#include "mesh_render_info_macros.h"
#include "mesh_render_info.h"

#include <vclib/mesh/requirements.h>
#include <vclib/space/core/bit_set.h>
Expand Down Expand Up @@ -108,9 +108,14 @@ class MeshRenderSettings
return mCapability.visible;
}

bool canPoint(MeshRenderInfo::Points p) const
{
return pointsCapability(p);
}

bool canPointBeVisible() const
{
return mDrawModeCapability0 & VCL_MRS_DRAW_POINTS;
return canPoint(MeshRenderInfo::Points::VISIBLE);
}

bool canPointShadingBePerVertex() const
Expand Down Expand Up @@ -230,7 +235,15 @@ class MeshRenderSettings

bool isVisible() const { return mDrawMode.visible; }

bool isPointVisible() const { return mDrawMode0 & VCL_MRS_DRAW_POINTS; }
bool isPoint(MeshRenderInfo::Points p) const
{
return pointsDrawMode(p);
}

bool isPointVisible() const
{
return pointsDrawMode(MeshRenderInfo::Points::VISIBLE);
}

bool isPointShadingNone() const
{
Expand Down Expand Up @@ -399,6 +412,8 @@ class MeshRenderSettings

bool setVisibility(bool b);

bool setPoint(MeshRenderInfo::Points p, bool b);

bool setPointVisibility(bool b);

bool setPointShadingNone();
Expand Down Expand Up @@ -492,7 +507,7 @@ class MeshRenderSettings
mCapability.visible = true;

// -- Points --
mDrawModeCapability0 |= VCL_MRS_DRAW_POINTS;
setPointsCapability(MeshRenderInfo::Points::VISIBLE);
mDrawModeCapability0 |= VCL_MRS_POINTS_SHADING_NONE;
mDrawModeCapability0 |= VCL_MRS_POINTS_PIXEL;
mDrawModeCapability0 |= VCL_MRS_POINTS_CIRCLE;
Expand Down Expand Up @@ -619,6 +634,31 @@ class MeshRenderSettings
}

void setDefaultSettingsFromCapability();

private:
bool pointsCapability(MeshRenderInfo::Points p) const
{
assert(p < MeshRenderInfo::Points::COUNT);
return mCapability.points[toUnderlying(p)];
}

bool pointsDrawMode(MeshRenderInfo::Points p) const
{
assert(p < MeshRenderInfo::Points::COUNT);
return mDrawMode.points[toUnderlying(p)];
}

void setPointsCapability(MeshRenderInfo::Points p, bool b = true)
{
assert(p < MeshRenderInfo::Points::COUNT);
mCapability.points[toUnderlying(p)] = b;
}

void setPointsDrawMode(MeshRenderInfo::Points p, bool b = true)
{
assert(p < MeshRenderInfo::Points::COUNT);
mDrawMode.points[toUnderlying(p)] = b;
}
};

} // namespace vcl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,30 @@ bool MeshRenderSettings::setVisibility(bool b)
}
}

bool MeshRenderSettings::setPointVisibility(bool b)
bool MeshRenderSettings::setPoint(MeshRenderInfo::Points p, bool b = true)
{
if (canPointBeVisible()) {
if (b)
mDrawMode0 |= VCL_MRS_DRAW_POINTS;
else
mDrawMode0 &= ~VCL_MRS_DRAW_POINTS;
if (canPoint(p)) {
auto rng = MeshRenderInfo::pointsExclusiveRange(p);
if (rng.first == rng.second) {
mDrawMode.points[rng.first] = b;
}
else {
for (auto i = rng.first; i < rng.second; ++i) {
mDrawMode.points[i] = toUnderlying(p) == i;
}
}
return true;
}
else {
return false;
}
}

bool MeshRenderSettings::setPointVisibility(bool b)
{
return setPoint(MeshRenderInfo::Points::VISIBLE, b);
}

bool MeshRenderSettings::setPointShadingNone()
{
if (canPointBeVisible()) {
Expand Down

0 comments on commit b254ebd

Please sign in to comment.