75 connect(renderer->model(), SIGNAL(objectModified(LDObject*)), this, SLOT(compileObject(LDObject*))); |
75 connect(renderer->model(), SIGNAL(objectModified(LDObject*)), this, SLOT(compileObject(LDObject*))); |
76 connect(renderer->model(), SIGNAL(aboutToRemoveObject(LDObject*)), this, SLOT(forgetObject(LDObject*)), Qt::DirectConnection); |
76 connect(renderer->model(), SIGNAL(aboutToRemoveObject(LDObject*)), this, SLOT(forgetObject(LDObject*)), Qt::DirectConnection); |
77 connect(renderer, SIGNAL(objectHighlightingChanged(LDObject*)), this, SLOT(compileObject(LDObject*))); |
77 connect(renderer, SIGNAL(objectHighlightingChanged(LDObject*)), this, SLOT(compileObject(LDObject*))); |
78 connect(m_window, SIGNAL(gridChanged()), this, SLOT(recompile())); |
78 connect(m_window, SIGNAL(gridChanged()), this, SLOT(recompile())); |
79 |
79 |
80 for (LDObject* object : renderer->model()->objects()) |
80 for (QModelIndex index : renderer->model()->indices()) |
81 stageForCompilation(object); |
81 { |
|
82 print("%1", index); |
|
83 stageForCompilation(index); |
|
84 } |
82 } |
85 } |
83 |
86 |
84 /* |
87 /* |
85 * Initializes the VBOs after OpenGL is initialized. |
88 * Initializes the VBOs after OpenGL is initialized. |
86 */ |
89 */ |
226 } |
229 } |
227 |
230 |
228 /* |
231 /* |
229 * Stages the given object for compilation. |
232 * Stages the given object for compilation. |
230 */ |
233 */ |
231 void GLCompiler::stageForCompilation(LDObject* obj) |
234 void GLCompiler::stageForCompilation(QModelIndex index) |
232 { |
235 { |
233 m_staged << obj; |
236 m_staged.insert(index); |
234 } |
237 } |
235 |
238 |
236 /* |
239 /* |
237 * Removes an object from the set of objects to be compiled. |
240 * Removes an object from the set of objects to be compiled. |
238 */ |
241 */ |
239 void GLCompiler::unstage(LDObject* obj) |
242 void GLCompiler::unstage(QModelIndex index) |
240 { |
243 { |
241 m_staged.remove (obj); |
244 m_staged.remove(index); |
|
245 } |
|
246 |
|
247 LDObject* GLCompiler::resolveObject(const QModelIndex& index) |
|
248 { |
|
249 return m_renderer->model()->data(index, Model::ObjectRole).value<LDObject*>(); |
242 } |
250 } |
243 |
251 |
244 /* |
252 /* |
245 * Compiles all staged objects. |
253 * Compiles all staged objects. |
246 */ |
254 */ |
247 void GLCompiler::compileStaged() |
255 void GLCompiler::compileStaged() |
248 { |
256 { |
249 for (LDObject* object : m_staged) |
257 for (const QModelIndex& index : m_staged) |
250 compileObject(object); |
258 compileObject(index); |
251 |
259 |
252 m_staged.clear(); |
260 m_staged.clear(); |
253 } |
261 } |
254 |
262 |
255 /* |
263 /* |
263 if (m_vboChanged[vbonum]) |
271 if (m_vboChanged[vbonum]) |
264 { |
272 { |
265 // Merge the VBO into a vector of floats. |
273 // Merge the VBO into a vector of floats. |
266 QVector<GLfloat> vbodata; |
274 QVector<GLfloat> vbodata; |
267 |
275 |
268 for (auto it = m_objectInfo.begin(); it != m_objectInfo.end();) |
276 for ( |
269 { |
277 auto iterator = m_objectInfo.begin(); |
270 if (it.key() == nullptr) |
278 iterator != m_objectInfo.end(); |
271 { |
279 ) { |
272 it = m_objectInfo.erase(it); |
280 if (not iterator.key().isValid()) |
|
281 { |
|
282 iterator = m_objectInfo.erase(iterator); |
273 } |
283 } |
274 else |
284 else |
275 { |
285 { |
276 if (not it.key()->isHidden()) |
286 LDObject* object = resolveObject(iterator.key()); |
277 vbodata += it->data[vbonum]; |
287 if (not object->isHidden()) |
278 |
288 vbodata += iterator->data[vbonum]; |
279 ++it; |
289 |
|
290 ++iterator; |
280 } |
291 } |
281 } |
292 } |
282 |
293 |
283 // Transfer the VBO to the graphics processor. |
294 // Transfer the VBO to the graphics processor. |
284 glBindBuffer (GL_ARRAY_BUFFER, m_vbo[vbonum]); |
295 glBindBuffer (GL_ARRAY_BUFFER, m_vbo[vbonum]); |
291 } |
302 } |
292 |
303 |
293 /* |
304 /* |
294 * Removes the data related to the given object. |
305 * Removes the data related to the given object. |
295 */ |
306 */ |
296 void GLCompiler::dropObjectInfo(LDObject* object) |
307 void GLCompiler::dropObjectInfo(const QModelIndex& index) |
297 { |
308 { |
298 if (m_objectInfo.contains(object)) |
309 if (m_objectInfo.contains(index)) |
299 { |
310 { |
300 // If we have data relating to this object, remove it. The VBOs have changed now and need to be merged. |
311 // If we have data relating to this object, remove it. |
301 m_objectInfo.remove(object); |
312 // The VBOs have changed now and need to be merged. |
|
313 m_objectInfo.remove(index); |
302 needMerge(); |
314 needMerge(); |
303 } |
315 } |
304 } |
316 } |
305 |
317 |
306 /* |
318 /* |
307 * Makes the compiler forget about the given object completely. |
319 * Makes the compiler forget about the given object completely. |
308 */ |
320 */ |
309 void GLCompiler::forgetObject(LDObject* object) |
321 void GLCompiler::forgetObject(QModelIndex index) |
310 { |
322 { |
311 dropObjectInfo(object); |
323 dropObjectInfo(index); |
312 unstage(object); |
324 unstage(index); |
313 } |
325 } |
314 |
326 |
315 /* |
327 /* |
316 * Compiles a single object. |
328 * Compiles a single object. |
317 */ |
329 */ |
318 void GLCompiler::compileObject(LDObject* object) |
330 void GLCompiler::compileObject(QModelIndex index) |
319 { |
331 { |
|
332 LDObject* object = resolveObject(index); |
|
333 |
320 if (object == nullptr) |
334 if (object == nullptr) |
321 return; |
335 return; |
322 |
336 |
323 ObjectVboData info; |
337 ObjectVboData info; |
324 dropObjectInfo(object); |
338 dropObjectInfo(index); |
325 |
339 |
326 switch (object->type()) |
340 switch (object->type()) |
327 { |
341 { |
328 // Note: We cannot split quads into triangles here, it would mess up the wireframe view. |
342 // Note: We cannot split quads into triangles here, it would mess up the |
329 // Quads must go into separate vbos. |
343 // wireframe view. Quads must go into separate vbos. |
330 case LDObjectType::Triangle: |
344 case LDObjectType::Triangle: |
331 case LDObjectType::Quadrilateral: |
345 case LDObjectType::Quadrilateral: |
332 case LDObjectType::EdgeLine: |
346 case LDObjectType::EdgeLine: |
333 case LDObjectType::ConditionalEdge: |
347 case LDObjectType::ConditionalEdge: |
334 { |
348 { |