src/glrenderer.cpp

changeset 1323
05b3e173c900
parent 1319
39d7a9642eea
child 1326
69a90bd2dba2
equal deleted inserted replaced
1322:d8935cdb24c0 1323:05b3e173c900
62 {"Back camera", {backCameraMatrix, X, Y, true, true, true}}, // back 62 {"Back camera", {backCameraMatrix, X, Y, true, true, true}}, // back
63 {"Right camera", {rightCameraMatrix, Z, Y, false, true, true}}, // right 63 {"Right camera", {rightCameraMatrix, Z, Y, false, true, true}}, // right
64 {"Free camera", GLCamera::FreeCamera}, // free 64 {"Free camera", GLCamera::FreeCamera}, // free
65 } 65 }
66 { 66 {
67 m_camera = (Camera) m_config->camera(); 67 m_camera = (Camera) config::camera();
68 m_compiler = new GLCompiler (this); 68 m_compiler = new GLCompiler (this);
69 m_toolTipTimer = new QTimer (this); 69 m_toolTipTimer = new QTimer (this);
70 m_toolTipTimer->setSingleShot (true); 70 m_toolTipTimer->setSingleShot (true);
71 setAcceptDrops (true); 71 setAcceptDrops (true);
72 connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (showCameraIconTooltip())); 72 connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (showCameraIconTooltip()));
173 glPolygonOffset (1.0f, 1.0f); 173 glPolygonOffset (1.0f, 1.0f);
174 glEnable (GL_DEPTH_TEST); 174 glEnable (GL_DEPTH_TEST);
175 glShadeModel (GL_SMOOTH); 175 glShadeModel (GL_SMOOTH);
176 glEnable (GL_MULTISAMPLE); 176 glEnable (GL_MULTISAMPLE);
177 177
178 if (m_config->antiAliasedLines()) 178 if (config::antiAliasedLines())
179 { 179 {
180 glEnable (GL_LINE_SMOOTH); 180 glEnable (GL_LINE_SMOOTH);
181 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); 181 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
182 } 182 }
183 else 183 else
239 // 239 //
240 void GLRenderer::initializeGL() 240 void GLRenderer::initializeGL()
241 { 241 {
242 initializeOpenGLFunctions(); 242 initializeOpenGLFunctions();
243 setBackground(); 243 setBackground();
244 glLineWidth (m_config->lineThickness()); 244 glLineWidth (config::lineThickness());
245 glLineStipple (1, 0x6666); 245 glLineStipple (1, 0x6666);
246 setAutoFillBackground (false); 246 setAutoFillBackground (false);
247 setMouseTracking (true); 247 setMouseTracking (true);
248 setFocusPolicy (Qt::WheelFocus); 248 setFocusPolicy (Qt::WheelFocus);
249 m_compiler->initialize(); 249 m_compiler->initialize();
309 void GLRenderer::setBackground() 309 void GLRenderer::setBackground()
310 { 310 {
311 if (not m_isDrawingSelectionScene) 311 if (not m_isDrawingSelectionScene)
312 { 312 {
313 // Otherwise use the background that the user wants. 313 // Otherwise use the background that the user wants.
314 QColor color = m_config->backgroundColor(); 314 QColor color = config::backgroundColor();
315 315
316 if (color.isValid()) 316 if (color.isValid())
317 { 317 {
318 color.setAlpha(255); 318 color.setAlpha(255);
319 m_useDarkBackground = luma(color) < 80; 319 m_useDarkBackground = luma(color) < 80;
357 { 357 {
358 m_needZoomToFit = false; 358 m_needZoomToFit = false;
359 zoomAllToFit(); 359 zoomAllToFit();
360 } 360 }
361 361
362 if (m_config->drawWireframe() and not m_isDrawingSelectionScene) 362 if (config::drawWireframe() and not m_isDrawingSelectionScene)
363 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); 363 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
364 364
365 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 365 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
366 glEnable(GL_DEPTH_TEST); 366 glEnable(GL_DEPTH_TEST);
367 367
368 if (m_config->lighting() and not m_isDrawingSelectionScene) 368 if (config::lighting() and not m_isDrawingSelectionScene)
369 glEnable(GL_LIGHTING); 369 glEnable(GL_LIGHTING);
370 else 370 else
371 glDisable(GL_LIGHTING); 371 glDisable(GL_LIGHTING);
372 372
373 if (camera() != Camera::Free) 373 if (camera() != Camera::Free)
400 drawVbos (VboClass::Lines, VboSubclass::PickColors); 400 drawVbos (VboClass::Lines, VboSubclass::PickColors);
401 drawVbos (VboClass::ConditionalLines, VboSubclass::PickColors); 401 drawVbos (VboClass::ConditionalLines, VboSubclass::PickColors);
402 } 402 }
403 else 403 else
404 { 404 {
405 if (m_config->bfcRedGreenView()) 405 if (config::bfcRedGreenView())
406 { 406 {
407 glEnable (GL_CULL_FACE); 407 glEnable (GL_CULL_FACE);
408 glCullFace (GL_BACK); 408 glCullFace (GL_BACK);
409 drawVbos (VboClass::Triangles, VboSubclass::BfcFrontColors); 409 drawVbos (VboClass::Triangles, VboSubclass::BfcFrontColors);
410 drawVbos (VboClass::Quads, VboSubclass::BfcFrontColors); 410 drawVbos (VboClass::Quads, VboSubclass::BfcFrontColors);
415 } 415 }
416 else 416 else
417 { 417 {
418 VboSubclass colors; 418 VboSubclass colors;
419 419
420 if (m_config->randomColors()) 420 if (config::randomColors())
421 colors = VboSubclass::RandomColors; 421 colors = VboSubclass::RandomColors;
422 else 422 else
423 colors = VboSubclass::RegularColors; 423 colors = VboSubclass::RegularColors;
424 424
425 drawVbos (VboClass::Triangles, colors); 425 drawVbos (VboClass::Triangles, colors);
429 drawVbos (VboClass::Lines, VboSubclass::RegularColors); 429 drawVbos (VboClass::Lines, VboSubclass::RegularColors);
430 glEnable (GL_LINE_STIPPLE); 430 glEnable (GL_LINE_STIPPLE);
431 drawVbos (VboClass::ConditionalLines, VboSubclass::RegularColors); 431 drawVbos (VboClass::ConditionalLines, VboSubclass::RegularColors);
432 glDisable (GL_LINE_STIPPLE); 432 glDisable (GL_LINE_STIPPLE);
433 433
434 if (m_config->drawAxes()) 434 if (config::drawAxes())
435 { 435 {
436 glDisableClientState (GL_NORMAL_ARRAY); 436 glDisableClientState (GL_NORMAL_ARRAY);
437 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo); 437 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo);
438 glVertexPointer (3, GL_FLOAT, 0, NULL); 438 glVertexPointer (3, GL_FLOAT, 0, NULL);
439 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo); 439 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo);
463 * - colors determines what VBO subclass to use for colors 463 * - colors determines what VBO subclass to use for colors
464 */ 464 */
465 void GLRenderer::drawVbos(VboClass surface, VboSubclass colors) 465 void GLRenderer::drawVbos(VboClass surface, VboSubclass colors)
466 { 466 {
467 // Filter this through some configuration options 467 // Filter this through some configuration options
468 if ((isOneOf(surface, VboClass::Quads, VboClass::Triangles) and m_config->drawSurfaces() == false) 468 if ((isOneOf(surface, VboClass::Quads, VboClass::Triangles) and config::drawSurfaces() == false)
469 or (surface == VboClass::Lines and m_config->drawEdgeLines() == false) 469 or (surface == VboClass::Lines and config::drawEdgeLines() == false)
470 or (surface == VboClass::ConditionalLines and m_config->drawConditionalLines() == false)) 470 or (surface == VboClass::ConditionalLines and config::drawConditionalLines() == false))
471 { 471 {
472 return; 472 return;
473 } 473 }
474 474
475 GLenum type; 475 GLenum type;
693 { 693 {
694 // The edit mode may forbid the free camera. 694 // The edit mode may forbid the free camera.
695 if (freeCameraAllowed() or camera != Camera::Free) 695 if (freeCameraAllowed() or camera != Camera::Free)
696 { 696 {
697 m_camera = camera; 697 m_camera = camera;
698 m_config->setCamera(static_cast<int>(camera)); 698 config::setCamera(static_cast<int>(camera));
699 } 699 }
700 } 700 }
701 701
702 /* 702 /*
703 * Resolves a pixel pointer to an RGB color. 703 * Resolves a pixel pointer to an RGB color.
794 if (m_isDrawingSelectionScene) 794 if (m_isDrawingSelectionScene)
795 { 795 {
796 glDisable(GL_DITHER); 796 glDisable(GL_DITHER);
797 797
798 // Use particularly thick lines while picking ease up selecting lines. 798 // Use particularly thick lines while picking ease up selecting lines.
799 glLineWidth(qMax<double>(m_config->lineThickness(), 6.5)); 799 glLineWidth(qMax<double>(config::lineThickness(), 6.5));
800 } 800 }
801 else 801 else
802 { 802 {
803 glEnable(GL_DITHER); 803 glEnable(GL_DITHER);
804 804
805 // Restore line thickness 805 // Restore line thickness
806 glLineWidth(m_config->lineThickness()); 806 glLineWidth(config::lineThickness());
807 } 807 }
808 } 808 }
809 809
810 /* 810 /*
811 * Returns an image containing the current render of the scene. 811 * Returns an image containing the current render of the scene.
934 934
935 // ============================================================================= 935 // =============================================================================
936 // 936 //
937 void GLRenderer::highlightCursorObject() 937 void GLRenderer::highlightCursorObject()
938 { 938 {
939 if (not m_config->highlightObjectBelowCursor() and not objectAtCursor().isValid()) 939 if (not config::highlightObjectBelowCursor() and not objectAtCursor().isValid())
940 return; 940 return;
941 941
942 QModelIndex newIndex; 942 QModelIndex newIndex;
943 QModelIndex oldIndex = m_objectAtCursor; 943 QModelIndex oldIndex = m_objectAtCursor;
944 944
945 if (not m_isCameraMoving and m_config->highlightObjectBelowCursor()) 945 if (not m_isCameraMoving and config::highlightObjectBelowCursor())
946 { 946 {
947 setPicking (true); 947 setPicking (true);
948 drawGLScene(); 948 drawGLScene();
949 setPicking (false); 949 setPicking (false);
950 unsigned char pixel[4]; 950 unsigned char pixel[4];

mercurial