diff -r e34d6a30b96d -r 75efc3ba5a56 src/gl/compiler.cpp --- a/src/gl/compiler.cpp Mon Apr 10 14:46:36 2023 +0300 +++ b/src/gl/compiler.cpp Tue Apr 11 11:11:28 2023 +0300 @@ -114,33 +114,34 @@ )"; template -constexpr void pointsToRender(const PolygonElement& element, Fn func) +constexpr void pointsToRender(const PlainPolygonElement& element, Fn func) { - visitPolygon( - [&func](const LineSegment& edge) - { - func(edge.p1, glm::vec3{}); - func(edge.p2, glm::vec3{}); - }, - [&func](const Triangle& tri) - { - func(tri.p1, normalVector({tri.p3, tri.p1, tri.p2})); - func(tri.p2, normalVector({tri.p1, tri.p2, tri.p3})); - func(tri.p3, normalVector({tri.p2, tri.p3, tri.p1})); - }, - [&func](const Quadrilateral& quad) - { - func(quad.p1, normalVector({quad.p4, quad.p1, quad.p2})); - func(quad.p2, normalVector({quad.p1, quad.p2, quad.p3})); - func(quad.p3, normalVector({quad.p2, quad.p3, quad.p4})); - func(quad.p4, normalVector({quad.p3, quad.p4, quad.p1})); - }, - [&func](const ConditionalEdge& cedge) - { - func(cedge.p1, glm::vec3{}); - func(cedge.p2, glm::vec3{}); - }, - element); + if (const LineSegment* edge = std::get_if(&element)) + { + func(edge->p1, glm::vec3{}); + func(edge->p2, glm::vec3{}); + } + else if (std::holds_alternative(element)) + { + const Triangle& tri = std::get(element); + func(tri.p1, normalVector({tri.p3, tri.p1, tri.p2})); + func(tri.p2, normalVector(tri)); + func(tri.p3, normalVector({tri.p2, tri.p3, tri.p1})); + } + else if (std::holds_alternative(element)) + { + const Quadrilateral& quad = std::get(element); + func(quad.p1, normalVector({quad.p4, quad.p1, quad.p2})); + func(quad.p2, normalVector({quad.p1, quad.p2, quad.p3})); + func(quad.p3, normalVector({quad.p2, quad.p3, quad.p4})); + func(quad.p4, normalVector({quad.p3, quad.p4, quad.p1})); + } + else + { + const ConditionalEdge& conditional_edge = std::get(element); + func(conditional_edge.p1, glm::vec3{}); + func(conditional_edge.p2, glm::vec3{}); + } } void gl::buildShaders( @@ -211,7 +212,7 @@ } } -static constexpr gl::ArrayClass classifyPolygon(const PolygonElement& element) +static constexpr gl::ArrayClass classifyPolygon(const PlainPolygonElement& element) { return visitPolygon( [](const LineSegment&) { return gl::ArrayClass::Lines; }, @@ -267,7 +268,7 @@ { visitPoints([&result](const glm::vec3& p) { addPointToBox(result, p); - }, polygon); + }, polygon.element); }); return result; } @@ -287,10 +288,10 @@ } iterateModelPolygons(model, context, [&](const WithId& polygon) { - const int index = static_cast(classifyPolygon(polygon)); + const int index = static_cast(classifyPolygon(polygon.element)); std::vector& vertexBuffer = shaders->shaderObjects[index].cachedData; const QColor color = getColorForPolygon(polygon, preferences, colorTable); - pointsToRender(polygon, [&](const glm::vec3& point, const glm::vec3& normal){ + pointsToRender(polygon.element, [&](const glm::vec3& point, const glm::vec3& normal){ gl::ModelShaders::Vertex& vertex = vertexBuffer.emplace_back(); vertex.position = point; vertex.normal = normal;