src/gl/compiler.cpp

changeset 150
b6cbba6e29a1
parent 139
72098474d362
child 189
815fbaae9cb2
--- a/src/gl/compiler.cpp	Tue Nov 02 15:43:57 2021 +0200
+++ b/src/gl/compiler.cpp	Thu Mar 03 11:42:52 2022 +0200
@@ -125,8 +125,9 @@
 }
 )";
 
-gl::Compiler::Compiler(const ldraw::ColorTable& colorTable, QObject* parent) :
+gl::Compiler::Compiler(Model *model, const ldraw::ColorTable& colorTable, QObject* parent) :
 	QObject{parent},
+	model{model},
 	colorTable{colorTable}
 {
 }
@@ -206,24 +207,32 @@
 	}
 }
 
-void gl::Compiler::build(Model* model, DocumentManager* context, const gl::RenderPreferences& preferences)
+void gl::Compiler::build(DocumentManager* context, const gl::RenderPreferences& preferences)
 {
 	this->boundingBox = {};
 	std::vector<Vertex> vboData[gl::NUM_POLYGON_TYPES];
-	const std::vector<gl::Polygon> polygons = model->getPolygons(context);
-	for (const gl::Polygon& polygon : polygons)
-	{
-		this->buildPolygon(polygon, vboData, preferences);
-	}
-	for (int arrayId = 0; arrayId < gl::NUM_POLYGON_TYPES; arrayId += 1)
+	std::optional<ModelId> modelId = context->findIdForModel(this->model);
+	if (modelId.has_value())
 	{
-		auto& buffer = this->glObjects[arrayId].buffer;
-		auto& vector = vboData[arrayId];
-		this->storedVertexCounts[arrayId] = vector.size();
-		this->glObjects[arrayId].cachedData = vector; // todo: get rid of this copy
-		buffer.bind();
-		buffer.allocate(vector.data(), static_cast<int>(vector.size() * sizeof vector[0]));
-		buffer.release();
+		PolygonCache* polygonBuilder = context->getPolygonCacheForModel(modelId.value());
+		if (polygonBuilder != nullptr)
+		{
+			const std::vector<gl::Polygon> polygons = polygonBuilder->getPolygons(context);
+			for (const gl::Polygon& polygon : polygons)
+			{
+				this->buildPolygon(polygon, vboData, preferences);
+			}
+			for (int arrayId = 0; arrayId < gl::NUM_POLYGON_TYPES; arrayId += 1)
+			{
+				auto& buffer = this->glObjects[arrayId].buffer;
+				auto& vector = vboData[arrayId];
+				this->storedVertexCounts[arrayId] = vector.size();
+				this->glObjects[arrayId].cachedData = vector; // todo: get rid of this copy
+				buffer.bind();
+				buffer.allocate(vector.data(), static_cast<int>(vector.size() * sizeof vector[0]));
+				buffer.release();
+			}
+		}
 	}
 }
 

mercurial