src/GLRenderer.cc

changeset 679
dd7545e00a8f
parent 676
f7f965742fd5
child 681
c1cc036c6e1f
equal deleted inserted replaced
678:0526d8404097 679:dd7545e00a8f
128 setFile (null); 128 setFile (null);
129 setDrawOnly (false); 129 setDrawOnly (false);
130 setMessageLog (null); 130 setMessageLog (null);
131 m_width = m_height = -1; 131 m_width = m_height = -1;
132 m_hoverpos = g_origin; 132 m_hoverpos = g_origin;
133 m_compiler = new GLCompiler;
133 134
134 m_toolTipTimer = new QTimer (this); 135 m_toolTipTimer = new QTimer (this);
135 m_toolTipTimer->setSingleShot (true); 136 m_toolTipTimer->setSingleShot (true);
136 connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer())); 137 connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (slot_toolTipTimer()));
137 138
147 CameraIcon* info = &m_cameraIcons[cam]; 148 CameraIcon* info = &m_cameraIcons[cam];
148 info->img = new QPixmap (getIcon (iconname)); 149 info->img = new QPixmap (getIcon (iconname));
149 info->cam = cam; 150 info->cam = cam;
150 } 151 }
151 152
152 // Init VBO for axes
153 float axesdata[18];
154 memset (axesdata, 0, sizeof axesdata);
155 float colordata[18];
156
157 for (int i = 0; i < 3; ++i)
158 {
159 for (int j = 0; j < 3; ++j)
160 {
161 axesdata[(i * 6) + j] = g_GLAxes[i].vert.getCoordinate (j);
162 axesdata[(i * 6) + 3 + j] = -g_GLAxes[i].vert.getCoordinate (j);
163 }
164
165 for (int j = 0; j < 2; ++j)
166 {
167 colordata[(i * 6) + (j * 3) + 0] = g_GLAxes[i].col.red();
168 colordata[(i * 6) + (j * 3) + 1] = g_GLAxes[i].col.green();
169 colordata[(i * 6) + (j * 3) + 2] = g_GLAxes[i].col.blue();
170 }
171 }
172
173 glGenBuffers (1, &g_GLAxes_VBO);
174 glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_VBO);
175 glBufferData (GL_ARRAY_BUFFER, sizeof axesdata, axesdata, GL_STATIC_DRAW);
176 glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_VBO);
177
178 calcCameraIcons(); 153 calcCameraIcons();
179 } 154 }
180 155
181 // ============================================================================= 156 // =============================================================================
182 // 157 //
185 for (int i = 0; i < 6; ++i) 160 for (int i = 0; i < 6; ++i)
186 delete currentDocumentData().overlays[i].img; 161 delete currentDocumentData().overlays[i].img;
187 162
188 for (CameraIcon& info : m_cameraIcons) 163 for (CameraIcon& info : m_cameraIcons)
189 delete info.img; 164 delete info.img;
165
166 delete m_compiler;
190 } 167 }
191 168
192 // ============================================================================= 169 // =============================================================================
193 // Calculates the "hitboxes" of the camera icons so that we can tell when the 170 // Calculates the "hitboxes" of the camera icons so that we can tell when the
194 // cursor is pointing at the camera icon. 171 // cursor is pointing at the camera icon.
278 255
279 setAutoFillBackground (false); 256 setAutoFillBackground (false);
280 setMouseTracking (true); 257 setMouseTracking (true);
281 setFocusPolicy (Qt::WheelFocus); 258 setFocusPolicy (Qt::WheelFocus);
282 259
283 g_vertexCompiler.compileDocument(); 260 m_compiler->initialize();
261 m_compiler->compileDocument();
262
263 initializeAxes();
264 }
265
266 // =============================================================================
267 //
268 void GLRenderer::initializeAxes()
269 {
270 float axesdata[18];
271 memset (axesdata, 0, sizeof axesdata);
272 float colordata[18];
273
274 for (int i = 0; i < 3; ++i)
275 {
276 for (int j = 0; j < 3; ++j)
277 {
278 axesdata[(i * 6) + j] = g_GLAxes[i].vert.getCoordinate (j);
279 axesdata[(i * 6) + 3 + j] = -g_GLAxes[i].vert.getCoordinate (j);
280 }
281
282 for (int j = 0; j < 2; ++j)
283 {
284 colordata[(i * 6) + (j * 3) + 0] = g_GLAxes[i].col.red();
285 colordata[(i * 6) + (j * 3) + 1] = g_GLAxes[i].col.green();
286 colordata[(i * 6) + (j * 3) + 2] = g_GLAxes[i].col.blue();
287 }
288 }
289
290 glGenBuffers (1, &g_GLAxes_VBO);
291 glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_VBO);
292 glBufferData (GL_ARRAY_BUFFER, sizeof axesdata, axesdata, GL_STATIC_DRAW);
293 glBindBuffer (GL_ARRAY_BUFFER, 0);
284 } 294 }
285 295
286 // ============================================================================= 296 // =============================================================================
287 // 297 //
288 QColor GLRenderer::getMainColor() 298 QColor GLRenderer::getMainColor()
322 332
323 // ============================================================================= 333 // =============================================================================
324 // ----------------------------------------------------------------------------- 334 // -----------------------------------------------------------------------------
325 void GLRenderer::hardRefresh() 335 void GLRenderer::hardRefresh()
326 { 336 {
327 g_vertexCompiler.compileDocument(); 337 m_compiler->compileDocument();
328 refresh(); 338 refresh();
329 339
330 glLineWidth (gl_linethickness); 340 glLineWidth (gl_linethickness);
331 } 341 }
332 342
398 glEnableClientState (GL_VERTEX_ARRAY); 408 glEnableClientState (GL_VERTEX_ARRAY);
399 409
400 if (gl_axes) 410 if (gl_axes)
401 { 411 {
402 glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_VBO); 412 glBindBuffer (GL_ARRAY_BUFFER, g_GLAxes_VBO);
413 checkGLError();
403 glVertexPointer (3, GL_FLOAT, 0, NULL); 414 glVertexPointer (3, GL_FLOAT, 0, NULL);
415 checkGLError();
404 glDrawArrays (GL_LINES, 0, 6); 416 glDrawArrays (GL_LINES, 0, 6);
417 checkGLError();
405 } 418 }
406 419
407 drawVBOs (VBO_Triangles, GL_TRIANGLES); 420 drawVBOs (VBO_Triangles, GL_TRIANGLES);
408 drawVBOs (VBO_Quads, GL_QUADS); 421 drawVBOs (VBO_Quads, GL_QUADS);
409 drawVBOs (VBO_Lines, GL_LINES); 422 drawVBOs (VBO_Lines, GL_LINES);
410 drawVBOs (VBO_CondLines, GL_LINES); 423 drawVBOs (VBO_CondLines, GL_LINES);
411 424
412 glPopMatrix(); 425 glPopMatrix();
426 glBindBuffer (GL_ARRAY_BUFFER, 0);
413 glDisableClientState (GL_VERTEX_ARRAY); 427 glDisableClientState (GL_VERTEX_ARRAY);
428 checkGLError();
414 glDisable (GL_CULL_FACE); 429 glDisable (GL_CULL_FACE);
415 glMatrixMode (GL_MODELVIEW); 430 glMatrixMode (GL_MODELVIEW);
416 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 431 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
417 } 432 }
418 433
419 // ============================================================================= 434 // =============================================================================
420 // 435 //
421 void GLRenderer::drawVBOs (E_VBOArray arrayType, GLenum type) 436 void GLRenderer::drawVBOs (E_VBOArray arrayType, GLenum type)
422 { 437 {
423 g_vertexCompiler.prepareVBOArray (arrayType); 438 m_compiler->prepareVBOArray (arrayType);
424 GLuint idx = g_vertexCompiler.getVBOIndex (arrayType); 439 GLuint idx = m_compiler->getVBOIndex (arrayType);
425 GLsizei count = g_vertexCompiler.getVBOCount (arrayType); 440 GLsizei count = m_compiler->getVBOCount (arrayType);
426 441
427 if (count > 0) 442 if (count > 0)
428 { 443 {
429 glBindBuffer (GL_ARRAY_BUFFER, idx); 444 glBindBuffer (GL_ARRAY_BUFFER, idx);
445 checkGLError();
430 glVertexPointer (3, GL_FLOAT, 0, null); 446 glVertexPointer (3, GL_FLOAT, 0, null);
447 checkGLError();
431 // glColorPointer (4, GL_UNSIGNED_BYTE, sizeof (GLCompiler::VAO), &array->data()[0].color); 448 // glColorPointer (4, GL_UNSIGNED_BYTE, sizeof (GLCompiler::VAO), &array->data()[0].color);
432 // glVertexAttribPointer (idx, 3, GL_FLOAT, GL_FALSE, 0, null); 449 // glVertexAttribPointer (idx, 3, GL_FLOAT, GL_FALSE, 0, null);
433 glDrawArrays (type, 0, count); 450 glDrawArrays (type, 0, count);
451 checkGLError();
434 } 452 }
435 } 453 }
436 454
437 // ============================================================================= 455 // =============================================================================
438 // This converts a 2D point on the screen to a 3D point in the model. If 'snap' 456 // This converts a 2D point on the screen to a 3D point in the model. If 'snap'
827 845
828 // ============================================================================= 846 // =============================================================================
829 // 847 //
830 void GLRenderer::compileAllObjects() 848 void GLRenderer::compileAllObjects()
831 { 849 {
832 g_vertexCompiler.compileDocument(); 850 m_compiler->compileDocument();
833 } 851 }
834 852
835 // ============================================================================= 853 // =============================================================================
836 // 854 //
837 void GLRenderer::clampAngle (double& angle) const 855 void GLRenderer::clampAngle (double& angle) const
1283 // ============================================================================= 1301 // =============================================================================
1284 // 1302 //
1285 void GLRenderer::setFile (LDDocument* const& a) 1303 void GLRenderer::setFile (LDDocument* const& a)
1286 { 1304 {
1287 m_File = a; 1305 m_File = a;
1288 g_vertexCompiler.setDocument (a); 1306 m_compiler->setDocument (a);
1289 1307
1290 if (a != null) 1308 if (a != null)
1291 { 1309 {
1292 initOverlaysFromObjects(); 1310 initOverlaysFromObjects();
1293 1311
1557 1575
1558 // ============================================================================= 1576 // =============================================================================
1559 // 1577 //
1560 void GLRenderer::compileObject (LDObject* obj) 1578 void GLRenderer::compileObject (LDObject* obj)
1561 { 1579 {
1562 g_vertexCompiler.stageForCompilation (obj); 1580 m_compiler->stageForCompilation (obj);
1563 1581
1564 // Mark in known vertices of this object 1582 // Mark in known vertices of this object
1565 QList<Vertex> verts = getVertices (obj); 1583 QList<Vertex> verts = getVertices (obj);
1566 m_knownVerts << verts; 1584 m_knownVerts << verts;
1567 removeDuplicates (m_knownVerts); 1585 removeDuplicates (m_knownVerts);

mercurial