Skip to content

Commit

Permalink
[render] MeshRenderSettings migration to new implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Feb 13, 2025
1 parent 48f731f commit 8e499da
Show file tree
Hide file tree
Showing 10 changed files with 566 additions and 864 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ class MeshRenderSettingsUniforms

void updateSettings(const vcl::MeshRenderSettings& settings)
{
auto [d0, d1] = settings.drawMode();
// TODO
mDrawPack[0] = Uniform::uintBitsToFloat(settings.drawMode0());
mDrawPack[1] = Uniform::uintBitsToFloat(settings.drawMode1());
auto mri = settings.drawMode();
uint d0 = mri.points.underlying();
d0 |= mri.surface.underlying() << 16;
uint d1 = mri.wireframe.underlying();
d1 |= mri.edges.underlying() << 16;

mDrawPack[0] = Uniform::uintBitsToFloat(d0);
mDrawPack[1] = Uniform::uintBitsToFloat(d1);

mWidthPack[0] = settings.pointWidth();
mWidthPack[1] = settings.wireframeWidth();
Expand Down
6 changes: 0 additions & 6 deletions vclib/render/include/vclib/opengl2/drawable/drawable_mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,6 @@ class DrawableMeshOpenGL2 : public AbstractDrawableMesh, public MeshType
}
}
}
if (mMRS.isBboxEnabled()) {
drawBox3(
mBoundingBox.min(),
mBoundingBox.max(),
vcl::Color(0, 0, 0));
}
}
}

Expand Down
191 changes: 134 additions & 57 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,6 +25,7 @@

#include "mesh_render_info_macros.h"

#include <vclib/space/core/bit_set.h>
#include <vclib/types.h>

#include <array>
Expand All @@ -34,7 +35,8 @@ namespace vcl {
namespace detail {

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

std::size_t i = 0;
Expand All @@ -45,7 +47,19 @@ auto constexpr makeExclusiveReangesArray(auto... args) {

} // namespace detail

struct MeshRenderInfo {
/**
* @brief The MeshRenderInfo class is a collection of rendering settings for a
* Mesh.
*
* It provides a set of enums that can be used for various rendering purposes
* (like rendering settings, render buffer lists, ...).
*
* It also allows to store settings that can be used for draw capability
* or draw mode of a mesh.
*/
class MeshRenderInfo
{
public:
enum class Points {
VISIBLE = VCL_MRS_DRAW_POINTS,
SHAPE_PIXEL = VCL_MRS_POINTS_PIXEL,
Expand All @@ -59,92 +73,155 @@ struct MeshRenderInfo {
COUNT
};

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

enum class Surface {
VISIBLE = 0,
SHADING_NONE,
SHADING_FLAT,
SHADING_SMOOTH,
COLOR_FACE,
COLOR_VERTEX,
COLOR_MESH,
COLOR_USER,
COLOR_VERTEX_TEX,
COLOR_WEDGE_TEX,
VISIBLE = VCL_MRS_DRAW_SURF,
SHADING_NONE = VCL_MRS_SURF_SHADING_NONE,
SHADING_FLAT = VCL_MRS_SURF_SHADING_FLAT,
SHADING_SMOOTH = VCL_MRS_SURF_SHADING_SMOOTH,
COLOR_VERTEX = VCL_MRS_SURF_COLOR_VERTEX,
COLOR_FACE = VCL_MRS_SURF_COLOR_FACE,
COLOR_VERTEX_TEX = VCL_MRS_SURF_TEX_VERTEX,
COLOR_WEDGE_TEX = VCL_MRS_SURF_TEX_WEDGE,
COLOR_MESH = VCL_MRS_SURF_COLOR_MESH,
COLOR_USER = VCL_MRS_SURF_COLOR_USER,

COUNT
};

constexpr static auto surfaceExclusiveRange(auto value)
{
return getExclusiveRange(value, SURFACE_EXCLUSIVE_RANGES);
}

enum class Wireframe {
VISIBLE = 0,
SHADING_NONE,
SHADING_VERT,
COLOR_VERTEX,
COLOR_MESH,
COLOR_USER,
VISIBLE = VCL_MRS_DRAW_WIREFRAME,
SHADING_NONE = VCL_MRS_WIREFRAME_SHADING_NONE,
SHADING_VERT = VCL_MRS_WIREFRAME_SHADING_VERT,
COLOR_VERTEX = VCL_MRS_WIREFRAME_COLOR_VERT,
COLOR_MESH = VCL_MRS_WIREFRAME_COLOR_MESH,
COLOR_USER = VCL_MRS_WIREFRAME_COLOR_USER,

COUNT
};

constexpr static auto wireframeExclusiveRange(auto value)
{
return getExclusiveRange(value, WIREFRAME_EXCLUSIVE_RANGES);
}

enum class Edges {
VISIBLE = 0,
SHADING_NONE,
SHADING_FLAT,
SHADING_SMOOTH,
COLOR_VERTEX,
COLOR_EDGE,
COLOR_USER,
COLOR_MESH,
VISIBLE = VCL_MRS_DRAW_EDGES,
SHADING_NONE = VCL_MRS_EDGES_SHADING_NONE,
SHADING_FLAT = VCL_MRS_EDGES_SHADING_FLAT,
SHADING_SMOOTH = VCL_MRS_EDGES_SHADING_SMOOTH,
COLOR_VERTEX = VCL_MRS_EDGES_COLOR_VERTEX,
COLOR_EDGE = VCL_MRS_EDGES_COLOR_EDGE,
COLOR_MESH = VCL_MRS_EDGES_COLOR_MESH,
COLOR_USER = VCL_MRS_EDGES_COLOR_USER,

COUNT
};

bool visible;

// settings for each primitive
BitSet16 points;
BitSet16 surface;
BitSet16 wireframe;
BitSet16 edges;

void reset()
{
visible = false;
points.reset();
surface.reset();
wireframe.reset();
edges.reset();
}

bool operator==(const MeshRenderInfo& o) const
{
return visible == o.visible && points == o.points &&
surface == o.surface && wireframe == o.wireframe &&
edges == o.edges;
}

MeshRenderInfo& operator&=(const MeshRenderInfo& o)
{
visible &= o.visible;
points &= o.points;
surface &= o.surface;
wireframe &= o.wireframe;
edges &= o.edges;
return *this;
}

MeshRenderInfo& operator|=(const MeshRenderInfo& o)
{
visible |= o.visible;
points |= o.points;
surface |= o.surface;
wireframe |= o.wireframe;
edges |= o.edges;
return *this;
}

MeshRenderInfo& operator^=(const MeshRenderInfo& o)
{
visible ^= o.visible;
points ^= o.points;
surface ^= o.surface;
wireframe ^= o.wireframe;
edges ^= o.edges;
return *this;
}

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

constexpr static auto surfaceExclusiveRange(auto value)
{
return getExclusiveRange(value, SURFACE_EXCLUSIVE_RANGES);
}

constexpr static auto wireframeExclusiveRange(auto value)
{
return getExclusiveRange(value, WIREFRAME_EXCLUSIVE_RANGES);
}

constexpr static auto edgesExclusiveRange(auto value)
{
return getExclusiveRange(value, EDGES_EXCLUSIVE_RANGES);
}

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

inline static constexpr auto const SURFACE_EXCLUSIVE_RANGES =
Points::SHAPE_PIXEL,
Points::SHAPE_CIRCLE,
Points::SHADING_NONE,
Points::SHADING_VERT,
Points::COLOR_VERTEX,
Points::COLOR_USER);

inline static constexpr const auto SURFACE_EXCLUSIVE_RANGES =
detail::makeExclusiveReangesArray<Surface>(
Surface::SHADING_NONE, Surface::SHADING_SMOOTH,
Surface::COLOR_FACE, Surface::COLOR_WEDGE_TEX);
Surface::SHADING_NONE,
Surface::SHADING_SMOOTH,
Surface::COLOR_VERTEX,
Surface::COLOR_USER);

inline static constexpr auto const WIREFRAME_EXCLUSIVE_RANGES =
inline static constexpr const auto WIREFRAME_EXCLUSIVE_RANGES =
detail::makeExclusiveReangesArray<Wireframe>(
Wireframe::SHADING_NONE, Wireframe::SHADING_VERT,
Wireframe::COLOR_VERTEX, Wireframe::COLOR_USER);
Wireframe::SHADING_NONE,
Wireframe::SHADING_VERT,
Wireframe::COLOR_VERTEX,
Wireframe::COLOR_USER);

inline static constexpr auto const EDGES_EXCLUSIVE_RANGES =
inline static constexpr const auto EDGES_EXCLUSIVE_RANGES =
detail::makeExclusiveReangesArray<Edges>(
Edges::SHADING_NONE, Edges::SHADING_SMOOTH,
Edges::COLOR_VERTEX, Edges::COLOR_MESH);
Edges::SHADING_NONE,
Edges::SHADING_SMOOTH,
Edges::COLOR_VERTEX,
Edges::COLOR_USER);

constexpr static auto getExclusiveRange(auto value, const auto& array)
{
for (uint i = 0; i < array.size(); i+=2) {
for (uint i = 0; i < array.size(); i += 2) {
if (toUnderlying(value) >= toUnderlying(array[i]) &&
toUnderlying(value) <= toUnderlying(array[i+1])) {
toUnderlying(value) <= toUnderlying(array[i + 1])) {
return std::pair(
toUnderlying(array[i]), toUnderlying(array[i + 1]));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
* These macros are used both on the library and on the shader side.
*/

/* uint mDrawMode0 */

// points
#define VCL_MRS_DRAW_POINTS 0 // point visibility
#define VCL_MRS_POINTS_PIXEL 1 // draw points as pixels
Expand All @@ -40,38 +38,36 @@
#define VCL_MRS_POINTS_COLOR_USER 7 // user color for points

// surface
#define VCL_MRS_DRAW_SURF uint(1 << 10) // surface visibility
#define VCL_MRS_SURF_SHADING_NONE uint(1 << 11) // no shading
#define VCL_MRS_SURF_SHADING_FLAT uint(1 << 12) // flat shading
#define VCL_MRS_SURF_SHADING_SMOOTH uint(1 << 13) // smooth shading
#define VCL_MRS_SURF_COLOR_FACE uint(1 << 14) // face color for surface
#define VCL_MRS_SURF_COLOR_VERTEX uint(1 << 15) // vert color for surface
#define VCL_MRS_SURF_COLOR_MESH uint(1 << 16) // mesh color for surface
#define VCL_MRS_SURF_COLOR_USER uint(1 << 17) // user color for surface
#define VCL_MRS_SURF_TEX_VERTEX uint(1 << 18) // per vertex texcoords
#define VCL_MRS_SURF_TEX_WEDGE uint(1 << 19) // per wedge texcoords
#define VCL_MRS_DRAW_SURF 0 // surface visibility
#define VCL_MRS_SURF_SHADING_NONE 1 // no shading
#define VCL_MRS_SURF_SHADING_FLAT 2 // flat shading
#define VCL_MRS_SURF_SHADING_SMOOTH 3 // smooth shading
#define VCL_MRS_SURF_COLOR_VERTEX 4 // vert color for surface
#define VCL_MRS_SURF_COLOR_FACE 5 // face color for surface
#define VCL_MRS_SURF_TEX_VERTEX 6 // per vertex texcoords
#define VCL_MRS_SURF_TEX_WEDGE 7 // per wedge texcoords
#define VCL_MRS_SURF_COLOR_MESH 8 // mesh color for surface
#define VCL_MRS_SURF_COLOR_USER 9 // user color for surface

// wireframe
#define VCL_MRS_DRAW_WIREFRAME uint(1 << 20) // draw wireframe
#define VCL_MRS_WIREFRAME_SHADING_NONE uint(1 << 21) // no shading
#define VCL_MRS_WIREFRAME_SHADING_VERT uint(1 << 22) // vertex normal shading
#define VCL_MRS_WIREFRAME_COLOR_VERT uint(1 << 23) // vert color for wireframe
#define VCL_MRS_WIREFRAME_COLOR_USER uint(1 << 24) // user color for wireframe
#define VCL_MRS_WIREFRAME_COLOR_MESH uint(1 << 25) // mesh color for wireframe

// bounding box - TODO: remove this
#define VCL_MRS_DRAW_BOUNDINGBOX uint(1 << 31) // bounding box visibility
// wireframe
#define VCL_MRS_DRAW_WIREFRAME 0 // draw wireframe
#define VCL_MRS_WIREFRAME_SHADING_NONE 1 // no shading
#define VCL_MRS_WIREFRAME_SHADING_VERT 2 // vertex normal shading
#define VCL_MRS_WIREFRAME_COLOR_VERT 3 // vert color for wireframe
#define VCL_MRS_WIREFRAME_COLOR_MESH 4 // mesh color for wireframe
#define VCL_MRS_WIREFRAME_COLOR_USER 5 // user color for wireframe

/* uint mDrawMode1 */

// edges
#define VCL_MRS_DRAW_EDGES uint(1 << 0) // draw edges
#define VCL_MRS_EDGES_SHADING_NONE uint(1 << 1) // no shading
#define VCL_MRS_EDGES_SHADING_FLAT uint(1 << 2) // edge normal shading
#define VCL_MRS_EDGES_SHADING_SMOOTH uint(1 << 3) // vertex normal shading
#define VCL_MRS_EDGES_COLOR_VERTEX uint(1 << 4) // vert color for edges
#define VCL_MRS_EDGES_COLOR_EDGE uint(1 << 5) // edge color for edges
#define VCL_MRS_EDGES_COLOR_USER uint(1 << 6) // user color for edges
#define VCL_MRS_EDGES_COLOR_MESH uint(1 << 7) // mesh color for edges
#define VCL_MRS_DRAW_EDGES 0 // draw edges
#define VCL_MRS_EDGES_SHADING_NONE 1 // no shading
#define VCL_MRS_EDGES_SHADING_FLAT 2 // edge normal shading
#define VCL_MRS_EDGES_SHADING_SMOOTH 3 // vertex normal shading
#define VCL_MRS_EDGES_COLOR_VERTEX 4 // vert color for edges
#define VCL_MRS_EDGES_COLOR_EDGE 5 // edge color for edges
#define VCL_MRS_EDGES_COLOR_MESH 6 // mesh color for edges
#define VCL_MRS_EDGES_COLOR_USER 7 // user color for edges


#endif // VCL_RENDER_DRAWABLE_MESH_MESH_RENDER_INFO_MACROS_H
Loading

0 comments on commit 8e499da

Please sign in to comment.