diff -r e1ced2523cad -r b6cbba6e29a1 src/gl/compiler.cpp --- 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 vboData[gl::NUM_POLYGON_TYPES]; - const std::vector 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 = 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(vector.size() * sizeof vector[0])); - buffer.release(); + PolygonCache* polygonBuilder = context->getPolygonCacheForModel(modelId.value()); + if (polygonBuilder != nullptr) + { + const std::vector 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(vector.size() * sizeof vector[0])); + buffer.release(); + } + } } }