Fri, 28 Dec 2018 00:03:47 +0200
moved GL stuff into a new gl namespace
src/canvas.cpp | file | annotate | diff | comparison | revisions | |
src/canvas.h | file | annotate | diff | comparison | revisions | |
src/glcompiler.cpp | file | annotate | diff | comparison | revisions | |
src/glcompiler.h | file | annotate | diff | comparison | revisions | |
src/glrenderer.cpp | file | annotate | diff | comparison | revisions | |
src/glrenderer.h | file | annotate | diff | comparison | revisions | |
src/mainwindow.cpp | file | annotate | diff | comparison | revisions | |
src/toolsets/viewtoolset.cpp | file | annotate | diff | comparison | revisions |
--- a/src/canvas.cpp Thu Dec 27 23:41:06 2018 +0200 +++ b/src/canvas.cpp Fri Dec 28 00:03:47 2018 +0200 @@ -25,7 +25,7 @@ #include "generics/ring.h" Canvas::Canvas(LDDocument* document, QWidget* parent) : - GLRenderer {document, parent}, + gl::Renderer {document, parent}, m_document {*document}, m_currentEditMode {AbstractEditMode::createByType (this, EditModeType::Select)} {} @@ -36,10 +36,10 @@ void Canvas::overpaint(QPainter& painter) { - GLRenderer::overpaint(painter); + gl::Renderer::overpaint(painter); QFontMetrics metrics {QFont {}}; - if (camera() != Camera::Free) + if (camera() != gl::FreeCamera) { // Paint the coordinates onto the screen. Vertex idealized = currentCamera().idealize(m_position3D); @@ -186,7 +186,7 @@ glEnd(); glDisable(GL_LINE_STIPPLE); - if (this->camera() < Camera::Free) + if (this->camera() < gl::FreeCamera) { GLfloat cullz = this->cullValues[static_cast<int>(this->camera())]; QMatrix4x4 matrix = { @@ -213,8 +213,8 @@ m_currentEditMode = AbstractEditMode::createByType(this, a); // If we cannot use the free camera, use the top one instead. - if (camera() == Camera::Free and not m_currentEditMode->allowFreeCamera()) - setCamera(Camera::Top); + if (camera() == gl::FreeCamera and not m_currentEditMode->allowFreeCamera()) + setCamera(gl::TopCamera); m_window->updateEditModeActions(); update(); @@ -259,7 +259,7 @@ void Canvas::keyReleaseEvent(QKeyEvent* event) { m_currentEditMode->keyReleased(event); - GLRenderer::keyReleaseEvent(event); + gl::Renderer::keyReleaseEvent(event); } void Canvas::mouseMoveEvent(QMouseEvent* event) @@ -268,7 +268,7 @@ m_position3D = currentCamera().convert2dTo3d(mousePosition(), grid()); if (not m_currentEditMode->mouseMoved(event)) - GLRenderer::mouseMoveEvent(event); + gl::Renderer::mouseMoveEvent(event); } void Canvas::mouseReleaseEvent(QMouseEvent *event) @@ -279,7 +279,7 @@ data.keymods = keyboardModifiers(); data.releasedButtons = lastButtons() & ~event->buttons(); m_currentEditMode->mouseReleased(data); - GLRenderer::mouseReleaseEvent(event); + gl::Renderer::mouseReleaseEvent(event); } void Canvas::mousePressEvent(QMouseEvent *event) @@ -287,7 +287,7 @@ if (m_currentEditMode->mousePressed(event)) event->accept(); - GLRenderer::mousePressEvent(event); + gl::Renderer::mousePressEvent(event); } const Vertex& Canvas::position3D() const @@ -298,7 +298,7 @@ void Canvas::drawPoint(QPainter& painter, QPointF pos, QColor color) const { int pointSize = 8; - QPen pen = thinBorderPen; + QPen pen = gl::thinBorderPen; pen.setWidth(1); painter.setPen(pen); painter.setBrush(color); @@ -318,7 +318,7 @@ QPen Canvas::linePen() const { - QPen linepen = thinBorderPen; + QPen linepen = gl::thinBorderPen; linepen.setWidth(2); linepen.setColor(luma(backgroundColor()) < 40 ? Qt::white : Qt::black); return linepen; @@ -374,20 +374,20 @@ double Canvas::currentCullValue() const { - if (this->camera() < Camera::Free) - return far - this->cullValues[static_cast<int>(this->camera())]; + if (this->camera() < gl::FreeCamera) + return gl::far - this->cullValues[static_cast<int>(this->camera())]; else return 0.0; } void Canvas::setCullValue(double value) { - if (this->camera() < Camera::Free) - this->cullValues[static_cast<int>(this->camera())] = far - value; + if (this->camera() < gl::FreeCamera) + this->cullValues[static_cast<int>(this->camera())] = gl::far - value; } void Canvas::clearCurrentCullValue() { - if (this->camera() < Camera::Free) + if (this->camera() < gl::FreeCamera) this->cullValues[static_cast<int>(this->camera())] = 0.0; }
--- a/src/canvas.h Thu Dec 27 23:41:06 2018 +0200 +++ b/src/canvas.h Fri Dec 28 00:03:47 2018 +0200 @@ -21,7 +21,7 @@ #include "editmodes/abstractEditMode.h" #include "geometry/plane.h" -class Canvas : public GLRenderer +class Canvas : public gl::Renderer { public: Canvas(LDDocument* document, QWidget* parent = nullptr);
--- a/src/glcompiler.cpp Thu Dec 27 23:41:06 2018 +0200 +++ b/src/glcompiler.cpp Fri Dec 28 00:03:47 2018 +0200 @@ -68,9 +68,9 @@ /* * Constructs a GL compiler. */ -GLCompiler::GLCompiler (GLRenderer* renderer) : - HierarchyElement (renderer), - m_renderer (renderer) +gl::Compiler::Compiler(gl::Renderer* renderer) : + HierarchyElement(renderer), + m_renderer(renderer) { connect( renderer->model(), @@ -108,7 +108,7 @@ /* * Initializes the VBOs after OpenGL is initialized. */ -void GLCompiler::initialize() +void gl::Compiler::initialize() { initializeOpenGLFunctions(); glGenBuffers(countof(m_vbo), &m_vbo[0]); @@ -118,7 +118,7 @@ /* * Destructs the VBOs when the compiler is deleted. */ -GLCompiler::~GLCompiler() +gl::Compiler::~Compiler() { glDeleteBuffers(countof(m_vbo), &m_vbo[0]); CHECK_GL_ERROR(); @@ -127,7 +127,7 @@ /* * Returns an index color for the LDObject ID given. This color represents the object in the picking scene. */ -QColor GLCompiler::indexColorForID (qint32 id) const +QColor gl::Compiler::indexColorForID (qint32 id) const { // Calculate a color based from this index. This method caters for // 16777216 objects. I don't think that will be exceeded anytime soon. :) @@ -143,7 +143,7 @@ * - polygonOwner is the LDObject from which the polygon originated. * - subclass provides context for the polygon. */ -QColor GLCompiler::getColorForPolygon( +QColor gl::Compiler::getColorForPolygon( const LDPolygon& polygon, const QModelIndex& polygonOwnerIndex, VboSubclass subclass @@ -247,7 +247,7 @@ /* * Tells the compiler that a merge of VBOs is required. */ -void GLCompiler::needMerge() +void gl::Compiler::needMerge() { for (int i = 0; i < countof (m_vboChanged); ++i) m_vboChanged[i] = true; @@ -256,7 +256,7 @@ /* * Stages the given object for compilation. */ -void GLCompiler::stageForCompilation(const QModelIndex& index) +void gl::Compiler::stageForCompilation(const QModelIndex& index) { m_staged.insert(index); } @@ -264,7 +264,7 @@ /* * Removes an object from the set of objects to be compiled. */ -void GLCompiler::unstage(const QModelIndex& index) +void gl::Compiler::unstage(const QModelIndex& index) { m_staged.remove(index); } @@ -272,7 +272,7 @@ /* * Compiles all staged objects. */ -void GLCompiler::compileStaged() +void gl::Compiler::compileStaged() { for (const QModelIndex& index : m_staged) compileObject(index); @@ -283,7 +283,7 @@ /* * Prepares a VBO for rendering. The VBO is merged if needed. */ -void GLCompiler::prepareVBO (int vbonum) +void gl::Compiler::prepareVBO (int vbonum) { // Compile anything that still awaits it compileStaged(); @@ -324,7 +324,7 @@ /* * Removes the data related to the given object. */ -void GLCompiler::dropObjectInfo(const QModelIndex& index) +void gl::Compiler::dropObjectInfo(const QModelIndex& index) { if (m_objectInfo.contains(index)) { @@ -339,7 +339,7 @@ /* * Makes the compiler forget about the given object completely. */ -void GLCompiler::forgetObject(QModelIndex index) +void gl::Compiler::forgetObject(QModelIndex index) { dropObjectInfo(index); unstage(index); @@ -348,7 +348,7 @@ /* * Compiles a single object. */ -void GLCompiler::compileObject(const QModelIndex& index) +void gl::Compiler::compileObject(const QModelIndex& index) { LDObject* object = m_renderer->model()->lookup(index); @@ -390,7 +390,7 @@ /* * Inserts a single polygon into VBOs. */ -void GLCompiler::compilePolygon( +void gl::Compiler::compilePolygon( LDPolygon& poly, const QModelIndex& polygonOwnerIndex, ObjectVboData& objectInfo @@ -487,7 +487,7 @@ /* * Returns the center point of the model. */ -Vertex GLCompiler::modelCenter() +Vertex gl::Compiler::modelCenter() { // If there's something still queued for compilation, we need to build those first so // that they get into the bounding box. @@ -527,24 +527,24 @@ return {}; } -int GLCompiler::vboNumber (VboClass surface, VboSubclass complement) +int gl::Compiler::vboNumber (VboClass surface, VboSubclass complement) { return (static_cast<int>(surface) * EnumLimits<VboSubclass>::Count) + static_cast<int>(complement); } -GLuint GLCompiler::vbo (int vbonum) const +GLuint gl::Compiler::vbo (int vbonum) const { return m_vbo[vbonum]; } -int GLCompiler::vboSize (int vbonum) const +int gl::Compiler::vboSize (int vbonum) const { return m_vboSizes[vbonum]; } -void GLCompiler::fullUpdate() +void gl::Compiler::fullUpdate() { m_objectInfo.clear(); recompile(); @@ -553,7 +553,7 @@ /* * Recompiles the entire model. */ -void GLCompiler::recompile() +void gl::Compiler::recompile() { for (QModelIndex index : m_renderer->model()->indices()) compileObject(index); @@ -561,7 +561,7 @@ emit sceneChanged(); } -void GLCompiler::handleRowInsertion(const QModelIndex&, int first, int last) +void gl::Compiler::handleRowInsertion(const QModelIndex&, int first, int last) { for (int row = first; row <= last; row += 1) m_staged.insert(m_renderer->model()->index(row)); @@ -569,7 +569,7 @@ emit sceneChanged(); } -void GLCompiler::handleRowRemoval(const QModelIndex&, int first, int last) +void gl::Compiler::handleRowRemoval(const QModelIndex&, int first, int last) { for (int row = last; row >= first; row -= 1) { auto index = m_renderer->model()->index(row); @@ -580,7 +580,7 @@ emit sceneChanged(); } -void GLCompiler::handleDataChange(const QModelIndex& topLeft, const QModelIndex& bottomRight) +void gl::Compiler::handleDataChange(const QModelIndex& topLeft, const QModelIndex& bottomRight) { for (int row = topLeft.row(); row <= bottomRight.row(); row += 1) m_staged.insert(m_renderer->model()->index(row)); @@ -589,7 +589,7 @@ emit sceneChanged(); } -void GLCompiler::handleObjectHighlightingChanged( +void gl::Compiler::handleObjectHighlightingChanged( const QModelIndex& oldIndex, const QModelIndex& newIndex ) { @@ -598,7 +598,7 @@ emit sceneChanged(); } -void GLCompiler::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) +void gl::Compiler::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) { for (const QModelIndex& index : selected.indexes()) m_staged.insert(index); @@ -610,12 +610,12 @@ emit sceneChanged(); } -QItemSelectionModel* GLCompiler::selectionModel() const +QItemSelectionModel* gl::Compiler::selectionModel() const { return _selectionModel; } -void GLCompiler::setSelectionModel(QItemSelectionModel* selectionModel) +void gl::Compiler::setSelectionModel(QItemSelectionModel* selectionModel) { if (this->_selectionModel) disconnect(this->_selectionModel, 0, 0, 0); @@ -641,7 +641,7 @@ emit sceneChanged(); } -void GLCompiler::clearSelectionModel() +void gl::Compiler::clearSelectionModel() { this->setSelectionModel(nullptr); emit sceneChanged();
--- a/src/glcompiler.h Thu Dec 27 23:41:06 2018 +0200 +++ b/src/glcompiler.h Fri Dec 28 00:03:47 2018 +0200 @@ -24,16 +24,22 @@ #include <QMap> #include <QSet> +namespace gl +{ + class Compiler; + class Renderer; +} + /* * Compiles LDObjects into polygons for the GLRenderer to draw. */ -class GLCompiler : public QObject, public HierarchyElement, protected QOpenGLFunctions +class gl::Compiler : public QObject, public HierarchyElement, protected QOpenGLFunctions { Q_OBJECT public: - GLCompiler (GLRenderer* renderer); - ~GLCompiler(); + Compiler (Renderer* renderer); + ~Compiler(); void initialize(); Vertex modelCenter(); @@ -76,7 +82,7 @@ bool m_vboChanged[NumVbos] = {true}; bool needBoundingBoxRebuild = true; int m_vboSizes[NumVbos] = {0}; - GLRenderer* m_renderer; + gl::Renderer* m_renderer; QItemSelectionModel* _selectionModel = nullptr; BoundingBox boundingBox;
--- a/src/glrenderer.cpp Thu Dec 27 23:41:06 2018 +0200 +++ b/src/glrenderer.cpp Fri Dec 28 00:03:47 2018 +0200 @@ -34,23 +34,10 @@ #include "documentmanager.h" #include "grid.h" -const QPen GLRenderer::thinBorderPen {QColor {0, 0, 0, 208}, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin}; - -// Transformation matrices for the fixed cameras. -const QMatrix4x4 GLRenderer::topCameraMatrix = QMatrix4x4 {}; -const QMatrix4x4 GLRenderer::frontCameraMatrix = {1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1}; -const QMatrix4x4 GLRenderer::leftCameraMatrix = {0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 1}; -const QMatrix4x4 GLRenderer::bottomCameraMatrix = {1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1}; -const QMatrix4x4 GLRenderer::backCameraMatrix = {-1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; -const QMatrix4x4 GLRenderer::rightCameraMatrix = {0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1}; - -// Conversion matrix from LDraw to OpenGL coordinates. -const QMatrix4x4 GLRenderer::ldrawToGLAdapterMatrix = {1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; - /* * Constructs a GL renderer. */ -GLRenderer::GLRenderer(const Model* model, QWidget* parent) : +gl::Renderer::Renderer(const Model* model, QWidget* parent) : QGLWidget {parent}, HierarchyElement {parent}, m_model {model}, @@ -65,8 +52,8 @@ } { Q_ASSERT(model != nullptr); - m_camera = (Camera) config::camera(); - m_compiler = new GLCompiler (this); + m_camera = (gl::CameraType) config::camera(); + m_compiler = new gl::Compiler (this); m_toolTipTimer = new QTimer (this); m_toolTipTimer->setSingleShot (true); setAcceptDrops (true); @@ -75,9 +62,9 @@ m_needZoomToFit = true; // Init camera icons - for (Camera camera : iterateEnum<Camera>()) + for (gl::CameraType camera : iterateEnum<gl::CameraType>()) { - const char* cameraIconNames[EnumLimits<Camera>::Count] = + const char* cameraIconNames[EnumLimits<gl::CameraType>::Count] = { "camera-top", "camera-front", "camera-left", "camera-bottom", "camera-back", "camera-right", @@ -91,9 +78,9 @@ connect( this->m_compiler, - &GLCompiler::sceneChanged, + &gl::Compiler::sceneChanged, this, - qOverload<>(&GLRenderer::update) + qOverload<>(&gl::Renderer::update) ); calcCameraIcons(); @@ -102,7 +89,7 @@ /* * Destructs the GL renderer. */ -GLRenderer::~GLRenderer() +gl::Renderer::~Renderer() { freeAxes(); } @@ -110,7 +97,7 @@ /* * Deletes the axes VBOs */ -void GLRenderer::freeAxes() +void gl::Renderer::freeAxes() { if (m_axesInitialized) { @@ -123,7 +110,7 @@ /* * Calculates the camera icon locations. */ -void GLRenderer::calcCameraIcons() +void gl::Renderer::calcCameraIcons() { int i = 0; const int columns = 3; @@ -157,7 +144,7 @@ /* * Returns the camera currently in use. */ -GLCamera& GLRenderer::currentCamera() +GLCamera& gl::Renderer::currentCamera() { return m_cameras[static_cast<int>(camera())]; } @@ -165,7 +152,7 @@ /* * Returns the camera currently in use. */ -const GLCamera& GLRenderer::currentCamera() const +const GLCamera& gl::Renderer::currentCamera() const { return m_cameras[static_cast<int>(camera())]; } @@ -173,7 +160,7 @@ /* * Prepares the GL context for rendering. */ -void GLRenderer::initGLData() +void gl::Renderer::initGLData() { glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -197,21 +184,21 @@ /* * Returns the object currently highlighted by the cursor. */ -QPersistentModelIndex GLRenderer::objectAtCursor() const +QPersistentModelIndex gl::Renderer::objectAtCursor() const { return m_objectAtCursor; } // ============================================================================= // -void GLRenderer::needZoomToFit() +void gl::Renderer::needZoomToFit() { m_needZoomToFit = true; } // ============================================================================= // -void GLRenderer::resetAngles() +void gl::Renderer::resetAngles() { if (m_initialized) { @@ -224,11 +211,11 @@ // ============================================================================= // -void GLRenderer::resetAllAngles() +void gl::Renderer::resetAllAngles() { - Camera oldCamera = camera(); + gl::CameraType const oldCamera = camera(); - for (Camera camera : iterateEnum<Camera>()) + for (gl::CameraType camera : iterateEnum<gl::CameraType>()) { setCamera(camera); resetAngles(); @@ -239,7 +226,7 @@ // ============================================================================= // -void GLRenderer::initializeGL() +void gl::Renderer::initializeGL() { initializeOpenGLFunctions(); @@ -262,7 +249,7 @@ resetAllAngles(); } -void GLRenderer::initializeLighting() +void gl::Renderer::initializeLighting() { GLfloat materialShininess[] = {5.0}; GLfloat lightPosition[] = {1.0, 1.0, 1.0, 0.0}; @@ -280,7 +267,7 @@ // ============================================================================= // -void GLRenderer::initializeAxes() +void gl::Renderer::initializeAxes() { freeAxes(); float axisVertexData[3][6]; @@ -314,7 +301,7 @@ // ============================================================================= // -void GLRenderer::setBackground() +void gl::Renderer::setBackground() { if (not m_isDrawingSelectionScene) { @@ -336,14 +323,14 @@ } } -QColor GLRenderer::backgroundColor() const +QColor gl::Renderer::backgroundColor() const { return m_backgroundColor; } // ============================================================================= // -void GLRenderer::resizeGL (int width, int height) +void gl::Renderer::resizeGL (int width, int height) { calcCameraIcons(); glViewport (0, 0, width, height); @@ -372,7 +359,7 @@ // ============================================================================= // -void GLRenderer::drawGLScene() +void gl::Renderer::drawGLScene() { if (m_needZoomToFit) { @@ -391,7 +378,7 @@ else glDisable(GL_LIGHTING); - if (camera() != Camera::Free) + if (camera() != gl::FreeCamera) { glMatrixMode (GL_PROJECTION); glPushMatrix(); @@ -487,7 +474,7 @@ * - surface determines what kind of surface to draw (triangles, quadrilaterals, edges or conditional edges) * - colors determines what VBO subclass to use for colors */ -void GLRenderer::drawVbos(VboClass surface, VboSubclass colors) +void gl::Renderer::drawVbos(VboClass surface, VboSubclass colors) { // Filter this through some configuration options if ((isOneOf(surface, VboClass::Quads, VboClass::Triangles) and config::drawSurfaces() == false) @@ -550,17 +537,17 @@ } } -QPen GLRenderer::textPen() const +QPen gl::Renderer::textPen() const { return {m_useDarkBackground ? Qt::white : Qt::black}; } -bool GLRenderer::freeCameraAllowed() const +bool gl::Renderer::freeCameraAllowed() const { return true; } -void GLRenderer::paintEvent(QPaintEvent*) +void gl::Renderer::paintEvent(QPaintEvent*) { makeCurrent(); initGLData(); @@ -574,7 +561,7 @@ overpaint(painter); } -void GLRenderer::overpaint(QPainter &painter) +void gl::Renderer::overpaint(QPainter &painter) { // Draw a background for the selected camera painter.setPen(thinBorderPen); @@ -585,7 +572,7 @@ for (const CameraIcon& info : m_cameraIcons) { // Don't draw the free camera icon when we can't use the free camera - if (info.camera == Camera::Free and not freeCameraAllowed()) + if (info.camera == gl::FreeCamera and not freeCameraAllowed()) continue; painter.drawPixmap(info.targetRect, info.image, info.sourceRect); @@ -602,7 +589,7 @@ // ============================================================================= // -void GLRenderer::mouseReleaseEvent(QMouseEvent* event) +void gl::Renderer::mouseReleaseEvent(QMouseEvent* event) { bool wasLeft = (m_lastButtons & Qt::LeftButton) and not (event->buttons() & Qt::LeftButton); m_panning = false; @@ -626,7 +613,7 @@ // ============================================================================= // -void GLRenderer::mousePressEvent(QMouseEvent* event) +void gl::Renderer::mousePressEvent(QMouseEvent* event) { m_lastButtons = event->buttons(); m_totalMouseMove = 0; @@ -634,7 +621,7 @@ // ============================================================================= // -void GLRenderer::mouseMoveEvent(QMouseEvent* event) +void gl::Renderer::mouseMoveEvent(QMouseEvent* event) { int xMove = event->x() - m_mousePosition.x(); int yMove = event->y() - m_mousePosition.y(); @@ -651,7 +638,7 @@ m_panning = true; m_isCameraMoving = true; } - else if (left and camera() == Camera::Free and (xMove != 0 or yMove != 0)) + else if (left and camera() == gl::FreeCamera and (xMove != 0 or yMove != 0)) { QQuaternion versor = QQuaternion::fromAxisAndAngle(yMove, xMove, 0, 0.6 * hypot(xMove, yMove)); m_rotation = versor * m_rotation; @@ -673,14 +660,14 @@ // ============================================================================= // -void GLRenderer::keyPressEvent(QKeyEvent* event) +void gl::Renderer::keyPressEvent(QKeyEvent* event) { m_currentKeyboardModifiers = event->modifiers(); } // ============================================================================= // -void GLRenderer::keyReleaseEvent(QKeyEvent* event) +void gl::Renderer::keyReleaseEvent(QKeyEvent* event) { m_currentKeyboardModifiers = event->modifiers(); update(); @@ -688,7 +675,7 @@ // ============================================================================= // -void GLRenderer::wheelEvent(QWheelEvent* ev) +void gl::Renderer::wheelEvent(QWheelEvent* ev) { makeCurrent(); currentCamera().zoomNotch(ev->delta() > 0); @@ -699,7 +686,7 @@ // ============================================================================= // -void GLRenderer::leaveEvent(QEvent*) +void gl::Renderer::leaveEvent(QEvent*) { m_toolTipTimer->stop(); update(); @@ -707,10 +694,10 @@ // ============================================================================= // -void GLRenderer::setCamera(Camera camera) +void gl::Renderer::setCamera(gl::CameraType camera) { // The edit mode may forbid the free camera. - if (freeCameraAllowed() or camera != Camera::Free) + if (freeCameraAllowed() or camera != gl::FreeCamera) { m_camera = camera; config::setCamera(static_cast<int>(camera)); @@ -729,7 +716,7 @@ /* * Returns the set of objects found in the specified pixel area. */ -QItemSelection GLRenderer::pick(const QRect& range) +QItemSelection gl::Renderer::pick(const QRect& range) { makeCurrent(); QItemSelection result; @@ -787,9 +774,9 @@ } /* - * Simpler version of GLRenderer::pick which simply picks whatever object on the cursor + * Simpler version of gl::Renderer::pick which simply picks whatever object on the cursor */ -QModelIndex GLRenderer::pick(int mouseX, int mouseY) +QModelIndex gl::Renderer::pick(int mouseX, int mouseY) { makeCurrent(); setPicking(true); @@ -804,7 +791,7 @@ // ============================================================================= // -void GLRenderer::setPicking(bool picking) +void gl::Renderer::setPicking(bool picking) { m_isDrawingSelectionScene = picking; setBackground(); @@ -828,7 +815,7 @@ /* * Returns an image containing the current render of the scene. */ -QImage GLRenderer::screenCapture() +QImage gl::Renderer::screenCapture() { // Read the current render to a buffer of pixels. We use RGBA format even though the image should be fully opaque at all times. // This is because apparently GL_RGBA/GL_UNSIGNED_BYTE is the only setting pair that is guaranteed to actually work! @@ -845,7 +832,7 @@ /* * Show a tooltip if the cursor is currently hovering over a camera icon. */ -void GLRenderer::showCameraIconTooltip() +void gl::Renderer::showCameraIconTooltip() { for (CameraIcon & icon : m_cameraIcons) { @@ -860,7 +847,7 @@ // ============================================================================= // -void GLRenderer::zoomToFit() +void gl::Renderer::zoomToFit() { currentCamera().setZoom(30.0f); bool lastfilled = false; @@ -945,14 +932,14 @@ // ============================================================================= // -void GLRenderer::zoomAllToFit() +void gl::Renderer::zoomAllToFit() { zoomToFit(); } // ============================================================================= // -void GLRenderer::highlightCursorObject() +void gl::Renderer::highlightCursorObject() { if (not config::highlightObjectBelowCursor() and not objectAtCursor().isValid()) return; @@ -987,52 +974,52 @@ update(); } -bool GLRenderer::mouseHasMoved() const +bool gl::Renderer::mouseHasMoved() const { return m_totalMouseMove >= 10; } -QPoint const& GLRenderer::mousePosition() const +QPoint const& gl::Renderer::mousePosition() const { return m_mousePosition; } -QPointF const& GLRenderer::mousePositionF() const +QPointF const& gl::Renderer::mousePositionF() const { return m_mousePositionF; } -Qt::KeyboardModifiers GLRenderer::keyboardModifiers() const +Qt::KeyboardModifiers gl::Renderer::keyboardModifiers() const { return m_currentKeyboardModifiers; } -Camera GLRenderer::camera() const +gl::CameraType gl::Renderer::camera() const { return m_camera; } -double GLRenderer::panning (Axis ax) const +double gl::Renderer::panning (Axis ax) const { return (ax == X) ? currentCamera().panningX() : currentCamera().panningY(); } -double GLRenderer::zoom() +double gl::Renderer::zoom() { return currentCamera().zoom(); } -bool GLRenderer::isDrawingSelectionScene() const +bool gl::Renderer::isDrawingSelectionScene() const { return m_isDrawingSelectionScene; } -Qt::MouseButtons GLRenderer::lastButtons() const +Qt::MouseButtons gl::Renderer::lastButtons() const { return m_lastButtons; } -const Model* GLRenderer::model() const +const Model* gl::Renderer::model() const { return m_model; } @@ -1041,19 +1028,19 @@ * This virtual function lets derivative classes render something to the fixed camera * before the main brick is rendered. */ -void GLRenderer::drawFixedCameraBackdrop() {} +void gl::Renderer::drawFixedCameraBackdrop() {} -QItemSelectionModel* GLRenderer::selectionModel() const +QItemSelectionModel* gl::Renderer::selectionModel() const { return m_compiler->selectionModel(); } -void GLRenderer::setSelectionModel(QItemSelectionModel* selectionModel) +void gl::Renderer::setSelectionModel(QItemSelectionModel* selectionModel) { this->m_compiler->setSelectionModel(selectionModel); } -void GLRenderer::fullUpdate() +void gl::Renderer::fullUpdate() { this->m_compiler->fullUpdate(); update();
--- a/src/glrenderer.h Thu Dec 27 23:41:06 2018 +0200 +++ b/src/glrenderer.h Fri Dec 28 00:03:47 2018 +0200 @@ -24,43 +24,62 @@ #include "glcamera.h" #include "hierarchyelement.h" -enum class Camera +namespace gl { - Top, - Front, - Left, - Bottom, - Back, - Right, - Free, - _End -}; + enum CameraType + { + TopCamera, + FrontCamera, + LeftCamera, + BottomCamera, + BackCamera, + RightCamera, + FreeCamera, + _End + }; + + struct CameraIcon + { + QPixmap image; + QRect sourceRect; + QRect targetRect; + QRect hitRect; + CameraType camera; + }; -struct CameraIcon -{ - QPixmap image; - QRect sourceRect; - QRect targetRect; - QRect hitRect; - Camera camera; -}; + class Renderer; + class Compiler; + + static const QPen thinBorderPen {QColor {0, 0, 0, 208}, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin}; -MAKE_ITERABLE_ENUM(Camera) + // Transformation matrices for the fixed cameras. + static const QMatrix4x4 topCameraMatrix = {}; + static const QMatrix4x4 frontCameraMatrix = {1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1}; + static const QMatrix4x4 leftCameraMatrix = {0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 1}; + static const QMatrix4x4 bottomCameraMatrix = {1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1}; + static const QMatrix4x4 backCameraMatrix = {-1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; + static const QMatrix4x4 rightCameraMatrix = {0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1}; + + // Conversion matrix from LDraw to OpenGL coordinates. + static const QMatrix4x4 ldrawToGLAdapterMatrix = {1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; + + enum { BlackRgb = 0xff000000 }; + static constexpr GLfloat near = 1.0f; + static constexpr GLfloat far = 10000.0f; +} + +MAKE_ITERABLE_ENUM(gl::CameraType) // The main renderer object, draws the brick on the screen, manages the camera and selection picking. -class GLRenderer : public QGLWidget, protected QOpenGLFunctions, public HierarchyElement +class gl::Renderer : public QGLWidget, protected QOpenGLFunctions, public HierarchyElement { Q_OBJECT public: - enum { BlackRgb = 0xff000000 }; - static constexpr GLfloat near = 1.0f; - static constexpr GLfloat far = 10000.0f; + Renderer(const Model* model, QWidget* parent = nullptr); + ~Renderer(); - GLRenderer(const Model* model, QWidget* parent = nullptr); - ~GLRenderer(); - - Camera camera() const; + gl::CameraType camera() const; GLCamera& currentCamera(); const GLCamera& currentCamera() const; Q_SLOT void fullUpdate(); @@ -75,20 +94,11 @@ void resetAngles(); QImage screenCapture(); void setBackground(); - void setCamera(Camera cam); + void setCamera(gl::CameraType cam); QPen textPen() const; QItemSelectionModel* selectionModel() const; void setSelectionModel(QItemSelectionModel* selectionModel); - static const QPen thinBorderPen; - static const QMatrix4x4 topCameraMatrix; - static const QMatrix4x4 frontCameraMatrix; - static const QMatrix4x4 leftCameraMatrix; - static const QMatrix4x4 bottomCameraMatrix; - static const QMatrix4x4 backCameraMatrix; - static const QMatrix4x4 rightCameraMatrix; - static const QMatrix4x4 ldrawToGLAdapterMatrix; - signals: void objectHighlightingChanged(const QModelIndex& oldIndex, const QModelIndex& newIndex); @@ -122,9 +132,9 @@ private: const Model* const m_model; - class GLCompiler* m_compiler; + gl::Compiler* m_compiler; QPersistentModelIndex m_objectAtCursor; - CameraIcon m_cameraIcons[7]; + gl::CameraIcon m_cameraIcons[7]; QTimer* m_toolTipTimer; Qt::MouseButtons m_lastButtons; Qt::KeyboardModifiers m_currentKeyboardModifiers; @@ -140,7 +150,7 @@ QPoint m_mousePosition; QPoint m_globalpos; QPointF m_mousePositionF; - Camera m_camera; + gl::CameraType m_camera; GLuint m_axeslist; int m_totalMouseMove; QColor m_backgroundColor;
--- a/src/mainwindow.cpp Thu Dec 27 23:41:06 2018 +0200 +++ b/src/mainwindow.cpp Fri Dec 28 00:03:47 2018 +0200 @@ -491,7 +491,7 @@ contextMenu->addAction (ui.actionSubfileSelection); } - if (renderer()->camera() != Camera::Free) + if (renderer()->camera() != gl::FreeCamera) { contextMenu->addSeparator(); contextMenu->addAction(ui.actionSetDrawPlane);
--- a/src/toolsets/viewtoolset.cpp Thu Dec 27 23:41:06 2018 +0200 +++ b/src/toolsets/viewtoolset.cpp Fri Dec 28 00:03:47 2018 +0200 @@ -220,7 +220,7 @@ void ViewToolset::setCullDepth() { - if (m_window->renderer()->camera() == Camera::Free) + if (m_window->renderer()->camera() == gl::FreeCamera) return; bool ok; @@ -232,8 +232,8 @@ m_window->renderer()->currentCamera().name() ), m_window->renderer()->currentCullValue(), - -GLRenderer::far, - GLRenderer::far, + -gl::far, + gl::far, 4, &ok );