12 extern_cfg (Bool, gl_blackedges); |
12 extern_cfg (Bool, gl_blackedges); |
13 static QList<short> g_warnedColors; |
13 static QList<short> g_warnedColors; |
14 GLCompiler g_vertexCompiler; |
14 GLCompiler g_vertexCompiler; |
15 |
15 |
16 // ============================================================================= |
16 // ============================================================================= |
17 // ----------------------------------------------------------------------------- |
17 // |
18 GLCompiler::GLCompiler() : |
18 GLCompiler::GLCompiler() : |
19 m_file (null) |
19 m_file (null) |
20 { |
20 { |
21 needMerge(); |
21 needMerge(); |
22 } |
22 } |
25 |
25 |
26 // ============================================================================= |
26 // ============================================================================= |
27 // Note: we use the top level object's color but the draw object's vertices. |
27 // Note: we use the top level object's color but the draw object's vertices. |
28 // This is so that the index color is generated correctly - it has to reference |
28 // This is so that the index color is generated correctly - it has to reference |
29 // the top level object's ID. This is crucial for picking to work. |
29 // the top level object's ID. This is crucial for picking to work. |
30 // ----------------------------------------------------------------------------- |
30 // |
31 void GLCompiler::compilePolygon (LDObject* drawobj, LDObject* trueobj, QList< GLCompiler::CompiledTriangle >& data) |
31 void GLCompiler::compilePolygon (LDObject* drawobj, LDObject* trueobj, QList< GLCompiler::CompiledTriangle >& data) |
32 { |
32 { |
33 const QColor pickColor = getObjectColor (trueobj, PickColor); |
33 const QColor pickColor = getObjectColor (trueobj, PickColor); |
34 LDObject::Type type = drawobj->getType(); |
34 LDObject::Type type = drawobj->getType(); |
35 LDObjectList objs; |
35 LDObjectList objs; |
125 |
125 |
126 needMerge(); |
126 needMerge(); |
127 } |
127 } |
128 |
128 |
129 // ============================================================================= |
129 // ============================================================================= |
130 // ----------------------------------------------------------------------------- |
130 // |
131 void GLCompiler::compileSubObject (LDObject* obj, LDObject* topobj, GLCompiler::PolygonList& data) |
131 void GLCompiler::compileSubObject (LDObject* obj, LDObject* topobj, GLCompiler::PolygonList& data) |
132 { |
132 { |
133 LDObjectList objs; |
133 LDObjectList objs; |
134 |
134 |
135 switch (obj->getType()) |
135 switch (obj->getType()) |
171 {} break; |
171 {} break; |
172 } |
172 } |
173 } |
173 } |
174 |
174 |
175 // ============================================================================= |
175 // ============================================================================= |
176 // ----------------------------------------------------------------------------- |
176 // |
177 void GLCompiler::compileDocument() |
177 void GLCompiler::compileDocument() |
178 { |
178 { |
179 for (LDObject * obj : m_file->getObjects()) |
179 for (LDObject * obj : m_file->getObjects()) |
180 compileObject (obj); |
180 compileObject (obj); |
181 } |
181 } |
182 |
182 |
183 // ============================================================================= |
183 // ============================================================================= |
184 // ----------------------------------------------------------------------------- |
184 // |
185 void GLCompiler::forgetObject (LDObject* obj) |
185 void GLCompiler::forgetObject (LDObject* obj) |
186 { |
186 { |
187 auto it = m_objArrays.find (obj); |
187 auto it = m_objArrays.find (obj); |
188 |
188 |
189 if (it != m_objArrays.end()) |
189 if (it != m_objArrays.end()) |
191 |
191 |
192 m_objArrays.remove (obj); |
192 m_objArrays.remove (obj); |
193 } |
193 } |
194 |
194 |
195 // ============================================================================= |
195 // ============================================================================= |
196 // ----------------------------------------------------------------------------- |
196 // |
197 void GLCompiler::setFile (LDDocument* file) |
197 void GLCompiler::setFile (LDDocument* file) |
198 { |
198 { |
199 m_file = file; |
199 m_file = file; |
200 } |
200 } |
201 |
201 |
202 // ============================================================================= |
202 // ============================================================================= |
203 // ----------------------------------------------------------------------------- |
203 // |
204 const GLCompiler::Array* GLCompiler::getMergedBuffer (GL::VAOType type) |
204 const GLCompiler::Array* GLCompiler::getMergedBuffer (GL::VAOType type) |
205 { |
205 { |
206 // If there are objects staged for compilation, compile them now. |
206 // If there are objects staged for compilation, compile them now. |
207 if (m_staged.size() > 0) |
207 if (m_staged.size() > 0) |
208 { |
208 { |
236 return &m_mainArrays[type]; |
236 return &m_mainArrays[type]; |
237 } |
237 } |
238 |
238 |
239 // ============================================================================= |
239 // ============================================================================= |
240 // This turns a compiled triangle into usable VAO vertices |
240 // This turns a compiled triangle into usable VAO vertices |
241 // ----------------------------------------------------------------------------- |
241 // |
242 GLCompiler::Array* GLCompiler::postprocess (const CompiledTriangle& poly, GLRenderer::VAOType type) |
242 GLCompiler::Array* GLCompiler::postprocess (const CompiledTriangle& poly, GLRenderer::VAOType type) |
243 { |
243 { |
244 Array* va = new Array; |
244 Array* va = new Array; |
245 Array verts; |
245 Array verts; |
246 |
246 |
247 for (int i = 0; i < poly.numVerts; ++i) |
247 for (int i = 0; i < poly.numVerts; ++i) |
248 { |
248 { |
249 alias v0 = poly.verts[i]; |
249 alias v0 = poly.verts[i]; |
250 Vertex v; |
250 VAO v; |
251 v.x = v0.x(); |
251 v.x = v0.x(); |
252 v.y = v0.y(); |
252 v.y = v0.y(); |
253 v.z = v0.z(); |
253 v.z = v0.z(); |
254 |
254 |
255 switch (type) |
255 switch (type) |
277 |
277 |
278 if (type == GL::EBFCArray) |
278 if (type == GL::EBFCArray) |
279 { |
279 { |
280 int32 rgb = getColorRGB (getObjectColor (poly.obj, BFCFront)); |
280 int32 rgb = getColorRGB (getObjectColor (poly.obj, BFCFront)); |
281 |
281 |
282 for (Vertex v : verts) |
282 for (VAO vao : verts) |
283 { |
283 { |
284 v.color = rgb; |
284 vao.color = rgb; |
285 *va << v; |
285 *va << vao; |
286 } |
286 } |
287 |
287 |
288 rgb = getColorRGB (getObjectColor (poly.obj, BFCBack)); |
288 rgb = getColorRGB (getObjectColor (poly.obj, BFCBack)); |
289 |
289 |
290 for (int i = verts.size() - 1; i >= 0; --i) |
290 for (int i = verts.size() - 1; i >= 0; --i) |
291 { |
291 { |
292 Vertex v = verts[i]; |
292 VAO vao = verts[i]; |
293 v.color = rgb; |
293 vao.color = rgb; |
294 *va << v; |
294 *va << vao; |
295 } |
295 } |
296 } |
296 } |
297 else |
297 else |
298 *va = verts; |
298 *va = verts; |
299 |
299 |
300 return va; |
300 return va; |
301 } |
301 } |
302 |
302 |
303 // ============================================================================= |
303 // ============================================================================= |
304 // ----------------------------------------------------------------------------- |
304 // |
305 uint32 GLCompiler::getColorRGB (const QColor& color) |
305 uint32 GLCompiler::getColorRGB (const QColor& color) |
306 { |
306 { |
307 return |
307 return |
308 (color.red() & 0xFF) << 0x00 | |
308 (color.red() & 0xFF) << 0x00 | |
309 (color.green() & 0xFF) << 0x08 | |
309 (color.green() & 0xFF) << 0x08 | |
310 (color.blue() & 0xFF) << 0x10 | |
310 (color.blue() & 0xFF) << 0x10 | |
311 (color.alpha() & 0xFF) << 0x18; |
311 (color.alpha() & 0xFF) << 0x18; |
312 } |
312 } |
313 |
313 |
314 // ============================================================================= |
314 // ============================================================================= |
315 // ----------------------------------------------------------------------------- |
315 // |
316 QColor GLCompiler::getObjectColor (LDObject* obj, ColorType colotype) const |
316 QColor GLCompiler::getObjectColor (LDObject* obj, ColorType colotype) const |
317 { |
317 { |
318 QColor qcol; |
318 QColor qcol; |
319 |
319 |
320 if (!obj->isColored()) |
320 if (!obj->isColored()) |
401 |
401 |
402 return qcol; |
402 return qcol; |
403 } |
403 } |
404 |
404 |
405 // ============================================================================= |
405 // ============================================================================= |
406 // ----------------------------------------------------------------------------- |
406 // |
407 void GLCompiler::needMerge() |
407 void GLCompiler::needMerge() |
408 { |
408 { |
409 // Set all of m_changed to true |
409 // Set all of m_changed to true |
410 memset (m_changed, 0xFF, sizeof m_changed); |
410 memset (m_changed, 0xFF, sizeof m_changed); |
411 } |
411 } |
412 |
412 |
413 // ============================================================================= |
413 // ============================================================================= |
414 // ----------------------------------------------------------------------------- |
414 // |
415 void GLCompiler::initObject (LDObject* obj) |
415 void GLCompiler::initObject (LDObject* obj) |
416 { |
416 { |
417 if (m_objArrays.find (obj) == m_objArrays.end()) |
417 if (m_objArrays.find (obj) == m_objArrays.end()) |
418 m_objArrays[obj] = new Array[GL::ENumArrays]; |
418 m_objArrays[obj] = new Array[GL::ENumArrays]; |
419 } |
419 } |
420 |
420 |
421 // ============================================================================= |
421 // ============================================================================= |
422 // ----------------------------------------------------------------------------- |
422 // |
423 void GLCompiler::stageForCompilation (LDObject* obj) |
423 void GLCompiler::stageForCompilation (LDObject* obj) |
424 { |
424 { |
425 m_staged << obj; |
425 m_staged << obj; |
426 removeDuplicates (m_staged); |
426 removeDuplicates (m_staged); |
427 } |
427 } |