src/glCompiler.cc

changeset 717
fdc285e5952f
parent 716
639a900999bc
child 721
4cf0f6c9082d
equal deleted inserted replaced
716:639a900999bc 717:fdc285e5952f
25 #include "ldDocument.h" 25 #include "ldDocument.h"
26 #include "miscallenous.h" 26 #include "miscallenous.h"
27 #include "glRenderer.h" 27 #include "glRenderer.h"
28 #include "dialogs.h" 28 #include "dialogs.h"
29 29
30 cfg (String, gl_selectcolor, "#0080FF")
31
32 struct GLErrorInfo 30 struct GLErrorInfo
33 { 31 {
34 GLenum value; 32 GLenum value;
35 QString text; 33 QString text;
36 }; 34 };
45 { GL_OUT_OF_MEMORY, "Out of memory" }, 43 { GL_OUT_OF_MEMORY, "Out of memory" },
46 { GL_STACK_UNDERFLOW, "The operation would have caused an underflow" }, 44 { GL_STACK_UNDERFLOW, "The operation would have caused an underflow" },
47 { GL_STACK_OVERFLOW, "The operation would have caused an overflow" }, 45 { GL_STACK_OVERFLOW, "The operation would have caused an overflow" },
48 }; 46 };
49 47
48 cfg (String, gl_selectcolor, "#0080FF")
50 extern_cfg (Bool, gl_blackedges); 49 extern_cfg (Bool, gl_blackedges);
51 extern_cfg (String, gl_bgcolor); 50 extern_cfg (String, gl_bgcolor);
52 static QList<short> g_warnedColors; 51
52 static QList<int> g_warnedColors;
53 static const QColor g_BFCFrontColor (40, 192, 40); 53 static const QColor g_BFCFrontColor (40, 192, 40);
54 static const QColor g_BFCBackColor (224, 40, 40); 54 static const QColor g_BFCBackColor (224, 40, 40);
55 static QMap<LDObject*, QString> g_objectOrigins;
56 55
57 // ============================================================================= 56 // =============================================================================
58 // 57 //
59 void checkGLError_private (const char* file, int line) 58 void checkGLError_private (const char* file, int line)
60 { 59 {
124 return QColor (r, g, b); 123 return QColor (r, g, b);
125 } 124 }
126 125
127 // ============================================================================= 126 // =============================================================================
128 // 127 //
129 QColor GLCompiler::polygonColor (LDPolygon& poly, LDObject* topobj) const 128 QColor GLCompiler::getColorForPolygon (LDPolygon& poly, LDObject* topobj) const
130 { 129 {
131 QColor qcol; 130 QColor qcol;
132 131
133 if (poly.color == maincolor) 132 if (poly.color == maincolor)
134 { 133 {
147 146
148 if (col) 147 if (col)
149 qcol = col->faceColor; 148 qcol = col->faceColor;
150 } 149 }
151 150
152 if (qcol.isValid() == false) 151 if (not qcol.isValid())
153 { 152 {
154 // The color was unknown. Use main color to make the poly.object at least 153 // The color was unknown. Use main color to make the polygon at least
155 // not appear pitch-black. 154 // not appear pitch-black.
156 if (poly.num != 2 && poly.num != 5) 155 if (poly.num != 2 && poly.num != 5)
157 qcol = GLRenderer::getMainColor(); 156 qcol = GLRenderer::getMainColor();
158 else 157 else
159 qcol = Qt::black; 158 qcol = Qt::black;
160 159
161 // Warn about the unknown color, but only once. 160 // Warn about the unknown color, but only once.
162 if (g_warnedColors.contains (poly.color) == false) 161 if (not g_warnedColors.contains (poly.color))
163 { 162 {
164 print ("Unknown color %1!\n", poly.color); 163 print ("Unknown color %1!\n", poly.color);
165 g_warnedColors << poly.color; 164 g_warnedColors << poly.color;
166 } 165 }
167 166
230 229
231 QVector<GLfloat> vbodata; 230 QVector<GLfloat> vbodata;
232 231
233 for (auto it = m_objectInfo.begin(); it != m_objectInfo.end(); ++it) 232 for (auto it = m_objectInfo.begin(); it != m_objectInfo.end(); ++it)
234 { 233 {
235 if (it.key()->document() == getCurrentDocument() && it.key()->isHidden() == false) 234 if (it.key()->document() == getCurrentDocument() && not it.key()->isHidden())
236 vbodata += it->data[vbonum]; 235 vbodata += it->data[vbonum];
237 } 236 }
238 237
239 glBindBuffer (GL_ARRAY_BUFFER, m_vbo[vbonum]); 238 glBindBuffer (GL_ARRAY_BUFFER, m_vbo[vbonum]);
240 glBufferData (GL_ARRAY_BUFFER, vbodata.size() * sizeof(GLfloat), vbodata.constData(), GL_STATIC_DRAW); 239 glBufferData (GL_ARRAY_BUFFER, vbodata.size() * sizeof(GLfloat), vbodata.constData(), GL_STATIC_DRAW);
262 void GLCompiler::compileObject (LDObject* obj) 261 void GLCompiler::compileObject (LDObject* obj)
263 { 262 {
264 if (obj->document()->isImplicit()) 263 if (obj->document()->isImplicit())
265 return; 264 return;
266 265
267 g_objectOrigins[obj] = obj->document()->getDisplayName() + ":" + QString::number (obj->lineNumber());
268 ObjectVBOInfo info; 266 ObjectVBOInfo info;
269 info.isChanged = true; 267 info.isChanged = true;
270 dropObject (obj); 268 dropObject (obj);
271 compileSubObject (obj, obj, &info); 269 compileSubObject (obj, obj, &info);
272 m_objectInfo[obj] = info; 270 m_objectInfo[obj] = info;
284 { 282 {
285 case 2: surface = VBOSF_Lines; numverts = 2; break; 283 case 2: surface = VBOSF_Lines; numverts = 2; break;
286 case 3: surface = VBOSF_Triangles; numverts = 3; break; 284 case 3: surface = VBOSF_Triangles; numverts = 3; break;
287 case 4: surface = VBOSF_Quads; numverts = 4; break; 285 case 4: surface = VBOSF_Quads; numverts = 4; break;
288 case 5: surface = VBOSF_CondLines; numverts = 2; break; 286 case 5: surface = VBOSF_CondLines; numverts = 2; break;
289 287 default: return;
290 default:
291 print ("OMGWTFBBQ weird polygon with number %1 (topobj: #%2, %3), origin: %4",
292 (int) poly.num, topobj->id(), topobj->typeName(), poly.origin);
293 assert (false);
294 } 288 }
295 289
296 for (int complement = 0; complement < VBOCM_NumComplements; ++complement) 290 for (int complement = 0; complement < VBOCM_NumComplements; ++complement)
297 { 291 {
298 const int vbonum = vboNumber (surface, (EVBOComplement) complement); 292 const int vbonum = vboNumber (surface, (EVBOComplement) complement);
299 QVector<GLfloat>& vbodata = objinfo->data[vbonum]; 293 QVector<GLfloat>& vbodata = objinfo->data[vbonum];
300 const QColor normalColor = polygonColor (poly, topobj); 294 const QColor normalColor = getColorForPolygon (poly, topobj);
301 const QColor pickColor = indexColorForID (topobj->id()); 295 const QColor pickColor = indexColorForID (topobj->id());
302 296
303 for (int vert = 0; vert < numverts; ++vert) 297 for (int vert = 0; vert < numverts; ++vert)
304 { 298 {
305 switch ((EVBOComplement) complement) 299 switch ((EVBOComplement) complement)

mercurial