src/gl/compiler.cpp

changeset 374
75efc3ba5a56
parent 338
719b909a7d2b
child 376
3cef3b016330
--- 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<typename Fn>
-constexpr void pointsToRender(const PolygonElement& element, Fn func)
+constexpr void pointsToRender(const PlainPolygonElement& element, Fn func)
 {
-	visitPolygon<void>(
-		[&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<LineSegment>(&element))
+	{
+		func(edge->p1, glm::vec3{});
+		func(edge->p2, glm::vec3{});
+	}
+	else if (std::holds_alternative<Triangle>(element))
+	{
+		const Triangle& tri = std::get<Triangle>(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<Quadrilateral>(element))
+	{
+		const Quadrilateral& quad = std::get<Quadrilateral>(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<ConditionalEdge>(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<gl::ArrayClass>(
 		[](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<PolygonElement>& polygon)
 	{
-		const int index = static_cast<int>(classifyPolygon(polygon));
+		const int index = static_cast<int>(classifyPolygon(polygon.element));
 		std::vector<gl::ModelShaders::Vertex>& 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;

mercurial