src/glRenderer.cpp

changeset 1017
fc1c13db9618
parent 1015
92c6ec099075
child 1023
9450ac3cd930
equal deleted inserted replaced
1016:3b279b5e57d3 1017:fc1c13db9618
76 HierarchyElement (parent), 76 HierarchyElement (parent),
77 m_document (nullptr), 77 m_document (nullptr),
78 m_initialized (false) 78 m_initialized (false)
79 { 79 {
80 m_isPicking = false; 80 m_isPicking = false;
81 m_camera = (ECamera) Config->camera(); 81 m_camera = (ECamera) m_config->camera();
82 m_drawToolTip = false; 82 m_drawToolTip = false;
83 m_currentEditMode = AbstractEditMode::createByType (this, EditModeType::Select); 83 m_currentEditMode = AbstractEditMode::createByType (this, EditModeType::Select);
84 m_panning = false; 84 m_panning = false;
85 m_compiler = new GLCompiler (this); 85 m_compiler = new GLCompiler (this);
86 m_objectAtCursor = nullptr; 86 m_objectAtCursor = nullptr;
172 glPolygonOffset (1.0f, 1.0f); 172 glPolygonOffset (1.0f, 1.0f);
173 glEnable (GL_DEPTH_TEST); 173 glEnable (GL_DEPTH_TEST);
174 glShadeModel (GL_SMOOTH); 174 glShadeModel (GL_SMOOTH);
175 glEnable (GL_MULTISAMPLE); 175 glEnable (GL_MULTISAMPLE);
176 176
177 if (Config->antiAliasedLines()) 177 if (m_config->antiAliasedLines())
178 { 178 {
179 glEnable (GL_LINE_SMOOTH); 179 glEnable (GL_LINE_SMOOTH);
180 glEnable (GL_POLYGON_SMOOTH); 180 glEnable (GL_POLYGON_SMOOTH);
181 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); 181 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
182 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); 182 glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST);
262 { 262 {
263 #ifdef USE_QT5 263 #ifdef USE_QT5
264 initializeOpenGLFunctions(); 264 initializeOpenGLFunctions();
265 #endif 265 #endif
266 setBackground(); 266 setBackground();
267 glLineWidth (Config->lineThickness()); 267 glLineWidth (m_config->lineThickness());
268 glLineStipple (1, 0x6666); 268 glLineStipple (1, 0x6666);
269 setAutoFillBackground (false); 269 setAutoFillBackground (false);
270 setMouseTracking (true); 270 setMouseTracking (true);
271 setFocusPolicy (Qt::WheelFocus); 271 setFocusPolicy (Qt::WheelFocus);
272 compiler()->initialize(); 272 compiler()->initialize();
329 { 329 {
330 glClearColor (0.0f, 0.0f, 0.0f, 1.0f); 330 glClearColor (0.0f, 0.0f, 0.0f, 1.0f);
331 return; 331 return;
332 } 332 }
333 333
334 QColor color = Config->backgroundColor(); 334 QColor color = m_config->backgroundColor();
335 335
336 if (not color.isValid()) 336 if (not color.isValid())
337 return; 337 return;
338 338
339 color.setAlpha (255); 339 color.setAlpha (255);
390 { 390 {
391 currentDocumentData().needZoomToFit = false; 391 currentDocumentData().needZoomToFit = false;
392 zoomAllToFit(); 392 zoomAllToFit();
393 } 393 }
394 394
395 if (Config->drawWireframe() and not isPicking()) 395 if (m_config->drawWireframe() and not isPicking())
396 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 396 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
397 397
398 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 398 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
399 glEnable (GL_DEPTH_TEST); 399 glEnable (GL_DEPTH_TEST);
400 400
444 drawVbos (LinesVbo, PickColorsVboComplement, GL_LINES); 444 drawVbos (LinesVbo, PickColorsVboComplement, GL_LINES);
445 drawVbos (ConditionalLinesVbo, PickColorsVboComplement, GL_LINES); 445 drawVbos (ConditionalLinesVbo, PickColorsVboComplement, GL_LINES);
446 } 446 }
447 else 447 else
448 { 448 {
449 if (Config->bfcRedGreenView()) 449 if (m_config->bfcRedGreenView())
450 { 450 {
451 glEnable (GL_CULL_FACE); 451 glEnable (GL_CULL_FACE);
452 glCullFace (GL_BACK); 452 glCullFace (GL_BACK);
453 drawVbos (TrianglesVbo, BfcFrontColorsVboComplement, GL_TRIANGLES); 453 drawVbos (TrianglesVbo, BfcFrontColorsVboComplement, GL_TRIANGLES);
454 drawVbos (QuadsVbo, BfcFrontColorsVboComplement, GL_QUADS); 454 drawVbos (QuadsVbo, BfcFrontColorsVboComplement, GL_QUADS);
459 } 459 }
460 else 460 else
461 { 461 {
462 ComplementVboType colors; 462 ComplementVboType colors;
463 463
464 if (Config->randomColors()) 464 if (m_config->randomColors())
465 colors = RandomColorsVboComplement; 465 colors = RandomColorsVboComplement;
466 else 466 else
467 colors = NormalColorsVboComplement; 467 colors = NormalColorsVboComplement;
468 468
469 drawVbos (TrianglesVbo, colors, GL_TRIANGLES); 469 drawVbos (TrianglesVbo, colors, GL_TRIANGLES);
473 drawVbos (LinesVbo, NormalColorsVboComplement, GL_LINES); 473 drawVbos (LinesVbo, NormalColorsVboComplement, GL_LINES);
474 glEnable (GL_LINE_STIPPLE); 474 glEnable (GL_LINE_STIPPLE);
475 drawVbos (ConditionalLinesVbo, NormalColorsVboComplement, GL_LINES); 475 drawVbos (ConditionalLinesVbo, NormalColorsVboComplement, GL_LINES);
476 glDisable (GL_LINE_STIPPLE); 476 glDisable (GL_LINE_STIPPLE);
477 477
478 if (Config->drawAxes()) 478 if (m_config->drawAxes())
479 { 479 {
480 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo); 480 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo);
481 glVertexPointer (3, GL_FLOAT, 0, NULL); 481 glVertexPointer (3, GL_FLOAT, 0, NULL);
482 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo); 482 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo);
483 glColorPointer (3, GL_FLOAT, 0, NULL); 483 glColorPointer (3, GL_FLOAT, 0, NULL);
499 // ============================================================================= 499 // =============================================================================
500 // 500 //
501 void GLRenderer::drawVbos (SurfaceVboType surface, ComplementVboType colors, GLenum type) 501 void GLRenderer::drawVbos (SurfaceVboType surface, ComplementVboType colors, GLenum type)
502 { 502 {
503 // Filter this through some configuration options 503 // Filter this through some configuration options
504 if ((isOneOf (surface, QuadsVbo, TrianglesVbo) and Config->drawSurfaces() == false) 504 if ((isOneOf (surface, QuadsVbo, TrianglesVbo) and m_config->drawSurfaces() == false)
505 or (surface == LinesVbo and Config->drawEdgeLines() == false) 505 or (surface == LinesVbo and m_config->drawEdgeLines() == false)
506 or (surface == ConditionalLinesVbo and Config->drawConditionalLines() == false)) 506 or (surface == ConditionalLinesVbo and m_config->drawConditionalLines() == false))
507 { 507 {
508 return; 508 return;
509 } 509 }
510 510
511 int surfacenum = m_compiler->vboNumber (surface, SurfacesVboComplement); 511 int surfacenum = m_compiler->vboNumber (surface, SurfacesVboComplement);
918 // The edit mode may forbid the free camera. 918 // The edit mode may forbid the free camera.
919 if (cam == EFreeCamera and not m_currentEditMode->allowFreeCamera()) 919 if (cam == EFreeCamera and not m_currentEditMode->allowFreeCamera())
920 return; 920 return;
921 921
922 m_camera = cam; 922 m_camera = cam;
923 Config->setCamera ((int) cam); 923 m_config->setCamera ((int) cam);
924 m_window->updateEditModeActions(); 924 m_window->updateEditModeActions();
925 } 925 }
926 926
927 // ============================================================================= 927 // =============================================================================
928 // 928 //
1093 if (isPicking()) 1093 if (isPicking())
1094 { 1094 {
1095 glDisable (GL_DITHER); 1095 glDisable (GL_DITHER);
1096 1096
1097 // Use particularly thick lines while picking ease up selecting lines. 1097 // Use particularly thick lines while picking ease up selecting lines.
1098 glLineWidth (qMax<double> (Config->lineThickness(), 6.5)); 1098 glLineWidth (qMax<double> (m_config->lineThickness(), 6.5));
1099 } 1099 }
1100 else 1100 else
1101 { 1101 {
1102 glEnable (GL_DITHER); 1102 glEnable (GL_DITHER);
1103 1103
1104 // Restore line thickness 1104 // Restore line thickness
1105 glLineWidth (Config->lineThickness()); 1105 glLineWidth (m_config->lineThickness());
1106 } 1106 }
1107 } 1107 }
1108 1108
1109 // ============================================================================= 1109 // =============================================================================
1110 // 1110 //
1508 if (obj->type() == OBJ_Overlay) 1508 if (obj->type() == OBJ_Overlay)
1509 lastOverlay = i; 1509 lastOverlay = i;
1510 } 1510 }
1511 1511
1512 if (lastOverlay != -1) 1512 if (lastOverlay != -1)
1513 document()->insertObj (lastOverlay + 1, ovlobj); 1513 document()->insertObject (lastOverlay + 1, ovlobj);
1514 else 1514 else
1515 { 1515 {
1516 document()->insertObj (i, ovlobj); 1516 document()->insertObject (i, ovlobj);
1517 1517
1518 if (found) 1518 if (found)
1519 document()->insertObj (i + 1, LDSpawn<LDEmpty>()); 1519 document()->insertObject (i + 1, LDSpawn<LDEmpty>());
1520 } 1520 }
1521 } 1521 }
1522 1522
1523 if (meta.img and ovlobj) 1523 if (meta.img and ovlobj)
1524 { 1524 {
1537 1537
1538 // ============================================================================= 1538 // =============================================================================
1539 // 1539 //
1540 void GLRenderer::highlightCursorObject() 1540 void GLRenderer::highlightCursorObject()
1541 { 1541 {
1542 if (not Config->highlightObjectBelowCursor() and objectAtCursor() == nullptr) 1542 if (not m_config->highlightObjectBelowCursor() and objectAtCursor() == nullptr)
1543 return; 1543 return;
1544 1544
1545 LDObject* newObject = nullptr; 1545 LDObject* newObject = nullptr;
1546 LDObject* oldObject = objectAtCursor(); 1546 LDObject* oldObject = objectAtCursor();
1547 qint32 newIndex; 1547 qint32 newIndex;
1548 1548
1549 if (m_isCameraMoving or not Config->highlightObjectBelowCursor()) 1549 if (m_isCameraMoving or not m_config->highlightObjectBelowCursor())
1550 { 1550 {
1551 newIndex = 0; 1551 newIndex = 0;
1552 } 1552 }
1553 else 1553 else
1554 { 1554 {
1593 LDSubfileReference* ref = LDSpawn<LDSubfileReference>(); 1593 LDSubfileReference* ref = LDSpawn<LDSubfileReference>();
1594 ref->setColor (MainColor); 1594 ref->setColor (MainColor);
1595 ref->setFileInfo (m_documents->getDocumentByName (primitiveName)); 1595 ref->setFileInfo (m_documents->getDocumentByName (primitiveName));
1596 ref->setPosition (Origin); 1596 ref->setPosition (Origin);
1597 ref->setTransform (IdentityMatrix); 1597 ref->setTransform (IdentityMatrix);
1598 currentDocument()->insertObj (m_window->suggestInsertPoint(), ref); 1598 currentDocument()->insertObject (m_window->suggestInsertPoint(), ref);
1599 ref->select(); 1599 ref->select();
1600 m_window->buildObjectList(); 1600 m_window->buildObjectList();
1601 m_window->renderer()->refresh(); 1601 m_window->renderer()->refresh();
1602 ev->acceptProposedAction(); 1602 ev->acceptProposedAction();
1603 } 1603 }

mercurial