44 } |
44 } |
45 |
45 |
46 #define DEBUG_PRINT(...) fprint (stdout, __VA_ARGS__) |
46 #define DEBUG_PRINT(...) fprint (stdout, __VA_ARGS__) |
47 |
47 |
48 extern_cfg (Bool, gl_blackedges); |
48 extern_cfg (Bool, gl_blackedges); |
49 static QList<short> gWarnedColors; |
49 static QList<short> g_warnedColors; |
50 static const QColor gBFCFrontColor (40, 192, 40); |
50 static const QColor g_BFCFrontColor (40, 192, 40); |
51 static const QColor gBFCBackColor (224, 40, 40); |
51 static const QColor g_BFCBackColor (224, 40, 40); |
52 |
52 |
53 // ============================================================================= |
53 // ============================================================================= |
54 // |
54 // |
55 void checkGLError_private (const char* file, int line) |
55 void checkGLError_private (const char* file, int line) |
56 { |
56 { |
75 // ============================================================================= |
75 // ============================================================================= |
76 // |
76 // |
77 GLCompiler::GLCompiler() |
77 GLCompiler::GLCompiler() |
78 { |
78 { |
79 needMerge(); |
79 needMerge(); |
80 memset (mVBOSizes, 0, sizeof mVBOSizes); |
80 memset (m_VBOSizes, 0, sizeof m_VBOSizes); |
81 } |
81 } |
82 |
82 |
83 // ============================================================================= |
83 // ============================================================================= |
84 // |
84 // |
85 void GLCompiler::initialize() |
85 void GLCompiler::initialize() |
86 { |
86 { |
87 glGenBuffers (gNumVBOs, &mVBOs[0]); |
87 glGenBuffers (g_numVBOs, &mVBOs[0]); |
88 checkGLError(); |
88 checkGLError(); |
89 } |
89 } |
90 |
90 |
91 // ============================================================================= |
91 // ============================================================================= |
92 // |
92 // |
93 GLCompiler::~GLCompiler() |
93 GLCompiler::~GLCompiler() |
94 { |
94 { |
95 glDeleteBuffers (gNumVBOs, &mVBOs[0]); |
95 glDeleteBuffers (g_numVBOs, &mVBOs[0]); |
96 checkGLError(); |
96 checkGLError(); |
97 } |
97 } |
98 |
98 |
99 // ============================================================================= |
99 // ============================================================================= |
100 // |
100 // |
148 |
148 |
149 if (qcol.isValid() == false) |
149 if (qcol.isValid() == false) |
150 { |
150 { |
151 // The color was unknown. Use main color to make the poly.object at least |
151 // The color was unknown. Use main color to make the poly.object at least |
152 // not appear pitch-black. |
152 // not appear pitch-black. |
153 if (poly.color != edgecolor) |
153 if (poly.num != 2 && poly.num != 5) |
154 qcol = GLRenderer::getMainColor(); |
154 qcol = GLRenderer::getMainColor(); |
155 else |
155 else |
156 qcol = Qt::black; |
156 qcol = Qt::black; |
157 |
157 |
158 // Warn about the unknown color, but only once. |
158 // Warn about the unknown color, but only once. |
159 for (short i : gWarnedColors) |
159 if (g_warnedColors.contains (poly.color) == false) |
160 if (poly.color == i) |
160 { |
161 return qcol; |
161 print ("Unknown color %1!\n", poly.color); |
162 |
162 g_warnedColors << poly.color; |
163 print ("%1: Unknown color %2!\n", __func__, poly.color); |
163 } |
164 gWarnedColors << poly.color; |
164 |
165 return qcol; |
165 return qcol; |
166 } |
166 } |
167 |
167 |
168 if (topobj->isSelected()) |
168 if (topobj->isSelected()) |
169 { |
169 { |
179 |
179 |
180 // ============================================================================= |
180 // ============================================================================= |
181 // |
181 // |
182 void GLCompiler::needMerge() |
182 void GLCompiler::needMerge() |
183 { |
183 { |
184 // Set all of mChanged to true |
184 for (int i = 0; i < countof (m_vboChanged); ++i) |
185 // memset (mChanged, 0xFF, sizeof mChanged); |
185 m_vboChanged[i] = true; |
186 for (int i = 0; i < ((int) (sizeof mChanged / sizeof *mChanged)); ++i) |
|
187 mChanged[i] = true; |
|
188 } |
186 } |
189 |
187 |
190 // ============================================================================= |
188 // ============================================================================= |
191 // |
189 // |
192 void GLCompiler::stageForCompilation (LDObject* obj) |
190 void GLCompiler::stageForCompilation (LDObject* obj) |
221 void GLCompiler::prepareVBO (int vbonum) |
219 void GLCompiler::prepareVBO (int vbonum) |
222 { |
220 { |
223 // Compile anything that still awaits it |
221 // Compile anything that still awaits it |
224 compileStaged(); |
222 compileStaged(); |
225 |
223 |
226 if (mChanged[vbonum] == false) |
224 if (m_vboChanged[vbonum] == false) |
227 return; |
225 return; |
228 |
226 |
229 QVector<GLfloat> vbodata; |
227 QVector<GLfloat> vbodata; |
230 |
228 |
231 for (auto it = mObjectInfo.begin(); it != mObjectInfo.end(); ++it) |
229 for (auto it = mObjectInfo.begin(); it != mObjectInfo.end(); ++it) |
236 |
234 |
237 glBindBuffer (GL_ARRAY_BUFFER, mVBOs[vbonum]); |
235 glBindBuffer (GL_ARRAY_BUFFER, mVBOs[vbonum]); |
238 glBufferData (GL_ARRAY_BUFFER, vbodata.size() * sizeof(GLfloat), vbodata.constData(), GL_DYNAMIC_DRAW); |
236 glBufferData (GL_ARRAY_BUFFER, vbodata.size() * sizeof(GLfloat), vbodata.constData(), GL_DYNAMIC_DRAW); |
239 glBindBuffer (GL_ARRAY_BUFFER, 0); |
237 glBindBuffer (GL_ARRAY_BUFFER, 0); |
240 checkGLError(); |
238 checkGLError(); |
241 mChanged[vbonum] = false; |
239 m_vboChanged[vbonum] = false; |
242 mVBOSizes[vbonum] = vbodata.size(); |
240 m_VBOSizes[vbonum] = vbodata.size(); |
243 } |
241 } |
244 |
242 |
245 // ============================================================================= |
243 // ============================================================================= |
246 // |
244 // |
247 void GLCompiler::dropObject (LDObject* obj) |
245 void GLCompiler::dropObject (LDObject* obj) |
319 break; |
317 break; |
320 } |
318 } |
321 |
319 |
322 case vboBFCFrontColors: |
320 case vboBFCFrontColors: |
323 { |
321 { |
324 writeColor (vbodata, gBFCFrontColor); |
322 writeColor (vbodata, g_BFCFrontColor); |
325 break; |
323 break; |
326 } |
324 } |
327 |
325 |
328 case vboBFCBackColors: |
326 case vboBFCBackColors: |
329 { |
327 { |
330 writeColor (vbodata, gBFCBackColor); |
328 writeColor (vbodata, g_BFCBackColor); |
331 break; |
329 break; |
332 } |
330 } |
333 |
331 |
334 case vboNumComplements: |
332 case vboNumComplements: |
335 break; |
333 break; |