src/gl/compiler.cpp

changeset 210
232e7634cc8a
parent 205
1a4342d80de7
child 211
b27b90fb993f
equal deleted inserted replaced
209:c93e4a1eaadb 210:232e7634cc8a
194 } 194 }
195 modelShaders->initialized = true; 195 modelShaders->initialized = true;
196 } 196 }
197 } 197 }
198 198
199 static gl::ArrayClass classifyPolygon(const gl::Polygon& polygon) 199 static constexpr gl::ArrayClass classifyPolygon(const PolygonElement& element)
200 { 200 {
201 switch (polygon.type) 201 return visitPolygon<gl::ArrayClass>(
202 { 202 [](const LineSegment&) { return gl::ArrayClass::Lines; },
203 case gl::Polygon::EdgeLine: 203 [](const Triangle&) { return gl::ArrayClass::Triangles; },
204 return gl::ArrayClass::Lines; 204 [](const Quadrilateral&) { return gl::ArrayClass::Quads; },
205 case gl::Polygon::Triangle: 205 [](const ConditionalEdge&) { return gl::ArrayClass::ConditionalLines; },
206 return gl::ArrayClass::Triangles; 206 element);
207 case gl::Polygon::Quadrilateral:
208 return gl::ArrayClass::Quads;
209 case gl::Polygon::ConditionalEdge:
210 return gl::ArrayClass::ConditionalLines;
211 }
212 return gl::ArrayClass::Lines;
213 } 207 }
214 208
215 template<typename Fn> 209 template<typename Fn>
216 void iterateModelPolygons(Model* model, DocumentManager* context, Fn&& fn) 210 void iterateModelPolygons(Model* model, DocumentManager* context, Fn&& fn)
217 { 211 {
219 if (modelId.has_value()) 213 if (modelId.has_value())
220 { 214 {
221 PolygonCache* cache = context->getPolygonCacheForModel(modelId.value()); 215 PolygonCache* cache = context->getPolygonCacheForModel(modelId.value());
222 if (cache != nullptr) 216 if (cache != nullptr)
223 { 217 {
224 for (const gl::Polygon& polygon : getCachedPolygons(cache, model, context)) 218 for (const WithId<PolygonElement>& polygon : getCachedPolygons(cache, model, context))
225 { 219 {
226 fn(polygon); 220 fn(polygon);
227 } 221 }
228 } 222 }
229 } 223 }
230 } 224 }
231 225
232 static QColor getColorForPolygon( 226 static QColor getColorForPolygon(
233 const gl::Polygon& polygon, 227 const PolygonElement& polygon,
234 const gl::RenderPreferences& preferences, 228 const gl::RenderPreferences& preferences,
235 const ColorTable& colorTable) 229 const ColorTable& colorTable)
236 { 230 {
237 QColor color; 231 QColor color;
238 // For normal colors, use the polygon's color. 232 // For normal colors, use the polygon's color.
257 * @brief Computes the minimum bounding box for a model 251 * @brief Computes the minimum bounding box for a model
258 */ 252 */
259 BoundingBox gl::boundingBoxForModel(Model* model, DocumentManager* context) 253 BoundingBox gl::boundingBoxForModel(Model* model, DocumentManager* context)
260 { 254 {
261 BoundingBox result = emptyBoundingBox; 255 BoundingBox result = emptyBoundingBox;
262 iterateModelPolygons(model, context, [&](const gl::Polygon& polygon) 256 iterateModelPolygons(model, context, [&](const PolygonElement& polygon)
263 { 257 {
264 for (unsigned int i = 0; i < polygon.numPolygonVertices(); i += 1) 258 visitPoints(
265 { 259 [&result](const glm::vec3& p) { addPointToBox(result, p); },
266 addPointToBox(result, polygon.vertices[i]); 260 polygon);
267 }
268 }); 261 });
269 return result; 262 return result;
270 } 263 }
271 264
272 /** 265 /**
280 const gl::RenderPreferences& preferences) 273 const gl::RenderPreferences& preferences)
281 { 274 {
282 for (gl::ModelShaders::ShaderObject& shader : shaders->shaderObjects) { 275 for (gl::ModelShaders::ShaderObject& shader : shaders->shaderObjects) {
283 shader.cachedData.clear(); 276 shader.cachedData.clear();
284 } 277 }
285 iterateModelPolygons(model, context, [&](const Polygon& polygon) 278 iterateModelPolygons(model, context, [&](const PolygonElement& polygon)
286 { 279 {
287 const int index = static_cast<int>(classifyPolygon(polygon)); 280 const int index = static_cast<int>(classifyPolygon(polygon));
288 std::vector<gl::ModelShaders::Vertex>& vertexBuffer = shaders->shaderObjects[index].cachedData; 281 std::vector<gl::ModelShaders::Vertex>& vertexBuffer = shaders->shaderObjects[index].cachedData;
289 auto vertexRing = iter::ring(polygon.vertices, polygon.numPolygonVertices()); 282 auto vertexRing = iter::ring(polygon.vertices, polygon.numPolygonVertices());
290 reserveMore(vertexBuffer, polygon.numPolygonVertices()); 283 reserveMore(vertexBuffer, polygon.numPolygonVertices());

mercurial