diff --git a/vclib/render/include/vclib/bgfx/drawable/uniforms/mesh_render_settings_uniforms.h b/vclib/render/include/vclib/bgfx/drawable/uniforms/mesh_render_settings_uniforms.h index d856b8f33..a0bd10aeb 100644 --- a/vclib/render/include/vclib/bgfx/drawable/uniforms/mesh_render_settings_uniforms.h +++ b/vclib/render/include/vclib/bgfx/drawable/uniforms/mesh_render_settings_uniforms.h @@ -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(); diff --git a/vclib/render/include/vclib/opengl2/drawable/drawable_mesh.h b/vclib/render/include/vclib/opengl2/drawable/drawable_mesh.h index 947f1d6e9..7b5f49c67 100644 --- a/vclib/render/include/vclib/opengl2/drawable/drawable_mesh.h +++ b/vclib/render/include/vclib/opengl2/drawable/drawable_mesh.h @@ -224,12 +224,6 @@ class DrawableMeshOpenGL2 : public AbstractDrawableMesh, public MeshType } } } - if (mMRS.isBboxEnabled()) { - drawBox3( - mBoundingBox.min(), - mBoundingBox.max(), - vcl::Color(0, 0, 0)); - } } } diff --git a/vclib/render/include/vclib/render/drawable/mesh/mesh_render_info.h b/vclib/render/include/vclib/render/drawable/mesh/mesh_render_info.h index 233f8c367..162fdcf08 100644 --- a/vclib/render/include/vclib/render/drawable/mesh/mesh_render_info.h +++ b/vclib/render/include/vclib/render/drawable/mesh/mesh_render_info.h @@ -25,6 +25,7 @@ #include "mesh_render_info_macros.h" +#include #include #include @@ -34,7 +35,8 @@ namespace vcl { namespace detail { template -auto constexpr makeExclusiveReangesArray(auto... args) { +auto constexpr makeExclusiveReangesArray(auto... args) +{ std::array array; std::size_t i = 0; @@ -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, @@ -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::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::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::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::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])); } diff --git a/vclib/render/include/vclib/render/drawable/mesh/mesh_render_info_macros.h b/vclib/render/include/vclib/render/drawable/mesh/mesh_render_info_macros.h index c5102177b..455174cb0 100644 --- a/vclib/render/include/vclib/render/drawable/mesh/mesh_render_info_macros.h +++ b/vclib/render/include/vclib/render/drawable/mesh/mesh_render_info_macros.h @@ -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 @@ -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 diff --git a/vclib/render/include/vclib/render/drawable/mesh/mesh_render_settings.h b/vclib/render/include/vclib/render/drawable/mesh/mesh_render_settings.h index 5753b21e4..6696db67d 100644 --- a/vclib/render/include/vclib/render/drawable/mesh/mesh_render_settings.h +++ b/vclib/render/include/vclib/render/drawable/mesh/mesh_render_settings.h @@ -60,35 +60,10 @@ namespace vcl { */ class MeshRenderSettings { - struct Info { - bool visible; - - // settings for each primitive - BitSet16 points; - BitSet16 surface; - BitSet16 wireframe; - BitSet16 edges; - - bool operator==(const Info& o) const - { - return visible == o.visible && points == o.points && - surface == o.surface && wireframe == o.wireframe && - edges == o.edges; - } - }; - - Info mCapability; - Info mDrawMode; - - // draw integers controlled using macros (same macros used also in shaders) + using MRI = MeshRenderInfo; - // draw mode 0: general visibility, points, surface and wireframe - uint mDrawModeCapability0 = 0; - uint mDrawMode0 = 0; - - // draw mode 1: edges, ... (to be implemented) - uint mDrawModeCapability1 = 0; - uint mDrawMode1 = 0; + MeshRenderInfo mCapability; // capabilities of the mesh + MeshRenderInfo mDrawMode; // current rendering settings float mPointWidth = 3; float mPointUserColor[4] = {1, 1, 0, 1}; // todo: change to uint @@ -121,173 +96,176 @@ class MeshRenderSettings bool canPoint(MeshRenderInfo::Points p) const { - return pointsCapability(p); + assert(p < MeshRenderInfo::Points::COUNT); + return mCapability.points[toUnderlying(p)]; } bool canPointBeVisible() const { - return canPoint(MeshRenderInfo::Points::VISIBLE); + return canPoint(MRI::Points::VISIBLE); } bool canPointShadingBePerVertex() const { - return canPoint(MeshRenderInfo::Points::SHADING_VERT); + return canPoint(MRI::Points::SHADING_VERT); } bool canPointColorBePerVertex() const { - return canPoint(MeshRenderInfo::Points::COLOR_VERTEX); + return canPoint(MRI::Points::COLOR_VERTEX); } bool canPointColorBePerMesh() const { - return mDrawModeCapability0 & VCL_MRS_POINTS_COLOR_MESH; + return canPoint(MRI::Points::COLOR_MESH); + } + + bool canSurface(MeshRenderInfo::Surface s) const + { + assert(s < MRI::Surface::COUNT); + return mCapability.surface[toUnderlying(s)]; } bool canSurfaceBeVisible() const { - return mDrawModeCapability0 & VCL_MRS_DRAW_SURF; + return canSurface(MRI::Surface::VISIBLE); } bool canSurfaceShadingBeFlat() const { - return mDrawModeCapability0 & VCL_MRS_SURF_SHADING_FLAT; + return canSurface(MRI::Surface::SHADING_FLAT); } bool canSurfaceShadingBeSmooth() const { - return mDrawModeCapability0 & VCL_MRS_SURF_SHADING_SMOOTH; + return canSurface(MRI::Surface::SHADING_SMOOTH); } bool canSurfaceColorBePerFace() const { - return mDrawModeCapability0 & VCL_MRS_SURF_COLOR_FACE; + return canSurface(MRI::Surface::COLOR_FACE); } bool canSurfaceColorBePerVertex() const { - return mDrawModeCapability0 & VCL_MRS_SURF_COLOR_VERTEX; + return canSurface(MRI::Surface::COLOR_VERTEX); } bool canSurfaceColorBePerMesh() const { - return mDrawModeCapability0 & VCL_MRS_SURF_COLOR_MESH; + return canSurface(MRI::Surface::COLOR_MESH); } bool canSurfaceColorBePerVertexTexcoords() const { - return mDrawModeCapability0 & VCL_MRS_SURF_TEX_VERTEX; + return canSurface(MRI::Surface::COLOR_VERTEX_TEX); } bool canSurfaceColorBePerWedgeTexcoords() const { - return mDrawModeCapability0 & VCL_MRS_SURF_TEX_WEDGE; + return canSurface(MRI::Surface::COLOR_WEDGE_TEX); + } + + bool canWireframe(MeshRenderInfo::Wireframe w) const + { + assert(w < MRI::Wireframe::COUNT); + return mCapability.wireframe[toUnderlying(w)]; } bool canWireframeShadingBePerVertex() const { - return mDrawModeCapability0 & VCL_MRS_WIREFRAME_SHADING_VERT; + return canWireframe(MRI::Wireframe::SHADING_VERT); } bool canWireframeColorBePerVertex() const { - return mDrawModeCapability0 & VCL_MRS_WIREFRAME_COLOR_VERT; + return canWireframe(MRI::Wireframe::COLOR_VERTEX); } bool canWireframeColorBePerMesh() const { - return mDrawModeCapability0 & VCL_MRS_WIREFRAME_COLOR_MESH; + return canWireframe(MRI::Wireframe::COLOR_MESH); } - bool canBoundingBoxBeVisible() const + bool canEdges(MeshRenderInfo::Edges e) const { - return mDrawModeCapability0 & VCL_MRS_DRAW_BOUNDINGBOX; + assert(e < MRI::Edges::COUNT); + return mCapability.edges[toUnderlying(e)]; } bool canEdgesBeVisible() const { - return mDrawModeCapability1 & VCL_MRS_DRAW_EDGES; + return canEdges(MRI::Edges::VISIBLE); } bool canEdgesShadingBeSmooth() const { - return mDrawModeCapability1 & VCL_MRS_EDGES_SHADING_SMOOTH; + return canEdges(MRI::Edges::SHADING_SMOOTH); } bool canEdgesShadingBeFlat() const { - return mDrawModeCapability1 & VCL_MRS_EDGES_SHADING_FLAT; + return canEdges(MRI::Edges::SHADING_FLAT); } bool canEdgesColorBePerVertex() const { - return mDrawModeCapability1 & VCL_MRS_EDGES_COLOR_VERTEX; + return canEdges(MRI::Edges::COLOR_VERTEX); } bool canEdgesColorBePerEdge() const { - return mDrawModeCapability1 & VCL_MRS_EDGES_COLOR_EDGE; + return canEdges(MRI::Edges::COLOR_EDGE); } bool canEdgesColorBePerMesh() const { - return mDrawModeCapability1 & VCL_MRS_EDGES_COLOR_MESH; + return canEdges(MRI::Edges::COLOR_MESH); } // rendering options getters - std::pair drawMode() const + MeshRenderInfo drawMode() const { - uint drawMode0 = mDrawMode.points.underlying(); - drawMode0 |= mDrawMode.surface.underlying() << 16; - uint drawMode1 = mDrawMode.wireframe.underlying(); - drawMode1 |= mDrawMode.edges.underlying() << 16; - return {drawMode0, drawMode1}; + return mDrawMode; } - uint drawMode0() const { return mDrawMode0; } - - uint drawMode1() const { return mDrawMode1; } - - uint drawModeCapability0() const { return mDrawModeCapability0; } - - uint drawModeCapability1() const { return mDrawModeCapability1; } - bool isVisible() const { return mDrawMode.visible; } bool isPoint(MeshRenderInfo::Points p) const { - return pointsDrawMode(p); + assert(p < MRI::Points::COUNT); + return mDrawMode.points[toUnderlying(p)]; } bool isPointVisible() const { - return pointsDrawMode(MeshRenderInfo::Points::VISIBLE); + return isPoint(MRI::Points::VISIBLE); } bool isPointShadingNone() const { - return pointsDrawMode(MeshRenderInfo::Points::SHADING_NONE); + return isPoint(MRI::Points::SHADING_NONE); } bool isPointShadingPerVertex() const { - return pointsDrawMode(MeshRenderInfo::Points::SHADING_VERT); + return isPoint(MRI::Points::SHADING_VERT); } bool isPointColorPerVertex() const { - return pointsDrawMode(MeshRenderInfo::Points::COLOR_VERTEX); + return isPoint(MRI::Points::COLOR_VERTEX); } bool isPointColorPerMesh() const { - return pointsDrawMode(MeshRenderInfo::Points::COLOR_MESH); + return isPoint(MRI::Points::COLOR_MESH); } bool isPointColorUserDefined() const { - return pointsDrawMode(MeshRenderInfo::Points::COLOR_USER); + return isPoint(MRI::Points::COLOR_USER); } float pointWidth() const { return mPointWidth; } @@ -296,85 +274,100 @@ class MeshRenderSettings const float* pointUserColorData() const { return mPointUserColor; } - bool isSurfaceVisible() const { return mDrawMode0 & VCL_MRS_DRAW_SURF; } + bool isSurface(MeshRenderInfo::Surface s) const + { + assert(s < MRI::Surface::COUNT); + return mDrawMode.surface[toUnderlying(s)]; + } + + bool isSurfaceVisible() const + { + return isSurface(MRI::Surface::VISIBLE); + } bool isSurfaceShadingNone() const { - return mDrawMode0 & VCL_MRS_SURF_SHADING_NONE; + return isSurface(MRI::Surface::SHADING_NONE); } bool isSurfaceShadingFlat() const { - return mDrawMode0 & VCL_MRS_SURF_SHADING_FLAT; + return isSurface(MRI::Surface::SHADING_FLAT); } bool isSurfaceShadingSmooth() const { - return mDrawMode0 & VCL_MRS_SURF_SHADING_SMOOTH; + return isSurface(MeshRenderInfo::Surface::SHADING_SMOOTH); } bool isSurfaceColorPerFace() const { - return mDrawMode0 & VCL_MRS_SURF_COLOR_FACE; + return isSurface(MRI::Surface::COLOR_FACE); } bool isSurfaceColorPerVertex() const { - return mDrawMode0 & VCL_MRS_SURF_COLOR_VERTEX; + return isSurface(MRI::Surface::COLOR_VERTEX); } bool isSurfaceColorPerMesh() const { - return mDrawMode0 & VCL_MRS_SURF_COLOR_MESH; + return isSurface(MRI::Surface::COLOR_MESH); } bool isSurfaceColorUserDefined() const { - return mDrawMode0 & VCL_MRS_SURF_COLOR_USER; + return isSurface(MRI::Surface::COLOR_USER); } bool isSurfaceColorPerVertexTexcoords() const { - return mDrawMode0 & VCL_MRS_SURF_TEX_VERTEX; + return isSurface(MRI::Surface::COLOR_VERTEX_TEX); } bool isSurfaceColorPerWedgeTexcoords() const { - return mDrawMode0 & VCL_MRS_SURF_TEX_WEDGE; + return isSurface(MRI::Surface::COLOR_WEDGE_TEX); } vcl::Color surfaceUserColor() const; const uint* surfaceUserColorData() const { return &mSurfUserColor; } + bool isWireframe(MeshRenderInfo::Wireframe w) const + { + assert(w < MRI::Wireframe::COUNT); + return mDrawMode.wireframe[toUnderlying(w)]; + } + bool isWireframeVisible() const { - return mDrawMode0 & VCL_MRS_DRAW_WIREFRAME; + return isWireframe(MRI::Wireframe::VISIBLE); } bool isWireframeShadingNone() const { - return mDrawMode0 & VCL_MRS_WIREFRAME_SHADING_NONE; + return isWireframe(MRI::Wireframe::SHADING_NONE); } bool isWireframeShadingPerVertex() const { - return mDrawMode0 & VCL_MRS_WIREFRAME_SHADING_VERT; + return isWireframe(MRI::Wireframe::SHADING_VERT); } bool isWireframeColorPerVertex() const { - return mDrawMode0 & VCL_MRS_WIREFRAME_COLOR_VERT; + return isWireframe(MRI::Wireframe::COLOR_VERTEX); } bool isWireframeColorPerMesh() const { - return mDrawMode0 & VCL_MRS_WIREFRAME_COLOR_MESH; + return isWireframe(MRI::Wireframe::COLOR_MESH); } bool isWireframeColorUserDefined() const { - return mDrawMode0 & VCL_MRS_WIREFRAME_COLOR_USER; + return isWireframe(MRI::Wireframe::COLOR_USER); } int wireframeWidth() const { return mWrfWidth; } @@ -383,43 +376,50 @@ class MeshRenderSettings const float* wireframeUserColorData() const { return mWrfUserColor; } - bool isBboxEnabled() const { return mDrawMode0 & VCL_MRS_DRAW_BOUNDINGBOX; } + bool isEdges(MeshRenderInfo::Edges e) const + { + assert(e < MRI::Edges::COUNT); + return mDrawMode.edges[toUnderlying(e)]; + } - bool isEdgesVisible() const { return mDrawMode1 & VCL_MRS_DRAW_EDGES; } + bool isEdgesVisible() const + { + return isEdges(MRI::Edges::VISIBLE); + } bool isEdgesShadingNone() const { - return mDrawMode1 & VCL_MRS_EDGES_SHADING_NONE; + return isEdges(MRI::Edges::SHADING_NONE); } bool isEdgesShadingSmooth() const { - return mDrawMode1 & VCL_MRS_EDGES_SHADING_SMOOTH; + return isEdges(MRI::Edges::SHADING_SMOOTH); } bool isEdgesShadingFlat() const { - return mDrawMode1 & VCL_MRS_EDGES_SHADING_FLAT; + return isEdges(MRI::Edges::SHADING_FLAT); } bool isEdgesColorPerVertex() const { - return mDrawMode1 & VCL_MRS_EDGES_COLOR_VERTEX; + return isEdges(MRI::Edges::COLOR_VERTEX); } bool isEdgesColorPerEdge() const { - return mDrawMode1 & VCL_MRS_EDGES_COLOR_EDGE; + return isEdges(MRI::Edges::COLOR_EDGE); } bool isEdgesColorPerMesh() const { - return mDrawMode1 & VCL_MRS_EDGES_COLOR_MESH; + return isEdges(MRI::Edges::COLOR_MESH); } bool isEdgesColorUserDefined() const { - return mDrawMode1 & VCL_MRS_EDGES_COLOR_USER; + return isEdges(MRI::Edges::COLOR_USER); } int edgesWidth() const { return mEdgesWidth; } @@ -432,25 +432,37 @@ class MeshRenderSettings bool setVisibility(bool b); - bool setPoint(MeshRenderInfo::Points p, bool b); + bool setPoint(MeshRenderInfo::Points p, bool b = true); - bool setSurface(MeshRenderInfo::Surface s, bool b); - - bool setWireframe(MeshRenderInfo::Wireframe w, bool b); - - bool setEdges(MeshRenderInfo::Edges e, bool b); - - bool setPointVisibility(bool b); + bool setPointVisibility(bool b) + { + return setPoint(MRI::Points::VISIBLE, b); + } - bool setPointShadingNone(); + bool setPointShadingNone() + { + return setPoint(MRI::Points::SHADING_NONE); + } - bool setPointShadingPerVertex(); + bool setPointShadingPerVertex() + { + return setPoint(MRI::Points::SHADING_VERT); + } - bool setPointColorPerVertex(); + bool setPointColorPerVertex() + { + return setPoint(MRI::Points::COLOR_VERTEX); + } - bool setPointColorPerMesh(); + bool setPointColorPerMesh() + { + return setPoint(MRI::Points::COLOR_MESH); + } - bool setPointColorUserDefined(); + bool setPointColorUserDefined() + { + return setPoint(MRI::Points::COLOR_USER); + } bool setPointWidth(float width); @@ -458,196 +470,309 @@ class MeshRenderSettings bool setPointUserColor(const vcl::Color& c); - bool setSurfaceVisibility(bool b); + bool setSurface(MeshRenderInfo::Surface s, bool b = true); - bool setSurfaceShadingNone(); + bool setSurfaceVisibility(bool b) + { + return setSurface(MRI::Surface::VISIBLE, b); + } - bool setSurfaceShadingFlat(); + /** + * @brief Unsets the shading of the surface (no light). + * Unsets automatically all the other shading options. + */ + bool setSurfaceShadingNone() + { + return setSurface(MRI::Surface::SHADING_NONE); + } - bool setSurfaceShadingSmooth(); + /** + * @brief Sets (if capability allows it) the shading of the surface flat + * (using triangle normals). Unsets automatically all the other shading + * options. + */ + bool setSurfaceShadingFlat() + { + return setSurface(MRI::Surface::SHADING_FLAT); + } - bool setSurfaceColorPerVertex(); + /** + * @brief Sets (if capability allows it) the shading of the surface smooth + * (using vertex normals). Unsets automatically all the other shading + * options. + */ + bool setSurfaceShadingSmooth() + { + return setSurface(MRI::Surface::SHADING_SMOOTH); + } + + /** + * @brief Set (if capability allows it) the surface coloring per vertex + * (using the vertex colors). Unsets automatically all the other surface + * colorizations. + */ + bool setSurfaceColorPerVertex() + { + return setSurface(MRI::Surface::COLOR_VERTEX); + } - bool setSurfaceColorPerFace(); + /** + * @brief Set (if capability allows it) the surface coloring per face (using + * the face colors). Unsets automatically all the other surface + * colorizations. + */ + bool setSurfaceColorPerFace() + { + return setSurface(MRI::Surface::COLOR_FACE); + } - bool setSurfaceColorPerMesh(); + /** + * @brief Set (if capability allows it) the surface coloring per mesh (using + * the mesh color). Unsets automatically all the other surface + * colorizations. + */ + bool setSurfaceColorPerMesh() + { + return setSurface(MRI::Surface::COLOR_MESH); + } - bool setSurfaceColorUserDefined(); + /** + * @brief Set the surface coloring by the user defined color. + * To set the user defined color, you can use the + * @ref setSurfaceColorUserDefined() function. Unsets automatically all the + * other surface colorizations. + */ + bool setSurfaceColorUserDefined() + { + return setSurface(MRI::Surface::COLOR_USER); + } - bool setSurfaceColorPerVertexTexcoords(); + /** + * @brief Set (if capability allows it) the surface color using the per + * vertex texcoords. Unsets automatically all the other surface + * colorizations. + */ + bool setSurfaceColorPerVertexTexcoords() + { + return setSurface(MRI::Surface::COLOR_VERTEX_TEX); + } - bool setSurfaceColorPerWedgeTexcoords(); + /** + * @brief Set (if capability allows it) the surface color using the per + * wedge texcoords. Unsets automatically all the other surface + * colorizations. + */ + bool setSurfaceColorPerWedgeTexcoords() + { + return setSurface(MRI::Surface::COLOR_WEDGE_TEX); + } bool setSurfaceUserColor(float r, float g, float b, float a = 1); bool setSurfaceUserColor(const vcl::Color& c); - bool setWireframeVisibility(bool b); + bool setWireframe(MeshRenderInfo::Wireframe w, bool b = true); + + bool setWireframeVisibility(bool b) + { + return setWireframe(MRI::Wireframe::VISIBLE, b); + } - bool setWireframeShadingNone(); + bool setWireframeShadingNone() + { + return setWireframe(MRI::Wireframe::SHADING_NONE); + } - bool setWireframeShadingPerVertex(); + bool setWireframeShadingPerVertex() + { + return setWireframe(MRI::Wireframe::SHADING_VERT); + } - bool setWireframeColorPerVertex(); + bool setWireframeColorPerVertex() + { + return setWireframe(MRI::Wireframe::COLOR_VERTEX); + } - bool setWireframeColorPerMesh(); + bool setWireframeColorPerMesh() + { + return setWireframe(MRI::Wireframe::COLOR_MESH); + } - bool setWireframeColorUserDefined(); + bool setWireframeColorUserDefined() + { + return setWireframe(MRI::Wireframe::COLOR_USER); + } bool setWireframeUserColor(float r, float g, float b, float a = 1); - bool setWireframeWidth(int width); - bool setWireframeUserColor(const vcl::Color& c); - bool setBoundingBoxVisibility(bool b); + bool setWireframeWidth(int width); - bool setEdgesVisibility(bool b); + bool setEdges(MeshRenderInfo::Edges e, bool b = true); - bool setEdgesShadingNone(); + bool setEdgesVisibility(bool b) + { + return setEdges(MRI::Edges::VISIBLE, b); + } - bool setEdgesShadingSmooth(); + bool setEdgesShadingNone() + { + return setEdges(MRI::Edges::SHADING_NONE); + } - bool setEdgesShadingFlat(); + bool setEdgesShadingSmooth() + { + return setEdges(MRI::Edges::SHADING_SMOOTH); + } - bool setEdgesColorPerVertex(); + bool setEdgesShadingFlat() + { + return setEdges(MRI::Edges::SHADING_FLAT); + } - bool setEdgesColorPerEdge(); + bool setEdgesColorPerVertex() + { + return setEdges(MRI::Edges::COLOR_VERTEX); + } - bool setEdgesColorPerMesh(); + bool setEdgesColorPerEdge() + { + return setEdges(MRI::Edges::COLOR_EDGE); + } - bool setEdgesColorUserDefined(); + bool setEdgesColorPerMesh() + { + return setEdges(MRI::Edges::COLOR_MESH); + } - bool setEdgesWidth(int width); + bool setEdgesColorUserDefined() + { + return setEdges(MRI::Edges::COLOR_USER); + } bool setEdgesUserColor(float r, float g, float b, float a = 1); bool setEdgesUserColor(const vcl::Color& c); + bool setEdgesWidth(int width); + template void setRenderCapabilityFrom(const MeshType& m) { - mDrawModeCapability0 = 0; + mCapability.reset(); if (m.vertexNumber() > 0) { mCapability.visible = true; // -- Points -- - setPointsCapability(MeshRenderInfo::Points::VISIBLE); - setPointsCapability(MeshRenderInfo::Points::SHAPE_PIXEL); - setPointsCapability(MeshRenderInfo::Points::SHAPE_CIRCLE); - setPointsCapability(MeshRenderInfo::Points::SHADING_NONE); - mDrawModeCapability0 |= VCL_MRS_POINTS_COLOR_USER; + setPointsCapability(MRI::Points::VISIBLE); + setPointsCapability(MRI::Points::SHAPE_PIXEL); + setPointsCapability(MRI::Points::SHAPE_CIRCLE); + setPointsCapability(MRI::Points::SHADING_NONE); + setPointsCapability(MRI::Points::COLOR_USER); if constexpr (vcl::HasPerVertexNormal) { if (vcl::isPerVertexNormalAvailable(m)) { - setPointsCapability(MeshRenderInfo::Points::SHADING_VERT); + setPointsCapability(MRI::Points::SHADING_VERT); } } if constexpr (vcl::HasPerVertexColor) { if (vcl::isPerVertexColorAvailable(m)) { - setPointsCapability(MeshRenderInfo::Points::COLOR_VERTEX); + setPointsCapability(MRI::Points::COLOR_VERTEX); } } if constexpr (vcl::HasColor) { - setPointsCapability(MeshRenderInfo::Points::COLOR_MESH); + setPointsCapability(MRI::Points::COLOR_MESH); } // -- Surface and Wireframe -- if constexpr (vcl::HasFaces) { if (m.faceNumber() > 0) { - mDrawModeCapability0 |= VCL_MRS_DRAW_SURF; - mDrawModeCapability0 |= VCL_MRS_SURF_SHADING_NONE; - mDrawModeCapability0 |= VCL_MRS_SURF_COLOR_USER; - mDrawModeCapability0 |= VCL_MRS_DRAW_WIREFRAME; - mDrawModeCapability0 |= VCL_MRS_WIREFRAME_SHADING_NONE; - mDrawModeCapability0 |= VCL_MRS_WIREFRAME_COLOR_USER; + setSurfaceCapability(MRI::Surface::VISIBLE); + setSurfaceCapability(MRI::Surface::SHADING_NONE); + setSurfaceCapability(MRI::Surface::COLOR_USER); + setWireframeCapability(MRI::Wireframe::VISIBLE); + setWireframeCapability(MRI::Wireframe::SHADING_NONE); + setWireframeCapability(MRI::Wireframe::COLOR_USER); if constexpr (vcl::HasColor) { - mDrawModeCapability0 |= VCL_MRS_SURF_COLOR_MESH; - mDrawModeCapability0 |= VCL_MRS_WIREFRAME_COLOR_MESH; + setSurfaceCapability(MRI::Surface::COLOR_MESH); + setWireframeCapability(MRI::Wireframe::COLOR_MESH); } if constexpr (vcl::HasPerFaceNormal) { if (vcl::isPerFaceNormalAvailable(m)) { - mDrawModeCapability0 |= VCL_MRS_SURF_SHADING_FLAT; + setSurfaceCapability(MRI::Surface::SHADING_FLAT); } } if constexpr (vcl::HasPerVertexNormal) { if (vcl::isPerVertexNormalAvailable(m)) { - mDrawModeCapability0 |= VCL_MRS_SURF_SHADING_SMOOTH; - mDrawModeCapability0 |= - VCL_MRS_WIREFRAME_SHADING_VERT; + setSurfaceCapability(MRI::Surface::SHADING_SMOOTH); + setWireframeCapability(MRI::Wireframe::SHADING_VERT); } } if constexpr (vcl::HasPerFaceColor) { if (vcl::isPerFaceColorAvailable(m)) - mDrawModeCapability0 |= VCL_MRS_SURF_COLOR_FACE; + setSurfaceCapability(MRI::Surface::COLOR_FACE); } if constexpr (vcl::HasPerVertexColor) { if (vcl::isPerVertexColorAvailable(m)) { - mDrawModeCapability0 |= VCL_MRS_SURF_COLOR_VERTEX; - mDrawModeCapability0 |= - VCL_MRS_WIREFRAME_COLOR_VERT; + setSurfaceCapability(MRI::Surface::COLOR_VERTEX); + setWireframeCapability(MRI::Wireframe::COLOR_VERTEX); } } if constexpr (vcl::HasTexturePaths) { if constexpr (vcl::HasPerVertexTexCoord) { if (vcl::isPerVertexTexCoordAvailable(m)) - mDrawModeCapability0 |= VCL_MRS_SURF_TEX_VERTEX; + setSurfaceCapability(MRI::Surface::COLOR_VERTEX_TEX); } if constexpr (vcl::HasPerFaceWedgeTexCoords) { if (vcl::isPerFaceWedgeTexCoordsAvailable(m)) - mDrawModeCapability0 |= VCL_MRS_SURF_TEX_WEDGE; + setSurfaceCapability(MRI::Surface::COLOR_WEDGE_TEX); } } } } - // -- Bounding Box -- - if constexpr (vcl::HasBoundingBox) { - mDrawModeCapability0 |= VCL_MRS_DRAW_BOUNDINGBOX; - } - // -- Edges -- if constexpr (vcl::HasEdges) { if (m.edgeNumber() > 0) { - mDrawModeCapability1 |= VCL_MRS_DRAW_EDGES; - mDrawModeCapability1 |= VCL_MRS_EDGES_SHADING_NONE; - mDrawModeCapability1 |= VCL_MRS_EDGES_COLOR_USER; + setEdgesCapability(MRI::Edges::VISIBLE); + setEdgesCapability(MRI::Edges::SHADING_NONE); + setEdgesCapability(MRI::Edges::COLOR_USER); if constexpr (vcl::HasColor) { - mDrawModeCapability1 |= VCL_MRS_EDGES_COLOR_MESH; + setEdgesCapability(MRI::Edges::COLOR_MESH); } if constexpr (vcl::HasPerVertexNormal) { if (vcl::isPerVertexNormalAvailable(m)) { - mDrawModeCapability1 |= - VCL_MRS_EDGES_SHADING_SMOOTH; + setEdgesCapability(MRI::Edges::SHADING_SMOOTH); } } if constexpr (vcl::HasPerEdgeNormal) { if (vcl::isPerEdgeNormalAvailable(m)) { - mDrawModeCapability1 |= VCL_MRS_EDGES_SHADING_FLAT; + setEdgesCapability(MRI::Edges::SHADING_FLAT); } } if constexpr (vcl::HasPerEdgeColor) { if (vcl::isPerEdgeColorAvailable(m)) - mDrawModeCapability1 |= VCL_MRS_EDGES_COLOR_EDGE; + setEdgesCapability(MRI::Edges::COLOR_EDGE); } if constexpr (vcl::HasPerVertexColor) { if (vcl::isPerVertexColorAvailable(m)) { - mDrawModeCapability1 |= VCL_MRS_EDGES_COLOR_VERTEX; + setEdgesCapability(MRI::Edges::COLOR_VERTEX); } } } @@ -655,106 +780,57 @@ class MeshRenderSettings } // make sure that the previous draw mode satisfies the new capabilites - mDrawMode0 &= mDrawModeCapability0; - mDrawMode1 &= mDrawModeCapability1; + mDrawMode &= mCapability; } 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); + assert(p < MRI::Points::COUNT); mCapability.points[toUnderlying(p)] = b; } void setPointsDrawMode(MeshRenderInfo::Points p, bool b = true) { - assert(p < MeshRenderInfo::Points::COUNT); + assert(p < MRI::Points::COUNT); mDrawMode.points[toUnderlying(p)] = b; } - bool surfaceCapability(MeshRenderInfo::Surface p) const - { - assert(p < MeshRenderInfo::Surface::COUNT); - return mCapability.surface[toUnderlying(p)]; - } - - bool surfaceDrawMode(MeshRenderInfo::Surface p) const - { - assert(p < MeshRenderInfo::Surface::COUNT); - return mDrawMode.surface[toUnderlying(p)]; - } - void setSurfaceCapability(MeshRenderInfo::Surface p, bool b = true) { - assert(p < MeshRenderInfo::Surface::COUNT); + assert(p < MRI::Surface::COUNT); mCapability.surface[toUnderlying(p)] = b; } void setSurfaceDrawMode(MeshRenderInfo::Surface p, bool b = true) { - assert(p < MeshRenderInfo::Surface::COUNT); + assert(p < MRI::Surface::COUNT); mDrawMode.surface[toUnderlying(p)] = b; } - bool wireframeCapability(MeshRenderInfo::Wireframe p) const - { - assert(p < MeshRenderInfo::Wireframe::COUNT); - return mCapability.wireframe[toUnderlying(p)]; - } - - bool wireframeDrawMode(MeshRenderInfo::Wireframe p) const - { - assert(p < MeshRenderInfo::Wireframe::COUNT); - return mDrawMode.wireframe[toUnderlying(p)]; - } - void setWireframeCapability(MeshRenderInfo::Wireframe p, bool b = true) { - assert(p < MeshRenderInfo::Wireframe::COUNT); + assert(p < MRI::Wireframe::COUNT); mCapability.wireframe[toUnderlying(p)] = b; } - void setWireframeDrawMode(MeshRenderInfo::Wireframe p, bool b = true) + void setWireframeDrawMode(MRI::Wireframe p, bool b = true) { - assert(p < MeshRenderInfo::Wireframe::COUNT); + assert(p < MRI::Wireframe::COUNT); mDrawMode.wireframe[toUnderlying(p)] = b; } - bool edgesCapability(MeshRenderInfo::Edges p) const - { - assert(p < MeshRenderInfo::Edges::COUNT); - return mCapability.edges[toUnderlying(p)]; - } - - bool edgesDrawMode(MeshRenderInfo::Edges p) const - { - assert(p < MeshRenderInfo::Edges::COUNT); - return mDrawMode.edges[toUnderlying(p)]; - } - void setEdgesCapability(MeshRenderInfo::Edges p, bool b = true) { - assert(p < MeshRenderInfo::Edges::COUNT); + assert(p < MRI::Edges::COUNT); mCapability.edges[toUnderlying(p)] = b; } void setEdgesDrawMode(MeshRenderInfo::Edges p, bool b = true) { - assert(p < MeshRenderInfo::Edges::COUNT); + assert(p < MRI::Edges::COUNT); mDrawMode.edges[toUnderlying(p)] = b; } }; diff --git a/vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/edges/fs_edges.sc b/vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/edges/fs_edges.sc index e70c0e2b5..a26cf5ec1 100644 --- a/vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/edges/fs_edges.sc +++ b/vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/edges/fs_edges.sc @@ -31,8 +31,6 @@ BUFFER_RO(primitiveNormals, float, VCL_MRB_PRIMITIVE_NORMAL_BUFFER); // normal o void main() { - uint drawMode1 = floatBitsToUint(u_drawMode1Float); - // depth offset - avoid z-fighting float depthOffset = 0.0; @@ -47,7 +45,7 @@ void main() vec3 normal = normalize(v_normal); // if flat shading, compute normal of face - if (bool(drawMode1 & VCL_MRS_EDGES_SHADING_FLAT)) { + if (bool(u_edgesMode & (1 << VCL_MRS_EDGES_SHADING_FLAT))) { normal = vec3( primitiveNormals[gl_PrimitiveID * 3], primitiveNormals[gl_PrimitiveID * 3 + 1], @@ -56,7 +54,7 @@ void main() } // if flat or smooth shading, compute light - if (!bool(drawMode1 & VCL_MRS_EDGES_SHADING_NONE)) { + if (!bool(u_edgesMode & (1 << VCL_MRS_EDGES_SHADING_NONE))) { light = computeLight(u_lightDir, u_lightColor, normal); specular = computeSpecular( @@ -70,13 +68,13 @@ void main() /***** compute color ******/ color = uintABGRToVec4Color(floatBitsToUint(u_userEdgesColorFloat)); - if (bool(drawMode1 & VCL_MRS_EDGES_COLOR_VERTEX)) { + if (bool(u_edgesMode & (1 << VCL_MRS_EDGES_COLOR_VERTEX))) { color = v_color; } - if (bool(drawMode1 & VCL_MRS_EDGES_COLOR_MESH)) { + if (bool(u_edgesMode & (1 << VCL_MRS_EDGES_COLOR_MESH))) { color = u_meshColor; } - if (bool(drawMode1 & VCL_MRS_EDGES_COLOR_EDGE)) { + if (bool(u_edgesMode & (1 << VCL_MRS_EDGES_COLOR_EDGE))) { color = uintABGRToVec4Color(primitiveColors[gl_PrimitiveID]); } depthOffset = 0.00005; diff --git a/vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/surface/fs_surface.sc b/vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/surface/fs_surface.sc index ffa09ae62..d45260f43 100644 --- a/vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/surface/fs_surface.sc +++ b/vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/surface/fs_surface.sc @@ -55,8 +55,6 @@ vec4 getColorFromTexture(uint texId, vec2 uv) { void main() { - uint drawMode0 = floatBitsToUint(u_drawMode0Float); - // depth offset - avoid z-fighting float depthOffset = 0.0; @@ -71,7 +69,7 @@ void main() vec3 normal = normalize(v_normal); // if flat shading, compute normal of face - if (bool(drawMode0 & VCL_MRS_SURF_SHADING_FLAT)) { + if (bool(u_surfaceMode & (1 << VCL_MRS_SURF_SHADING_FLAT))) { normal = vec3( primitiveNormals[gl_PrimitiveID * 3], primitiveNormals[gl_PrimitiveID * 3 + 1], @@ -81,7 +79,7 @@ void main() } // if flat or smooth shading, compute light - if (!bool(drawMode0 & VCL_MRS_SURF_SHADING_NONE)) { + if (!bool(u_surfaceMode & (1 << VCL_MRS_SURF_SHADING_NONE))) { light = computeLight(u_lightDir, u_lightColor, normal); specular = computeSpecular( @@ -95,19 +93,19 @@ void main() /***** compute color ******/ color = uintABGRToVec4Color(floatBitsToUint(u_userSurfaceColorFloat)); - if (bool(drawMode0 & VCL_MRS_SURF_COLOR_VERTEX)) { + if (bool(u_surfaceMode & (1 << VCL_MRS_SURF_COLOR_VERTEX))) { color = v_color; } - if (bool(drawMode0 & VCL_MRS_SURF_COLOR_MESH)) { + if (bool(u_surfaceMode & (1 << VCL_MRS_SURF_COLOR_MESH))) { color = u_meshColor; } - if (bool(drawMode0 & VCL_MRS_SURF_COLOR_FACE)) { + if (bool(u_surfaceMode & (1 << VCL_MRS_SURF_COLOR_FACE))) { color = uintABGRToVec4Color(primitiveColors[gl_PrimitiveID]); } - if (bool(drawMode0 & VCL_MRS_SURF_TEX_VERTEX)) { + if (bool(u_surfaceMode & (1 << VCL_MRS_SURF_TEX_VERTEX))) { color = getColorFromTexture(0, v_texcoord0); } - if (bool(drawMode0 & VCL_MRS_SURF_TEX_WEDGE)) { + if (bool(u_surfaceMode & (1 << VCL_MRS_SURF_TEX_WEDGE))) { color = getColorFromTexture(triTextureIds[gl_PrimitiveID], v_texcoord1); } diff --git a/vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/wireframe/fs_wireframe.sc b/vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/wireframe/fs_wireframe.sc index 6c3f0e740..cbdf3dfaa 100644 --- a/vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/wireframe/fs_wireframe.sc +++ b/vclib/render/shaders/vclib/bgfx/drawable/drawable_mesh/wireframe/fs_wireframe.sc @@ -27,8 +27,6 @@ $input v_position, v_normal, v_color void main() { - uint drawMode0 = floatBitsToUint(u_drawMode0Float); - // depth offset - avoid z-fighting float depthOffset = 0.0; @@ -43,16 +41,16 @@ void main() vec3 normal = normalize(v_normal); // shading - if (!bool(drawMode0 & VCL_MRS_WIREFRAME_SHADING_NONE)) { + if (!bool(u_wireframeMode & (1 << VCL_MRS_WIREFRAME_SHADING_NONE))) { light = computeLight(u_lightDir, u_lightColor, normal); } color = uintABGRToVec4Color(floatBitsToUint(u_userWireframeColorFloat)); - if (bool(drawMode0 & VCL_MRS_WIREFRAME_COLOR_VERT)) { + if (bool(u_wireframeMode & (1 << VCL_MRS_WIREFRAME_COLOR_VERT))) { color = v_color; } - if (bool(drawMode0 & VCL_MRS_WIREFRAME_COLOR_MESH)) { + if (bool(u_wireframeMode & (1 << VCL_MRS_WIREFRAME_COLOR_MESH))) { color = u_meshColor; } depthOffset = 0.00005; diff --git a/vclib/render/shaders/vclib/bgfx/drawable/uniforms/mesh_render_settings_uniforms.sh b/vclib/render/shaders/vclib/bgfx/drawable/uniforms/mesh_render_settings_uniforms.sh index f9a2e2a48..c42942d4a 100644 --- a/vclib/render/shaders/vclib/bgfx/drawable/uniforms/mesh_render_settings_uniforms.sh +++ b/vclib/render/shaders/vclib/bgfx/drawable/uniforms/mesh_render_settings_uniforms.sh @@ -27,13 +27,10 @@ uniform vec4 u_mrsDrawPack; uniform vec4 u_mrsWidthPack; uniform vec4 u_mrsColorPack; -#define u_drawMode0Float u_mrsDrawPack.x -#define u_drawMode1Float u_mrsDrawPack.y - #define u_pointsMode floatBitsToUint(u_mrsDrawPack.x) #define u_surfaceMode (floatBitsToUint(u_mrsDrawPack.x) >> 16) #define u_wireframeMode floatBitsToUint(u_mrsDrawPack.y) -#define u_edgeMode (floatBitsToUint(u_mrsDrawPack.y) >> 16) +#define u_edgesMode (floatBitsToUint(u_mrsDrawPack.y) >> 16) #define u_pointWidth u_mrsWidthPack.x #define u_wireframeWidth u_mrsWidthPack.y diff --git a/vclib/render/src/vclib/render/drawable/mesh/mesh_render_settings.cpp b/vclib/render/src/vclib/render/drawable/mesh/mesh_render_settings.cpp index 2bd5b4275..0583b05d1 100644 --- a/vclib/render/src/vclib/render/drawable/mesh/mesh_render_settings.cpp +++ b/vclib/render/src/vclib/render/drawable/mesh/mesh_render_settings.cpp @@ -69,11 +69,11 @@ bool MeshRenderSettings::setVisibility(bool b) } } -bool MeshRenderSettings::setPoint(MeshRenderInfo::Points p, bool b = true) +bool MeshRenderSettings::setPoint(MeshRenderInfo::Points p, bool b) { if (canPoint(p)) { // if the capability allows it // get the range of the mutual exclusive settings for p - auto rng = MeshRenderInfo::pointsExclusiveRange(p); + auto rng = MRI::pointsExclusiveRange(p); // if there are no mutual exclusive settings if (rng.first == rng.second) { // the setting could be true or false @@ -83,7 +83,7 @@ bool MeshRenderSettings::setPoint(MeshRenderInfo::Points p, bool b = true) else { // only one setting in the range can be true // e.g. the range SHAPE_* - for (auto i = rng.first; i < rng.second; ++i) { + for (auto i = rng.first; i <= rng.second; ++i) { mDrawMode.points[i] = toUnderlying(p) == i; } } @@ -94,97 +94,6 @@ bool MeshRenderSettings::setPoint(MeshRenderInfo::Points p, bool b = true) } } -bool MeshRenderSettings::setSurface(MeshRenderInfo::Surface s, bool b) -{ - // TODO - return false; -} - -bool MeshRenderSettings::setWireframe(MeshRenderInfo::Wireframe w, bool b) -{ - // TODO - return false; -} - -bool MeshRenderSettings::setEdges(MeshRenderInfo::Edges e, bool b) -{ - // TODO - return false; -} - -bool MeshRenderSettings::setPointVisibility(bool b) -{ - return setPoint(MeshRenderInfo::Points::VISIBLE, b); -} - -bool MeshRenderSettings::setPointShadingNone() -{ - // return setPoint(MeshRenderInfo::Points::SHADING_NONE); - if (canPointBeVisible()) { - mDrawMode0 |= (1 << VCL_MRS_POINTS_SHADING_NONE); - mDrawMode0 &= ~(1 << VCL_MRS_POINTS_SHADING_VERT); - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setPointShadingPerVertex() -{ - // return setPoint(MeshRenderInfo::Points::SHADING_VERT); - if (canPointBeVisible()) { - mDrawMode0 &= ~(1 << VCL_MRS_POINTS_SHADING_NONE); - mDrawMode0 |= (1 << VCL_MRS_POINTS_SHADING_VERT); - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setPointColorPerVertex() -{ - // return setPoint(MeshRenderInfo::Points::COLOR_VERTEX); - if (canSurfaceColorBePerVertex()) { - mDrawMode0 |= (1 << VCL_MRS_POINTS_COLOR_VERTEX); - mDrawMode0 &= ~(1 << VCL_MRS_POINTS_COLOR_MESH); - mDrawMode0 &= ~(1 << VCL_MRS_POINTS_COLOR_USER); - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setPointColorPerMesh() -{ - // return setPoint(MeshRenderInfo::Points::COLOR_MESH); - if (canSurfaceColorBePerMesh()) { - mDrawMode0 &= ~(1 << VCL_MRS_POINTS_COLOR_VERTEX); - mDrawMode0 |= (1 << VCL_MRS_POINTS_COLOR_MESH); - mDrawMode0 &= ~(1 << VCL_MRS_POINTS_COLOR_USER); - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setPointColorUserDefined() -{ - // return setPoint(MeshRenderInfo::Points::COLOR_USER); - if (canPointBeVisible()) { - mDrawMode0 &= ~(1 << VCL_MRS_POINTS_COLOR_VERTEX); - mDrawMode0 &= ~(1 << VCL_MRS_POINTS_COLOR_MESH); - mDrawMode0 |= (1 << VCL_MRS_POINTS_COLOR_USER); - return true; - } - else { - return false; - } -} - bool MeshRenderSettings::setPointWidth(float width) { if (canPointBeVisible()) { @@ -224,216 +133,24 @@ bool MeshRenderSettings::setPointUserColor(const Color& c) } } -bool MeshRenderSettings::setSurfaceVisibility(bool b) -{ - if (canSurfaceBeVisible()) { - if (b) - mDrawMode0 |= VCL_MRS_DRAW_SURF; - else - mDrawMode0 &= ~VCL_MRS_DRAW_SURF; - return true; - } - else { - return false; - } -} - -/** - * @brief Unsets the shading of the surface (no light). - * Unsets automatically the smooth and flat shadings. - */ -bool MeshRenderSettings::setSurfaceShadingNone() -{ - if (canSurfaceBeVisible()) { - mDrawMode0 |= VCL_MRS_SURF_SHADING_NONE; - mDrawMode0 &= ~VCL_MRS_SURF_SHADING_FLAT; - mDrawMode0 &= ~VCL_MRS_SURF_SHADING_SMOOTH; - return true; - } - else { - return false; - } -} - -/** - * @brief Sets the shading of the surface flat (using triangle normals). - * Unsets automatically the none and smooth shading. - */ -bool MeshRenderSettings::setSurfaceShadingFlat() -{ - if (canSurfaceShadingBeFlat()) { - mDrawMode0 |= VCL_MRS_SURF_SHADING_FLAT; - mDrawMode0 &= ~VCL_MRS_SURF_SHADING_NONE; - mDrawMode0 &= ~VCL_MRS_SURF_SHADING_SMOOTH; - return true; - } - else { - return false; - } -} - -/** - * @brief Sets the shading of the surface smooth (using vertex normals). - * Unsets automatically the none and flat shading. - */ -bool MeshRenderSettings::setSurfaceShadingSmooth() -{ - if (canSurfaceShadingBeSmooth()) { - mDrawMode0 |= VCL_MRS_SURF_SHADING_SMOOTH; - mDrawMode0 &= ~VCL_MRS_SURF_SHADING_NONE; - mDrawMode0 &= ~VCL_MRS_SURF_SHADING_FLAT; - return true; - } - else { - return false; - } -} - -/** - * @brief Set the surface coloring per vertex (using the vertex colors). - * Unsets automatically the other possible surface colorizations: - * - color per face - * - color per mesh - * - color user defined - * - per vertex texture - * - per wedge texture - */ -bool MeshRenderSettings::setSurfaceColorPerVertex() -{ - if (canSurfaceColorBePerVertex()) { - mDrawMode0 |= VCL_MRS_SURF_COLOR_VERTEX; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_FACE; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_MESH; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_USER; - mDrawMode0 &= ~VCL_MRS_SURF_TEX_VERTEX; - mDrawMode0 &= ~VCL_MRS_SURF_TEX_WEDGE; - return true; - } - else { - return false; - } -} - -/** - * @brief Set the surface coloring per face (using the face colors). - * Unsets automatically the other possible surface colorizations: - * - color per vertex - * - color per mesh - * - color user defined - * - per vertex texture - * - per wedge texture - */ -bool MeshRenderSettings::setSurfaceColorPerFace() -{ - if (canSurfaceColorBePerFace()) { - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_VERTEX; - mDrawMode0 |= VCL_MRS_SURF_COLOR_FACE; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_MESH; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_USER; - mDrawMode0 &= ~VCL_MRS_SURF_TEX_VERTEX; - mDrawMode0 &= ~VCL_MRS_SURF_TEX_WEDGE; - return true; - } - else { - return false; - } -} - -/** - * @brief Set the surface coloring per mesh (using the mesh color). - * Unsets automatically the other possible surface colorizations: - * - color per vertex - * - color per face - * - color user defined - * - per vertex texture - * - per wedge texture - */ -bool MeshRenderSettings::setSurfaceColorPerMesh() -{ - if (canSurfaceColorBePerMesh()) { - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_VERTEX; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_FACE; - mDrawMode0 |= VCL_MRS_SURF_COLOR_MESH; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_USER; - mDrawMode0 &= ~VCL_MRS_SURF_TEX_VERTEX; - mDrawMode0 &= ~VCL_MRS_SURF_TEX_WEDGE; - return true; - } - else { - return false; - } -} - -/** - * @brief Set the surface coloring by the user defined color. - * To set the user defined color, you can use the - * setSurfaceColorUserDefined() function. - * * Unsets automatically the other possible surface colorizations: - * - color per vertex - * - color per face - * - color per mesh - * - per vertex texture - * - per wedge texture - */ -bool MeshRenderSettings::setSurfaceColorUserDefined() -{ - if (canSurfaceBeVisible()) { - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_VERTEX; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_FACE; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_MESH; - mDrawMode0 |= VCL_MRS_SURF_COLOR_USER; - mDrawMode0 &= ~VCL_MRS_SURF_TEX_VERTEX; - mDrawMode0 &= ~VCL_MRS_SURF_TEX_WEDGE; - return true; - } - else { - return false; - } -} - -/** - * @brief Set the surface texture per vertex texcoords. - * Unsets automatically the other possible surface colorizations: - * - color per vertex - * - color per face - * - color per mesh - * - color user defined - * - per wedge texture - */ -bool MeshRenderSettings::setSurfaceColorPerVertexTexcoords() -{ - if (canSurfaceColorBePerVertexTexcoords()) { - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_VERTEX; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_FACE; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_MESH; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_USER; - mDrawMode0 |= VCL_MRS_SURF_TEX_VERTEX; - mDrawMode0 &= ~VCL_MRS_SURF_TEX_WEDGE; - return true; - } - else { - return false; - } -} - -/** - * @brief Set the surface texture per wedge texcoords. - * Unsets automatically the other possible surface colorizations: - * - color per vertex - * - color per face - * - color per mesh - * - color user defined - * - per vertex texture - */ -bool MeshRenderSettings::setSurfaceColorPerWedgeTexcoords() +bool MeshRenderSettings::setSurface(MeshRenderInfo::Surface s, bool b) { - if (canSurfaceColorBePerWedgeTexcoords()) { - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_VERTEX; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_FACE; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_MESH; - mDrawMode0 &= ~VCL_MRS_SURF_COLOR_USER; - mDrawMode0 &= ~VCL_MRS_SURF_TEX_VERTEX; - mDrawMode0 |= VCL_MRS_SURF_TEX_WEDGE; + if (canSurface(s)) { // if the capability allows it + // get the range of the mutual exclusive settings for s + auto rng = MRI::surfaceExclusiveRange(s); + // if there are no mutual exclusive settings + if (rng.first == rng.second) { + // the setting could be true or false + // e.g. VISIBLE + mDrawMode.surface[rng.first] = b; + } + else { + // only one setting in the range can be true + // e.g. the range COLOR_* + for (auto i = rng.first; i <= rng.second; ++i) { + mDrawMode.surface[i] = toUnderlying(s) == i; + } + } return true; } else { @@ -468,76 +185,24 @@ bool MeshRenderSettings::setSurfaceUserColor(const Color& c) } } -bool MeshRenderSettings::setWireframeVisibility(bool b) -{ - if (canSurfaceBeVisible()) { - if (b) - mDrawMode0 |= VCL_MRS_DRAW_WIREFRAME; - else - mDrawMode0 &= ~VCL_MRS_DRAW_WIREFRAME; - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setWireframeShadingNone() -{ - if (canSurfaceBeVisible()) { - mDrawMode0 |= VCL_MRS_WIREFRAME_SHADING_NONE; - mDrawMode0 &= ~VCL_MRS_WIREFRAME_SHADING_VERT; - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setWireframeShadingPerVertex() -{ - if (canSurfaceBeVisible()) { - mDrawMode0 &= ~VCL_MRS_WIREFRAME_SHADING_NONE; - mDrawMode0 |= VCL_MRS_WIREFRAME_SHADING_VERT; - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setWireframeColorPerVertex() -{ - if (canWireframeColorBePerVertex()) { - mDrawMode0 |= VCL_MRS_WIREFRAME_COLOR_VERT; - mDrawMode0 &= ~VCL_MRS_WIREFRAME_COLOR_MESH; - mDrawMode0 &= ~VCL_MRS_WIREFRAME_COLOR_USER; - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setWireframeColorPerMesh() -{ - if (canWireframeColorBePerMesh()) { - mDrawMode0 &= ~VCL_MRS_WIREFRAME_COLOR_VERT; - mDrawMode0 |= VCL_MRS_WIREFRAME_COLOR_MESH; - mDrawMode0 &= ~VCL_MRS_WIREFRAME_COLOR_USER; - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setWireframeColorUserDefined() +bool MeshRenderSettings::setWireframe(MeshRenderInfo::Wireframe w, bool b) { - if (canSurfaceBeVisible()) { - mDrawMode0 &= ~VCL_MRS_WIREFRAME_COLOR_VERT; - mDrawMode0 &= ~VCL_MRS_WIREFRAME_COLOR_MESH; - mDrawMode0 |= VCL_MRS_WIREFRAME_COLOR_USER; + if (canWireframe(w)) { // if the capability allows it + // get the range of the mutual exclusive settings for w + auto rng = MRI::wireframeExclusiveRange(w); + // if there are no mutual exclusive settings + if (rng.first == rng.second) { + // the setting could be true or false + // e.g. VISIBLE + mDrawMode.wireframe[rng.first] = b; + } + else { + // only one setting in the range can be true + // e.g. the range COLOR_* + for (auto i = rng.first; i <= rng.second; ++i) { + mDrawMode.wireframe[i] = toUnderlying(w) == i; + } + } return true; } else { @@ -563,17 +228,6 @@ bool MeshRenderSettings::setWireframeUserColor( } } -bool MeshRenderSettings::setWireframeWidth(int width) -{ - if (canSurfaceBeVisible()) { - mWrfWidth = width; - return true; - } - else { - return false; - } -} - bool MeshRenderSettings::setWireframeUserColor(const Color& c) { if (canSurfaceBeVisible()) { @@ -588,13 +242,10 @@ bool MeshRenderSettings::setWireframeUserColor(const Color& c) } } -bool MeshRenderSettings::setBoundingBoxVisibility(bool b) +bool MeshRenderSettings::setWireframeWidth(int width) { - if (canBoundingBoxBeVisible()) { - if (b) - mDrawMode0 |= VCL_MRS_DRAW_BOUNDINGBOX; - else - mDrawMode0 &= ~VCL_MRS_DRAW_BOUNDINGBOX; + if (canSurfaceBeVisible()) { + mWrfWidth = width; return true; } else { @@ -602,13 +253,24 @@ bool MeshRenderSettings::setBoundingBoxVisibility(bool b) } } -bool MeshRenderSettings::setEdgesVisibility(bool b) +bool MeshRenderSettings::setEdges(MeshRenderInfo::Edges e, bool b) { - if (canEdgesBeVisible()) { - if (b) - mDrawMode1 |= VCL_MRS_DRAW_EDGES; - else - mDrawMode1 &= ~VCL_MRS_DRAW_EDGES; + if (canEdges(e)) { // if the capability allows it + // get the range of the mutual exclusive settings for e + auto rng = MRI::edgesExclusiveRange(e); + // if there are no mutual exclusive settings + if (rng.first == rng.second) { + // the setting could be true or false + // e.g. VISIBLE + mDrawMode.edges[rng.first] = b; + } + else { + // only one setting in the range can be true + // e.g. the range COLOR_* + for (auto i = rng.first; i <= rng.second; ++i) { + mDrawMode.edges[i] = toUnderlying(e) == i; + } + } return true; } else { @@ -616,80 +278,15 @@ bool MeshRenderSettings::setEdgesVisibility(bool b) } } -bool MeshRenderSettings::setEdgesShadingNone() +bool MeshRenderSettings::setEdgesUserColor(float r, float g, float b, float a) { if (canEdgesBeVisible()) { - mDrawMode1 |= VCL_MRS_EDGES_SHADING_NONE; - mDrawMode1 &= ~VCL_MRS_EDGES_SHADING_SMOOTH; - mDrawMode1 &= ~VCL_MRS_EDGES_SHADING_FLAT; - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setEdgesShadingSmooth() -{ - if (canEdgesShadingBeSmooth()) { - mDrawMode1 &= ~VCL_MRS_EDGES_SHADING_NONE; - mDrawMode1 |= VCL_MRS_EDGES_SHADING_SMOOTH; - mDrawMode1 &= ~VCL_MRS_EDGES_SHADING_FLAT; - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setEdgesShadingFlat() -{ - if (canEdgesShadingBeFlat()) { - mDrawMode1 &= ~VCL_MRS_EDGES_SHADING_NONE; - mDrawMode1 &= ~VCL_MRS_EDGES_SHADING_SMOOTH; - mDrawMode1 |= VCL_MRS_EDGES_SHADING_FLAT; - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setEdgesColorPerVertex() -{ - if (canEdgesColorBePerVertex()) { - mDrawMode1 |= VCL_MRS_EDGES_COLOR_VERTEX; - mDrawMode1 &= ~VCL_MRS_EDGES_COLOR_EDGE; - mDrawMode1 &= ~VCL_MRS_EDGES_COLOR_MESH; - mDrawMode1 &= ~VCL_MRS_EDGES_COLOR_USER; - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setEdgesColorPerEdge() -{ - if (canEdgesColorBePerEdge()) { - mDrawMode1 &= ~VCL_MRS_EDGES_COLOR_VERTEX; - mDrawMode1 |= VCL_MRS_EDGES_COLOR_EDGE; - mDrawMode1 &= ~VCL_MRS_EDGES_COLOR_MESH; - mDrawMode1 &= ~VCL_MRS_EDGES_COLOR_USER; - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setEdgesColorPerMesh() -{ - if (canEdgesColorBePerMesh()) { - mDrawMode1 &= ~VCL_MRS_EDGES_COLOR_VERTEX; - mDrawMode1 &= ~VCL_MRS_EDGES_COLOR_EDGE; - mDrawMode1 |= VCL_MRS_EDGES_COLOR_MESH; - mDrawMode1 &= ~VCL_MRS_EDGES_COLOR_USER; + vcl::Color c; + c.setRedF(r); + c.setGreenF(g); + c.setBlueF(b); + c.setAlphaF(a); + mEdgesUserColor = c.abgr(); return true; } else { @@ -697,13 +294,10 @@ bool MeshRenderSettings::setEdgesColorPerMesh() } } -bool MeshRenderSettings::setEdgesColorUserDefined() +bool MeshRenderSettings::setEdgesUserColor(const Color& c) { if (canEdgesBeVisible()) { - mDrawMode1 &= ~VCL_MRS_EDGES_COLOR_VERTEX; - mDrawMode1 &= ~VCL_MRS_EDGES_COLOR_EDGE; - mDrawMode1 &= ~VCL_MRS_EDGES_COLOR_MESH; - mDrawMode1 |= VCL_MRS_EDGES_COLOR_USER; + mEdgesUserColor = c.abgr(); return true; } else { @@ -722,39 +316,9 @@ bool MeshRenderSettings::setEdgesWidth(int width) } } -bool MeshRenderSettings::setEdgesUserColor(float r, float g, float b, float a) -{ - if (canEdgesBeVisible()) { - vcl::Color c; - c.setRedF(r); - c.setGreenF(g); - c.setBlueF(b); - c.setAlphaF(a); - mEdgesUserColor = c.abgr(); - return true; - } - else { - return false; - } -} - -bool MeshRenderSettings::setEdgesUserColor(const Color& c) -{ - if (canEdgesBeVisible()) { - mEdgesUserColor = c.abgr(); - return true; - } - else { - return false; - } -} - void MeshRenderSettings::setDefaultSettingsFromCapability() { - mDrawMode0 = 0; - - // default settings - ignored if not available - setWireframeColorUserDefined(); + mDrawMode.reset(); if (canBeVisible()) { setVisibility(true);