--- a/src/gl/compiler.cpp Thu Jun 09 11:51:42 2022 +0300 +++ b/src/gl/compiler.cpp Thu Jun 09 13:32:55 2022 +0300 @@ -196,20 +196,14 @@ } } -static gl::ArrayClass classifyPolygon(const gl::Polygon& polygon) +static constexpr gl::ArrayClass classifyPolygon(const PolygonElement& element) { - switch (polygon.type) - { - case gl::Polygon::EdgeLine: - return gl::ArrayClass::Lines; - case gl::Polygon::Triangle: - return gl::ArrayClass::Triangles; - case gl::Polygon::Quadrilateral: - return gl::ArrayClass::Quads; - case gl::Polygon::ConditionalEdge: - return gl::ArrayClass::ConditionalLines; - } - return gl::ArrayClass::Lines; + return visitPolygon<gl::ArrayClass>( + [](const LineSegment&) { return gl::ArrayClass::Lines; }, + [](const Triangle&) { return gl::ArrayClass::Triangles; }, + [](const Quadrilateral&) { return gl::ArrayClass::Quads; }, + [](const ConditionalEdge&) { return gl::ArrayClass::ConditionalLines; }, + element); } template<typename Fn> @@ -221,7 +215,7 @@ PolygonCache* cache = context->getPolygonCacheForModel(modelId.value()); if (cache != nullptr) { - for (const gl::Polygon& polygon : getCachedPolygons(cache, model, context)) + for (const WithId<PolygonElement>& polygon : getCachedPolygons(cache, model, context)) { fn(polygon); } @@ -230,7 +224,7 @@ } static QColor getColorForPolygon( - const gl::Polygon& polygon, + const PolygonElement& polygon, const gl::RenderPreferences& preferences, const ColorTable& colorTable) { @@ -259,12 +253,11 @@ BoundingBox gl::boundingBoxForModel(Model* model, DocumentManager* context) { BoundingBox result = emptyBoundingBox; - iterateModelPolygons(model, context, [&](const gl::Polygon& polygon) + iterateModelPolygons(model, context, [&](const PolygonElement& polygon) { - for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) - { - addPointToBox(result, polygon.vertices[i]); - } + visitPoints( + [&result](const glm::vec3& p) { addPointToBox(result, p); }, + polygon); }); return result; } @@ -282,7 +275,7 @@ for (gl::ModelShaders::ShaderObject& shader : shaders->shaderObjects) { shader.cachedData.clear(); } - iterateModelPolygons(model, context, [&](const Polygon& polygon) + iterateModelPolygons(model, context, [&](const PolygonElement& polygon) { const int index = static_cast<int>(classifyPolygon(polygon)); std::vector<gl::ModelShaders::Vertex>& vertexBuffer = shaders->shaderObjects[index].cachedData;