src/gl/compiler.cpp

changeset 150
b6cbba6e29a1
parent 139
72098474d362
child 189
815fbaae9cb2
equal deleted inserted replaced
148:e1ced2523cad 150:b6cbba6e29a1
123 fColor = vColor; 123 fColor = vColor;
124 } 124 }
125 } 125 }
126 )"; 126 )";
127 127
128 gl::Compiler::Compiler(const ldraw::ColorTable& colorTable, QObject* parent) : 128 gl::Compiler::Compiler(Model *model, const ldraw::ColorTable& colorTable, QObject* parent) :
129 QObject{parent}, 129 QObject{parent},
130 model{model},
130 colorTable{colorTable} 131 colorTable{colorTable}
131 { 132 {
132 } 133 }
133 134
134 gl::Compiler::~Compiler() 135 gl::Compiler::~Compiler()
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 {

mercurial