204 } |
205 } |
205 this->initialized = true; |
206 this->initialized = true; |
206 } |
207 } |
207 } |
208 } |
208 |
209 |
209 void gl::Compiler::build(Model* model, DocumentManager* context, const gl::RenderPreferences& preferences) |
210 void gl::Compiler::build(DocumentManager* context, const gl::RenderPreferences& preferences) |
210 { |
211 { |
211 this->boundingBox = {}; |
212 this->boundingBox = {}; |
212 std::vector<Vertex> vboData[gl::NUM_POLYGON_TYPES]; |
213 std::vector<Vertex> vboData[gl::NUM_POLYGON_TYPES]; |
213 const std::vector<gl::Polygon> polygons = model->getPolygons(context); |
214 std::optional<ModelId> modelId = context->findIdForModel(this->model); |
214 for (const gl::Polygon& polygon : polygons) |
215 if (modelId.has_value()) |
215 { |
216 { |
216 this->buildPolygon(polygon, vboData, preferences); |
217 PolygonCache* polygonBuilder = context->getPolygonCacheForModel(modelId.value()); |
217 } |
218 if (polygonBuilder != nullptr) |
218 for (int arrayId = 0; arrayId < gl::NUM_POLYGON_TYPES; arrayId += 1) |
219 { |
219 { |
220 const std::vector<gl::Polygon> polygons = polygonBuilder->getPolygons(context); |
220 auto& buffer = this->glObjects[arrayId].buffer; |
221 for (const gl::Polygon& polygon : polygons) |
221 auto& vector = vboData[arrayId]; |
222 { |
222 this->storedVertexCounts[arrayId] = vector.size(); |
223 this->buildPolygon(polygon, vboData, preferences); |
223 this->glObjects[arrayId].cachedData = vector; // todo: get rid of this copy |
224 } |
224 buffer.bind(); |
225 for (int arrayId = 0; arrayId < gl::NUM_POLYGON_TYPES; arrayId += 1) |
225 buffer.allocate(vector.data(), static_cast<int>(vector.size() * sizeof vector[0])); |
226 { |
226 buffer.release(); |
227 auto& buffer = this->glObjects[arrayId].buffer; |
|
228 auto& vector = vboData[arrayId]; |
|
229 this->storedVertexCounts[arrayId] = vector.size(); |
|
230 this->glObjects[arrayId].cachedData = vector; // todo: get rid of this copy |
|
231 buffer.bind(); |
|
232 buffer.allocate(vector.data(), static_cast<int>(vector.size() * sizeof vector[0])); |
|
233 buffer.release(); |
|
234 } |
|
235 } |
227 } |
236 } |
228 } |
237 } |
229 |
238 |
230 gl::ArrayClass classifyPolygon(const gl::Polygon& polygon) |
239 gl::ArrayClass classifyPolygon(const gl::Polygon& polygon) |
231 { |
240 { |