src/glrenderer.cpp

Thu, 07 Feb 2019 13:45:07 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 07 Feb 2019 13:45:07 +0200
changeset 1438
988b6563d47d
parent 1437
1a77c6156db7
permissions
-rw-r--r--

stuff

655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1323
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
19 #define GL_GLEXT_PROTOTYPES
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
20 #include <GL/glu.h>
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
21 #include <GL/glext.h>
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include <QContextMenuEvent>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
23 #include <QToolTip>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include <QTimer>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include <GL/glu.h>
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "main.h"
1145
02264bf0108d Renamed ldDocument.cpp → lddocument.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1144
diff changeset
27 #include "lddocument.h"
1144
4f226fd97826 Renamed glRenderer.cpp → glrenderer.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1135
diff changeset
28 #include "glrenderer.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 #include "colors.h"
962
a4b463a7ee82 Rename MainWindow files
Teemu Piippo <crimsondusk64@gmail.com>
parents: 958
diff changeset
30 #include "mainwindow.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 #include "editHistory.h"
1146
bb728c124d47 Renamed glCompiler.cpp → glcompiler.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1145
diff changeset
32 #include "glcompiler.h"
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
33 #include "primitives.h"
998
5be0ce31ce60 Now compiles again
Teemu Piippo <crimsondusk64@gmail.com>
parents: 986
diff changeset
34 #include "documentmanager.h"
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
35 #include "grid.h"
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
1437
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
37 static GLCamera const cameraTemplates[7] = {
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
38 {"Top camera", {gl::topCameraMatrix, X, Z, false, false, false}},
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
39 {"Front camera", {gl::frontCameraMatrix, X, Y, false, true, false}},
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
40 {"Left camera", {gl::leftCameraMatrix, Z, Y, true, true, false}},
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
41 {"Bottom camera", {gl::bottomCameraMatrix, X, Z, false, true, true}},
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
42 {"Back camera", {gl::backCameraMatrix, X, Y, true, true, true}},
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
43 {"Right camera", {gl::rightCameraMatrix, Z, Y, false, true, true}},
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
44 {"Free camera", GLCamera::FreeCamera},
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
45 };
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
46
1133
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
47 /*
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
48 * Constructs a GL renderer.
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
49 */
1437
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
50 gl::Renderer::Renderer(const Model* model, CameraType cameraType, QWidget* parent) :
1097
9a9e6ce0c5dc Made a new renderer be created for each document, instead of reusing the same renderer for all documents.
Teemu Piippo <teemu@hecknology.net>
parents: 1096
diff changeset
51 QGLWidget {parent},
9a9e6ce0c5dc Made a new renderer be created for each document, instead of reusing the same renderer for all documents.
Teemu Piippo <teemu@hecknology.net>
parents: 1096
diff changeset
52 HierarchyElement {parent},
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
53 m_model {model},
1437
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
54 m_camera {cameraType},
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
55 m_cameraInfo {::cameraTemplates[cameraType]}
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 {
1428
ece049033adc fixed a crash when trying to open a document for the 3rd time after closing it 2 times
Teemu Piippo <teemu@hecknology.net>
parents: 1405
diff changeset
57 Q_ASSERT(model != nullptr);
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
58 m_compiler = new gl::Compiler (this);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 m_toolTipTimer = new QTimer (this);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 m_toolTipTimer->setSingleShot (true);
790
fe1b83f6ba82 - added primitives toolbox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 789
diff changeset
61 setAcceptDrops (true);
1131
03aa7091cb4a Simplified camera tooltip code.
Teemu Piippo <teemu@hecknology.net>
parents: 1130
diff changeset
62 connect (m_toolTipTimer, SIGNAL (timeout()), this, SLOT (showCameraIconTooltip()));
1437
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
63 resetAngles();
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
64 m_needZoomToFit = true;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
66 connect(
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
67 this->m_compiler,
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
68 &gl::Compiler::sceneChanged,
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
69 this,
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
70 qOverload<>(&gl::Renderer::update)
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
71 );
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73
1133
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
74 /*
1169
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
75 * Destructs the GL renderer.
1133
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
76 */
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
77 gl::Renderer::~Renderer()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78 {
1169
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
79 freeAxes();
1438
Teemu Piippo <teemu@hecknology.net>
parents: 1437
diff changeset
80 delete m_compiler;
1169
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
81 }
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
82
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
83 /*
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
84 * Deletes the axes VBOs
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
85 */
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
86 void gl::Renderer::freeAxes()
1169
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
87 {
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
88 if (m_axesInitialized)
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
89 {
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
90 glDeleteBuffers(1, &m_axesVbo);
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
91 glDeleteBuffers(1, &m_axesColorVbo);
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
92 m_axesInitialized = false;
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
93 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95
1133
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
96 /*
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
97 * Returns the camera currently in use.
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
98 */
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
99 GLCamera& gl::Renderer::currentCamera()
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
100 {
1437
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
101 return m_cameraInfo;
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
102 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
103
1133
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
104 /*
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
105 * Returns the camera currently in use.
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
106 */
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
107 const GLCamera& gl::Renderer::currentCamera() const
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
108 {
1437
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
109 return m_cameraInfo;
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
110 }
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
111
1133
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
112 /*
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
113 * Prepares the GL context for rendering.
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
114 */
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
115 void gl::Renderer::initGLData()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 glEnable (GL_BLEND);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 glEnable (GL_POLYGON_OFFSET_FILL);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 glPolygonOffset (1.0f, 1.0f);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 glEnable (GL_DEPTH_TEST);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 glShadeModel (GL_SMOOTH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
123 glEnable (GL_MULTISAMPLE);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
125 if (config::antiAliasedLines())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
127 glEnable (GL_LINE_SMOOTH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 glHint (GL_LINE_SMOOTH_HINT, GL_NICEST);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
129 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
130 else
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 glDisable (GL_LINE_SMOOTH);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
134 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
135
1133
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
136 /*
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
137 * Returns the object currently highlighted by the cursor.
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
138 */
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
139 QPersistentModelIndex gl::Renderer::objectAtCursor() const
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
140 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
141 return m_objectAtCursor;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
142 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
143
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
144 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
145 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
146 void gl::Renderer::needZoomToFit()
738
16b63398aa1f - resetAngles still needs to request a zoom to fit or the ctrl-0 action doesn't zoom to fit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 737
diff changeset
147 {
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
148 m_needZoomToFit = true;
738
16b63398aa1f - resetAngles still needs to request a zoom to fit or the ctrl-0 action doesn't zoom to fit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 737
diff changeset
149 }
16b63398aa1f - resetAngles still needs to request a zoom to fit or the ctrl-0 action doesn't zoom to fit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 737
diff changeset
150
16b63398aa1f - resetAngles still needs to request a zoom to fit or the ctrl-0 action doesn't zoom to fit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 737
diff changeset
151 // =============================================================================
16b63398aa1f - resetAngles still needs to request a zoom to fit or the ctrl-0 action doesn't zoom to fit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 737
diff changeset
152 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
153 void gl::Renderer::resetAngles()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
154 {
1095
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
155 if (m_initialized)
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
156 {
1393
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
157 m_rotation = QQuaternion::fromAxisAndAngle({1, 0, 0}, 30);
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
158 m_rotation *= QQuaternion::fromAxisAndAngle({0, 1, 0}, 330);
1095
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
159 }
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
160 currentCamera().setPanning(0, 0);
738
16b63398aa1f - resetAngles still needs to request a zoom to fit or the ctrl-0 action doesn't zoom to fit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 737
diff changeset
161 needZoomToFit();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
163
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
164 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
165 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
166 void gl::Renderer::initializeGL()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
167 {
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
168 initializeOpenGLFunctions();
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents: 1376
diff changeset
169
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents: 1376
diff changeset
170 if (glGetError() != GL_NO_ERROR)
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents: 1376
diff changeset
171 {
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents: 1376
diff changeset
172 abort();
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents: 1376
diff changeset
173 }
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents: 1376
diff changeset
174
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
175 setBackground();
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
176 glLineWidth (config::lineThickness());
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
177 glLineStipple (1, 0x6666);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 setAutoFillBackground (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 setMouseTracking (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180 setFocusPolicy (Qt::WheelFocus);
1133
47f6db5ea24d Some documentation and cleanup in GLRenderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1132
diff changeset
181 m_compiler->initialize();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
182 initializeAxes();
1119
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
183 initializeLighting();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
184 m_initialized = true;
1095
cb58a160bed3 - Use a QGenericMatrix to store the matrix, instead of a C array
Teemu Piippo <teemu@hecknology.net>
parents: 1094
diff changeset
185 // Now that GL is initialized, we can reset angles.
1437
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
186 resetAngles();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
187 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
188
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
189 void gl::Renderer::initializeLighting()
1119
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
190 {
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
191 GLfloat materialShininess[] = {5.0};
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
192 GLfloat lightPosition[] = {1.0, 1.0, 1.0, 0.0};
1248
8059668a2cf3 made lighting more subtle
Santeri Piippo
parents: 1247
diff changeset
193 GLfloat ambientLightingLevel[] = {0.5, 0.5, 0.5, 1.0};
1119
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
194 glShadeModel(GL_SMOOTH);
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
195 glMaterialfv(GL_FRONT, GL_SHININESS, materialShininess);
1248
8059668a2cf3 made lighting more subtle
Santeri Piippo
parents: 1247
diff changeset
196 glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLightingLevel);
8059668a2cf3 made lighting more subtle
Santeri Piippo
parents: 1247
diff changeset
197 glLightfv(GL_LIGHT0, GL_DIFFUSE, ambientLightingLevel);
1119
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
198 glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
199 glEnable(GL_LIGHTING);
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
200 glEnable(GL_LIGHT0);
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
201 glEnable(GL_COLOR_MATERIAL);
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
202 glEnable(GL_DEPTH_TEST);
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
203 }
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
204
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
205 // =============================================================================
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
206 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
207 void gl::Renderer::initializeAxes()
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
208 {
1169
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
209 freeAxes();
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
210 float axisVertexData[3][6];
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
211 float axisColorData[3][6];
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
212
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
213 auto compileAxis = [&](Axis axis, QColor color, Vertex extrema)
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
214 {
1169
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
215 axisVertexData[axis][0] = extrema[X];
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
216 axisVertexData[axis][1] = extrema[Y];
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
217 axisVertexData[axis][2] = extrema[Z];
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
218 axisVertexData[axis][3] = -extrema[X];
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
219 axisVertexData[axis][4] = -extrema[Y];
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
220 axisVertexData[axis][5] = -extrema[Z];
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
221 axisColorData[axis][0] = axisColorData[axis][3] = color.red();
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
222 axisColorData[axis][1] = axisColorData[axis][4] = color.green();
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
223 axisColorData[axis][2] = axisColorData[axis][5] = color.blue();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
224 };
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
225
1169
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
226 compileAxis(X, {192, 96, 96}, {10000, 0, 0});
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
227 compileAxis(Y, {48, 192, 48}, {0, 10000, 0});
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
228 compileAxis(Z, {48, 112, 192}, {0, 0, 10000});
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
229
1169
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
230 glGenBuffers(1, &m_axesVbo);
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
231 glBindBuffer(GL_ARRAY_BUFFER, m_axesVbo);
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
232 glBufferData(GL_ARRAY_BUFFER, sizeof axisVertexData, axisVertexData, GL_STATIC_DRAW);
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
233 glGenBuffers(1, &m_axesColorVbo);
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
234 glBindBuffer(GL_ARRAY_BUFFER, m_axesColorVbo);
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
235 glBufferData(GL_ARRAY_BUFFER, sizeof axisColorData, axisColorData, GL_STATIC_DRAW);
3da9287b4aff Cleanup GLRenderer::initializeAxes()
Teemu Piippo <teemu@hecknology.net>
parents: 1168
diff changeset
236 glBindBuffer(GL_ARRAY_BUFFER, 0);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
241 void gl::Renderer::setBackground()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 {
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
243 if (not m_isDrawingSelectionScene)
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
244 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
245 // Otherwise use the background that the user wants.
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
246 QColor color = config::backgroundColor();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
248 if (color.isValid())
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
249 {
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
250 color.setAlpha(255);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
251 m_useDarkBackground = luma(color) < 80;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
252 m_backgroundColor = color;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
253 qglClearColor(color);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
254 }
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
255 }
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
256 else
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
257 {
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
258 // The picking scene requires a black background.
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
259 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
260 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
261 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
263 QColor gl::Renderer::backgroundColor() const
1106
7541b0209057 Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents: 1105
diff changeset
264 {
7541b0209057 Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents: 1105
diff changeset
265 return m_backgroundColor;
7541b0209057 Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents: 1105
diff changeset
266 }
7541b0209057 Moved more methods only used by canvas code from GLRenderer to Canvas. Thin border pen is now a static constant.
Teemu Piippo <teemu@hecknology.net>
parents: 1105
diff changeset
267
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
270 void gl::Renderer::resizeGL (int width, int height)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
271 {
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
272 glViewport (0, 0, width, height);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 glMatrixMode (GL_PROJECTION);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 glLoadIdentity();
1369
1e2391b78d17 added cull depth support
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
275 gluPerspective (45.0f, (double) width / (double) height, near, far);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 glMatrixMode (GL_MODELVIEW);
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
277
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
278 // Unfortunately Qt does not provide a resized() signal so we have to manually feed the information.
1437
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
279 m_cameraInfo.rendererResized(width, height);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281
1393
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
282 /*
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
283 * Pads a 3×3 matrix into a 4×4 one by adding cells from the identity matrix.
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
284 */
1404
16eb4257e662 replaced GLRotationMatrix with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1393
diff changeset
285 QMatrix4x4 padMatrix(const QMatrix3x3& stub)
1393
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
286 {
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
287 return {
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
288 stub(0, 0), stub(0, 1), stub(0, 2), 0,
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
289 stub(1, 0), stub(1, 1), stub(1, 2), 0,
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
290 stub(2, 0), stub(2, 1), stub(2, 2), 0,
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
291 0, 0, 0, 1
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
292 };
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
293 }
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
294
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
296 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
297 void gl::Renderer::drawGLScene()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
298 {
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
299 if (m_needZoomToFit)
737
e58bdb21cc54 - more elegant version of ded0a9b, do not zoom to fit in setDocument, instead zoom to fit before rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
300 {
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1097
diff changeset
301 m_needZoomToFit = false;
737
e58bdb21cc54 - more elegant version of ded0a9b, do not zoom to fit in setDocument, instead zoom to fit before rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
302 zoomAllToFit();
e58bdb21cc54 - more elegant version of ded0a9b, do not zoom to fit in setDocument, instead zoom to fit before rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
303 }
e58bdb21cc54 - more elegant version of ded0a9b, do not zoom to fit in setDocument, instead zoom to fit before rendering
Santeri Piippo <crimsondusk64@gmail.com>
parents: 733
diff changeset
304
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
305 if (config::drawWireframe() and not m_isDrawingSelectionScene)
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
306 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
307
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
308 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
309 glEnable(GL_DEPTH_TEST);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
310
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
311 if (config::lighting() and not m_isDrawingSelectionScene)
1119
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
312 glEnable(GL_LIGHTING);
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
313 else
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
314 glDisable(GL_LIGHTING);
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
315
1437
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
316 if (not m_cameraInfo.isModelview())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
317 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
318 glMatrixMode (GL_PROJECTION);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
319 glPushMatrix();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
320 glLoadIdentity();
1404
16eb4257e662 replaced GLRotationMatrix with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1393
diff changeset
321 glMultMatrixf(currentCamera().realMatrix().constData());
16eb4257e662 replaced GLRotationMatrix with QMatrix4x4
Teemu Piippo <teemu@hecknology.net>
parents: 1393
diff changeset
322 glMultMatrixf(ldrawToGLAdapterMatrix.constData());
1178
3a88e7a60b63 At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents: 1177
diff changeset
323 drawFixedCameraBackdrop();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
324 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
325 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
326 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
327 glMatrixMode(GL_MODELVIEW);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
328 glPushMatrix();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
329 glLoadIdentity();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
330 glTranslatef(0.0f, 0.0f, -2.0f);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
331 glTranslatef(panning (X), panning (Y), -zoom());
1393
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
332 glMultMatrixf(padMatrix(m_rotation.toRotationMatrix()).constData());
1405
d2bf2e59a3ef replaced overloads with a new 'xyz' function
Teemu Piippo <teemu@hecknology.net>
parents: 1404
diff changeset
333 xyz(glTranslatef, -m_compiler->modelCenter());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
334 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335
1119
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
336 glEnableClientState (GL_NORMAL_ARRAY);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
337 glEnableClientState (GL_VERTEX_ARRAY);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
338 glEnableClientState (GL_COLOR_ARRAY);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
340 if (m_isDrawingSelectionScene)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
341 {
1167
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
342 drawVbos (VboClass::Triangles, VboSubclass::PickColors);
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
343 drawVbos (VboClass::Quads, VboSubclass::PickColors);
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
344 drawVbos (VboClass::Lines, VboSubclass::PickColors);
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
345 drawVbos (VboClass::ConditionalLines, VboSubclass::PickColors);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348 {
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
349 if (config::bfcRedGreenView())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
350 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
351 glEnable (GL_CULL_FACE);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
352 glCullFace (GL_BACK);
1167
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
353 drawVbos (VboClass::Triangles, VboSubclass::BfcFrontColors);
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
354 drawVbos (VboClass::Quads, VboSubclass::BfcFrontColors);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
355 glCullFace (GL_FRONT);
1167
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
356 drawVbos (VboClass::Triangles, VboSubclass::BfcBackColors);
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
357 drawVbos (VboClass::Quads, VboSubclass::BfcBackColors);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
358 glDisable (GL_CULL_FACE);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
359 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
360 else
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
361 {
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1121
diff changeset
362 VboSubclass colors;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
363
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
364 if (config::randomColors())
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1121
diff changeset
365 colors = VboSubclass::RandomColors;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
366 else
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1172
diff changeset
367 colors = VboSubclass::RegularColors;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
368
1167
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
369 drawVbos (VboClass::Triangles, colors);
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
370 drawVbos (VboClass::Quads, colors);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
371 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
372
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1172
diff changeset
373 drawVbos (VboClass::Lines, VboSubclass::RegularColors);
1376
83dd6cbd7f1a added an ini option to disable line stipple
Teemu Piippo <teemu@hecknology.net>
parents: 1372
diff changeset
374
83dd6cbd7f1a added an ini option to disable line stipple
Teemu Piippo <teemu@hecknology.net>
parents: 1372
diff changeset
375 if (config::useLineStipple())
83dd6cbd7f1a added an ini option to disable line stipple
Teemu Piippo <teemu@hecknology.net>
parents: 1372
diff changeset
376 glEnable (GL_LINE_STIPPLE);
83dd6cbd7f1a added an ini option to disable line stipple
Teemu Piippo <teemu@hecknology.net>
parents: 1372
diff changeset
377
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1172
diff changeset
378 drawVbos (VboClass::ConditionalLines, VboSubclass::RegularColors);
722
61e2d0ca0018 - conditional lines are now rendered with stippled lines again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 720
diff changeset
379 glDisable (GL_LINE_STIPPLE);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
381 if (config::drawAxes())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
382 {
1120
c3f07620494e Axes are not rendered with normals so the normals client state has to be disabled when drawing them.
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
383 glDisableClientState (GL_NORMAL_ARRAY);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
384 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
385 glVertexPointer (3, GL_FLOAT, 0, NULL);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
386 glBindBuffer (GL_ARRAY_BUFFER, m_axesVbo);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
387 glColorPointer (3, GL_FLOAT, 0, NULL);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
388 glDrawArrays (GL_LINES, 0, 6);
1120
c3f07620494e Axes are not rendered with normals so the normals client state has to be disabled when drawing them.
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
389 glEnableClientState (GL_NORMAL_ARRAY);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
390 CHECK_GL_ERROR();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
392 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
393
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
394 glPopMatrix();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
395 glBindBuffer (GL_ARRAY_BUFFER, 0);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
396 glDisableClientState (GL_VERTEX_ARRAY);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
397 glDisableClientState (GL_COLOR_ARRAY);
1119
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
398 glDisableClientState (GL_NORMAL_ARRAY);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
399 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
400 glDisable (GL_CULL_FACE);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401 glMatrixMode (GL_MODELVIEW);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
402 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
403 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
404
1167
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
405 /*
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
406 * Draws a set of VBOs onto the scene. Renders surfaces with appropriate normals and colors.
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
407 *
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
408 * Parameters:
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
409 * - surface determines what kind of surface to draw (triangles, quadrilaterals, edges or conditional edges)
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
410 * - colors determines what VBO subclass to use for colors
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
411 */
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
412 void gl::Renderer::drawVbos(VboClass surface, VboSubclass colors)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
413 {
815
efe34366e56a - added ability to filter out surfaces/edgelines/condlines from the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
414 // Filter this through some configuration options
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
415 if ((isOneOf(surface, VboClass::Quads, VboClass::Triangles) and config::drawSurfaces() == false)
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
416 or (surface == VboClass::Lines and config::drawEdgeLines() == false)
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
417 or (surface == VboClass::ConditionalLines and config::drawConditionalLines() == false))
815
efe34366e56a - added ability to filter out surfaces/edgelines/condlines from the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
418 {
efe34366e56a - added ability to filter out surfaces/edgelines/condlines from the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
419 return;
efe34366e56a - added ability to filter out surfaces/edgelines/condlines from the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
420 }
efe34366e56a - added ability to filter out surfaces/edgelines/condlines from the viewport
Santeri Piippo <crimsondusk64@gmail.com>
parents: 795
diff changeset
421
1167
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
422 GLenum type;
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
423
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
424 switch (surface)
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
425 {
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
426 case VboClass::_End:
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
427 case VboClass::Lines:
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
428 case VboClass::ConditionalLines:
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
429 type = GL_LINES;
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
430 break;
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
431
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
432 case VboClass::Triangles:
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
433 type = GL_TRIANGLES;
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
434 break;
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
435
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
436 case VboClass::Quads:
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
437 type = GL_QUADS;
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
438 break;
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
439 }
a348cee365e3 GLRenderer::drawVbos no longer needs to be told the GL type
Teemu Piippo <teemu@hecknology.net>
parents: 1161
diff changeset
440
1237
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1235
diff changeset
441 VboSubclass normals;
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1235
diff changeset
442
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1235
diff changeset
443 if (colors != VboSubclass::BfcBackColors)
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1235
diff changeset
444 normals = VboSubclass::Normals;
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1235
diff changeset
445 else
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1235
diff changeset
446 normals = VboSubclass::InvertedNormals;
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1235
diff changeset
447
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1121
diff changeset
448 int surfaceVboNumber = m_compiler->vboNumber(surface, VboSubclass::Surfaces);
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
449 int colorVboNumber = m_compiler->vboNumber(surface, colors);
1237
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1235
diff changeset
450 int normalVboNumber = m_compiler->vboNumber(surface, normals);
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1172
diff changeset
451 m_compiler->prepareVBO(surfaceVboNumber);
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1172
diff changeset
452 m_compiler->prepareVBO(colorVboNumber);
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1172
diff changeset
453 m_compiler->prepareVBO(normalVboNumber);
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
454 GLuint surfaceVbo = m_compiler->vbo(surfaceVboNumber);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
455 GLuint colorVbo = m_compiler->vbo(colorVboNumber);
1119
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
456 GLuint normalVbo = m_compiler->vbo(normalVboNumber);
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
457 GLsizei count = m_compiler->vboSize(surfaceVboNumber) / 3;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
458
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
459 if (count > 0)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
460 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
461 glBindBuffer(GL_ARRAY_BUFFER, surfaceVbo);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
462 glVertexPointer(3, GL_FLOAT, 0, nullptr);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
463 CHECK_GL_ERROR();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
464 glBindBuffer(GL_ARRAY_BUFFER, colorVbo);
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
465 glColorPointer(4, GL_FLOAT, 0, nullptr);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
466 CHECK_GL_ERROR();
1119
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
467 glBindBuffer(GL_ARRAY_BUFFER, normalVbo);
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
468 glNormalPointer(GL_FLOAT, 0, nullptr);
749fdf61b5cd Implemented lighting. Yay! Unfortunately, faces that show up the wrong way around in BFC red/green mode also show up with inverted lighting here.
Teemu Piippo <teemu@hecknology.net>
parents: 1116
diff changeset
469 CHECK_GL_ERROR();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
470 glDrawArrays(type, 0, count);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 859
diff changeset
471 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
472 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
473 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
474
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
475 QPen gl::Renderer::textPen() const
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
476 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
477 return {m_useDarkBackground ? Qt::white : Qt::black};
823
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
478 }
1a2f593f0c02 - saving work done on edit mode revamp
Santeri Piippo <crimsondusk64@gmail.com>
parents: 821
diff changeset
479
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
480 bool gl::Renderer::freeCameraAllowed() const
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
481 {
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
482 return true;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
483 }
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
484
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
485 void gl::Renderer::paintEvent(QPaintEvent*)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
486 {
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
487 makeCurrent();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
488 initGLData();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
489 drawGLScene();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
490
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
491 if (isDrawingSelectionScene())
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
492 return;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
493
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
494 QPainter painter {this};
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
495 painter.setRenderHint(QPainter::Antialiasing);
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
496 overpaint(painter);
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
497 }
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
498
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
499 void gl::Renderer::overpaint(QPainter &painter)
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
500 {
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
501 // Draw a label for the current camera in the bottom left corner
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
502 {
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
503 QFontMetrics metrics {QFont {}};
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
504 int margin = 4;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
505 painter.setPen(textPen());
1130
17f92eb2a30c Moved camera names to GLCamera, other adjustments
Teemu Piippo <teemu@hecknology.net>
parents: 1129
diff changeset
506 painter.drawText(QPoint {margin, height() - margin - metrics.descent()}, currentCamera().name());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
507 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
508 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
509
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
510 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
511 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
512 void gl::Renderer::mouseReleaseEvent(QMouseEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
513 {
1437
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
514 ignore(event);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
515 m_panning = false;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
516 update();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
517 m_totalMouseMove = 0;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
518 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
519
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
520 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
521 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
522 void gl::Renderer::mousePressEvent(QMouseEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
523 {
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
524 m_lastButtons = event->buttons();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
525 m_totalMouseMove = 0;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
526 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
527
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
528 // =============================================================================
825
f7649c9bfd9a - more work on edit modes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 824
diff changeset
529 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
530 void gl::Renderer::mouseMoveEvent(QMouseEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
531 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
532 int xMove = event->x() - m_mousePosition.x();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
533 int yMove = event->y() - m_mousePosition.y();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
534 m_totalMouseMove += qAbs(xMove) + qAbs(yMove);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
535 m_isCameraMoving = false;
828
7dd8f19159f7 - and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents: 827
diff changeset
536
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
537 bool left = event->buttons() & Qt::LeftButton;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
538 bool mid = event->buttons() & Qt::MidButton;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
539 bool shift = event->modifiers() & Qt::ShiftModifier;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
540
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
541 if (mid or (left and shift))
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
542 {
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
543 currentCamera().pan(xMove, yMove);
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
544 m_panning = true;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
545 m_isCameraMoving = true;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
546 }
1437
1a77c6156db7 commit work done on mdi
Teemu Piippo <teemu@hecknology.net>
parents: 1436
diff changeset
547 else if (left and m_cameraInfo.isModelview() and (xMove != 0 or yMove != 0))
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
548 {
1393
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
549 QQuaternion versor = QQuaternion::fromAxisAndAngle(yMove, xMove, 0, 0.6 * hypot(xMove, yMove));
f0fe7ea82b81 changed rotation matrix to quaternion in GLRenderer
Teemu Piippo <teemu@hecknology.net>
parents: 1391
diff changeset
550 m_rotation = versor * m_rotation;
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
551 m_isCameraMoving = true;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
552 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
553
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
554 // Start the tool tip timer
1131
03aa7091cb4a Simplified camera tooltip code.
Teemu Piippo <teemu@hecknology.net>
parents: 1130
diff changeset
555 m_toolTipTimer->start (500);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
556
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
557 // Update 2d position
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
558 m_mousePosition = event->pos();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
559 m_globalpos = event->globalPos();
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
560 m_mousePositionF = event->localPos();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
561
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
562 highlightCursorObject();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
563 update();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
564 event->accept();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
565 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
566
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
567 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
568 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
569 void gl::Renderer::keyPressEvent(QKeyEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
570 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
571 m_currentKeyboardModifiers = event->modifiers();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
572 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
573
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
574 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
575 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
576 void gl::Renderer::keyReleaseEvent(QKeyEvent* event)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
577 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
578 m_currentKeyboardModifiers = event->modifiers();
875
ce8e9b37d44f - finished line loop mode
Teemu Piippo <crimsondusk64@gmail.com>
parents: 869
diff changeset
579 update();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
580 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
581
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
582 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
583 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
584 void gl::Renderer::wheelEvent(QWheelEvent* ev)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
585 {
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
586 makeCurrent();
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
587 currentCamera().zoomNotch(ev->delta() > 0);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
588 m_isCameraMoving = true;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
589 update();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
590 ev->accept();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
591 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
592
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
593 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
594 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
595 void gl::Renderer::leaveEvent(QEvent*)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
596 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
597 m_toolTipTimer->stop();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
598 update();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
599 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
600
1110
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
601 /*
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
602 * Resolves a pixel pointer to an RGB color.
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
603 * pixel[0..2] must be valid.
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
604 */
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
605 static QRgb colorFromPixel(uint8_t* pixel)
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
606 {
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
607 return pixel[0] << 16 | pixel[1] << 8 | pixel[2] | 0xff000000;
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
608 }
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
609
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
610 /*
1110
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
611 * Returns the set of objects found in the specified pixel area.
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
612 */
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
613 QItemSelection gl::Renderer::pick(const QRect& range)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
614 {
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
615 makeCurrent();
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1248
diff changeset
616 QItemSelection result;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
617
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
618 // Paint the picking scene
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
619 setPicking(true);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
620 drawGLScene();
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
621
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
622 int x0 = range.left();
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
623 int y0 = range.top();
828
7dd8f19159f7 - and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents: 827
diff changeset
624 int x1 = x0 + range.width();
7dd8f19159f7 - and now it works fine too
Santeri Piippo <crimsondusk64@gmail.com>
parents: 827
diff changeset
625 int y1 = y0 + range.height();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
626
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
627 // Clamp the values to ensure they're within bounds
966
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 962
diff changeset
628 x0 = qMax (0, x0);
a834e43a57da Replaced Min/Max/Clamp/Abs with use of Qt versions of them.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 962
diff changeset
629 y0 = qMax (0, y0);
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
630 x1 = qMin (x1, width());
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
631 y1 = qMin (y1, height());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
632 const int areawidth = (x1 - x0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
633 const int areaheight = (y1 - y0);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
634 const qint32 numpixels = areawidth * areaheight;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
635
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
636 // Allocate space for the pixel data.
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
637 QVector<unsigned char> pixelData;
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
638 pixelData.resize(4 * numpixels);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
639
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
640 // Read pixels from the color buffer.
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
641 glReadPixels(x0, height() - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
642
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
643 QSet<QRgb> pixelColors;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
644
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
645 // Go through each pixel read and add them to the selection.
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
646 // Each pixel maps to an LDObject injectively.
753
Santeri Piippo <crimsondusk64@gmail.com>
parents: 752
diff changeset
647 // Note: black is background, those indices are skipped.
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
648 for (int i : ::range(0, 4, pixelData.size() - 4))
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
649 {
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
650 QRgb color = colorFromPixel(&pixelData[i]);
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
651
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
652 if (color != BlackRgb)
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
653 pixelColors.insert(color);
752
b80ccc2a24e4 - optimized picking, black is background now in pick scenes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 742
diff changeset
654 }
b80ccc2a24e4 - optimized picking, black is background now in pick scenes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 742
diff changeset
655
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
656 // For each index read, resolve the LDObject behind it and add it to the selection.
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
657 for (QRgb color : pixelColors)
752
b80ccc2a24e4 - optimized picking, black is background now in pick scenes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 742
diff changeset
658 {
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
659 QModelIndex index = m_model->objectByPickingColor(color);
958
1dc890c73e01 Removed all asserts from the code. Removed assert handling and the bomb box dialog.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 952
diff changeset
660
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1248
diff changeset
661 if (index.isValid())
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1248
diff changeset
662 result.select(index, index);
1057
3c7782ec3753 Fixed additive range selection not working properly.
Teemu Piippo <teemu@hecknology.net>
parents: 1056
diff changeset
663 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
664
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
665 setPicking(false);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
666 repaint();
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1248
diff changeset
667 return result;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
668 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
669
1110
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
670 /*
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
671 * Simpler version of gl::Renderer::pick which simply picks whatever object on the cursor
1110
ec3ee7da7806 Moved more business logic out of GLRenderer into Canvas. GLRenderer::pick(const QRange&) now returns a set of LDObjects without modifying them. Replaced the GLRenderer::pick(int, int) overload with GLRenderer::pickOneObject.
Teemu Piippo <teemu@hecknology.net>
parents: 1109
diff changeset
672 */
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
673 QModelIndex gl::Renderer::pick(int mouseX, int mouseY)
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
674 {
1013
fa025ba493d8 Cleanup miscallenous.cpp/.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
675 makeCurrent();
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
676 setPicking(true);
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
677 drawGLScene();
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1248
diff changeset
678 unsigned char pixel[4];
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
679 glReadPixels(mouseX, height() - mouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
680 QModelIndex result = m_model->objectByPickingColor(colorFromPixel(pixel));
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
681 setPicking(false);
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
682 repaint();
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1248
diff changeset
683 return result;
818
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
684 }
748ba8818af8 - added the magic wand tool
Santeri Piippo <crimsondusk64@gmail.com>
parents: 816
diff changeset
685
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
686 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
687 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
688 void gl::Renderer::setPicking(bool picking)
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
689 {
1170
2045a395213a Hardened the GLRenderer interface, made methods more private.
Teemu Piippo <teemu@hecknology.net>
parents: 1169
diff changeset
690 m_isDrawingSelectionScene = picking;
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
691 setBackground();
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
692
1061
273333700685 refactor
Teemu Piippo <teemu@hecknology.net>
parents: 1057
diff changeset
693 if (m_isDrawingSelectionScene)
772
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
694 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
695 glDisable(GL_DITHER);
772
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
696
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
697 // Use particularly thick lines while picking ease up selecting lines.
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
698 glLineWidth(qMax<double>(config::lineThickness(), 6.5));
772
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
699 }
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
700 else
772
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
701 {
1056
27b7991b3bea Cleanup in GL renderer...
Teemu Piippo <teemu@hecknology.net>
parents: 1049
diff changeset
702 glEnable(GL_DITHER);
772
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
703
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
704 // Restore line thickness
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
705 glLineWidth(config::lineThickness());
772
e117509e1b51 - make pick scenes always use particularly thick lines so that the line picking behavior is relayed to the mouse-over highlight
Santeri Piippo <crimsondusk64@gmail.com>
parents: 768
diff changeset
706 }
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
707 }
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
708
1171
430ffa371d2a Turned GLRenderer::pixelCapture to GLRenderer::screenCapture() which encapsulates screen capturing properly and returns a ready image.
Teemu Piippo <teemu@hecknology.net>
parents: 1170
diff changeset
709 /*
430ffa371d2a Turned GLRenderer::pixelCapture to GLRenderer::screenCapture() which encapsulates screen capturing properly and returns a ready image.
Teemu Piippo <teemu@hecknology.net>
parents: 1170
diff changeset
710 * Returns an image containing the current render of the scene.
430ffa371d2a Turned GLRenderer::pixelCapture to GLRenderer::screenCapture() which encapsulates screen capturing properly and returns a ready image.
Teemu Piippo <teemu@hecknology.net>
parents: 1170
diff changeset
711 */
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
712 QImage gl::Renderer::screenCapture()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
713 {
1171
430ffa371d2a Turned GLRenderer::pixelCapture to GLRenderer::screenCapture() which encapsulates screen capturing properly and returns a ready image.
Teemu Piippo <teemu@hecknology.net>
parents: 1170
diff changeset
714 // Read the current render to a buffer of pixels. We use RGBA format even though the image should be fully opaque at all times.
430ffa371d2a Turned GLRenderer::pixelCapture to GLRenderer::screenCapture() which encapsulates screen capturing properly and returns a ready image.
Teemu Piippo <teemu@hecknology.net>
parents: 1170
diff changeset
715 // This is because apparently GL_RGBA/GL_UNSIGNED_BYTE is the only setting pair that is guaranteed to actually work!
430ffa371d2a Turned GLRenderer::pixelCapture to GLRenderer::screenCapture() which encapsulates screen capturing properly and returns a ready image.
Teemu Piippo <teemu@hecknology.net>
parents: 1170
diff changeset
716 // ref: https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glReadPixels.xml
1172
3defab8cfd93 Changed QByteArray to QVector to avoid that ugly reinterpret_cast.
Teemu Piippo <teemu@hecknology.net>
parents: 1171
diff changeset
717 QVector<unsigned char> pixelData;
1171
430ffa371d2a Turned GLRenderer::pixelCapture to GLRenderer::screenCapture() which encapsulates screen capturing properly and returns a ready image.
Teemu Piippo <teemu@hecknology.net>
parents: 1170
diff changeset
718 pixelData.resize(4 * width() * height());
430ffa371d2a Turned GLRenderer::pixelCapture to GLRenderer::screenCapture() which encapsulates screen capturing properly and returns a ready image.
Teemu Piippo <teemu@hecknology.net>
parents: 1170
diff changeset
719 glReadPixels(0, 0, width(), height(), GL_RGBA, GL_UNSIGNED_BYTE, pixelData.data());
430ffa371d2a Turned GLRenderer::pixelCapture to GLRenderer::screenCapture() which encapsulates screen capturing properly and returns a ready image.
Teemu Piippo <teemu@hecknology.net>
parents: 1170
diff changeset
720
430ffa371d2a Turned GLRenderer::pixelCapture to GLRenderer::screenCapture() which encapsulates screen capturing properly and returns a ready image.
Teemu Piippo <teemu@hecknology.net>
parents: 1170
diff changeset
721 // Prepare the image and return it. It appears that GL and Qt formats have red and blue swapped and the Y axis flipped.
1172
3defab8cfd93 Changed QByteArray to QVector to avoid that ugly reinterpret_cast.
Teemu Piippo <teemu@hecknology.net>
parents: 1171
diff changeset
722 QImage image {pixelData.constData(), width(), height(), QImage::Format_ARGB32};
1171
430ffa371d2a Turned GLRenderer::pixelCapture to GLRenderer::screenCapture() which encapsulates screen capturing properly and returns a ready image.
Teemu Piippo <teemu@hecknology.net>
parents: 1170
diff changeset
723 return image.rgbSwapped().mirrored();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
724 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
725
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
726 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
727 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
728 void gl::Renderer::zoomToFit()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
729 {
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
730 currentCamera().setZoom(30.0f);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
731 bool lastfilled = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
732 bool firstrun = true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
733 bool inward = true;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
734 int runaway = 50;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
735
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
736 // Use the pick list while drawing the scene, this way we can tell whether borders
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
737 // are background or not.
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
738 setPicking (true);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
739
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
740 while (--runaway)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
741 {
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 828
diff changeset
742 if (zoom() > 10000.0 or zoom() < 0.0)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
743 {
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
744 // Nothing to draw if we get here.
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
745 currentCamera().setZoom(30.0);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
746 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
747 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
748
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
749 currentCamera().zoomNotch(inward);
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
750 QVector<unsigned char> capture (4 * width() * height());
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
751 drawGLScene();
1111
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
752 glReadPixels (0, 0, width(), height(), GL_RGBA, GL_UNSIGNED_BYTE, capture.data());
471572db2fe1 Replaced GLRenderer::m_width and GLRenderer::m_height with width() and height() calls.
Teemu Piippo <teemu@hecknology.net>
parents: 1110
diff changeset
753 QImage image (capture.constData(), width(), height(), QImage::Format_ARGB32);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
754 bool filled = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
755
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
756 // Check the top and bottom rows
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
757 for (int i = 0; i < image.width(); ++i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
758 {
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
759 if (image.pixel (i, 0) != BlackRgb or image.pixel (i, height() - 1) != BlackRgb)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
760 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
761 filled = true;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
762 break;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
763 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
764 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
765
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
766 // Left and right edges
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
767 if (filled == false)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
768 {
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
769 for (int i = 0; i < image.height(); ++i)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
770 {
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
771 if (image.pixel (0, i) != BlackRgb or image.pixel (width() - 1, i) != BlackRgb)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
772 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
773 filled = true;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
774 break;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
775 }
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
776 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
777 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
778
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
779 if (firstrun)
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
780 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
781 // If this is the first run, we don't know enough to determine
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
782 // whether the zoom was to fit, so we mark in our knowledge so
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
783 // far and start over.
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
784 inward = not filled;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
785 firstrun = false;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
786 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
787 else
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
788 {
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
789 // If this run filled the screen and the last one did not, the
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
790 // last run had ideal zoom - zoom a bit back and we should reach it.
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 828
diff changeset
791 if (filled and not lastfilled)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
792 {
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
793 currentCamera().zoomNotch(false);
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
794 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
795 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
796
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
797 // If this run did not fill the screen and the last one did, we've
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
798 // now reached ideal zoom so we're done here.
840
d077dd19bf9a - changed `&&` and `||` operators to their named variants `and` and `or`
Teemu Piippo <crimsondusk64@gmail.com>
parents: 828
diff changeset
799 if (not filled and lastfilled)
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
800 break;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
801
662
2f1bd9112408 - use the keyword 'not' in place of the exclamation mark for operator!, this is clearer. also converted uses of '== false' to this.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 655
diff changeset
802 inward = not filled;
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
803 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
804
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
805 lastfilled = filled;
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
806 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
807
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
808 setPicking (false);
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
809 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
810
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
811 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
812 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
813 void gl::Renderer::zoomAllToFit()
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
814 {
901
6e89eaa1df70 - zoom-to-fit now works.. better than before
Teemu Piippo <crimsondusk64@gmail.com>
parents: 897
diff changeset
815 zoomToFit();
655
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
816 }
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
817
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
818 // =============================================================================
b376645315ab - renamed files to camelCase
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
819 //
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
820 void gl::Renderer::highlightCursorObject()
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
821 {
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
822 if (not config::highlightObjectBelowCursor() and not objectAtCursor().isValid())
760
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
823 return;
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
824
1247
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
825 QModelIndex newIndex;
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
826 QModelIndex oldIndex = m_objectAtCursor;
760
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
827
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
828 if (not m_isCameraMoving and config::highlightObjectBelowCursor())
760
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
829 {
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
830 setPicking (true);
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
831 drawGLScene();
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
832 setPicking (false);
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
833 unsigned char pixel[4];
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
834 glReadPixels(
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
835 m_mousePosition.x(),
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
836 height() - m_mousePosition.y(),
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
837 1,
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
838 1,
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
839 GL_RGBA,
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
840 GL_UNSIGNED_BYTE,
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
841 &pixel[0]
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
842 );
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1251
diff changeset
843 newIndex = model()->objectByPickingColor(colorFromPixel(pixel));
760
e4e585f464b3 - made the mouse-hover object highlight togglable from configuration
Santeri Piippo <crimsondusk64@gmail.com>
parents: 759
diff changeset
844 }
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
845
1247
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
846 if (newIndex != oldIndex)
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
847 {
1247
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
848 m_objectAtCursor = newIndex;
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
849 emit objectHighlightingChanged(oldIndex, newIndex);
759
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
850 }
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
851
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
852 update();
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
853 }
038985b4a154 - added a selection hover effect to the renderer. selecting objects just became a lot more convenient...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 757
diff changeset
854
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
855 bool gl::Renderer::mouseHasMoved() const
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
856 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
857 return m_totalMouseMove >= 10;
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
858 }
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
859
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
860 QPoint const& gl::Renderer::mousePosition() const
827
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
861 {
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
862 return m_mousePosition;
82469b40567e - now compiles
Santeri Piippo <crimsondusk64@gmail.com>
parents: 825
diff changeset
863 }
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 851
diff changeset
864
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
865 QPointF const& gl::Renderer::mousePositionF() const
869
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
866 {
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
867 return m_mousePositionF;
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
868 }
7184f3bae695 - circle tool is now able to rotate the partial circular primitives spawned
Teemu Piippo <crimsondusk64@gmail.com>
parents: 866
diff changeset
869
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
870 Qt::KeyboardModifiers gl::Renderer::keyboardModifiers() const
897
ef9e4469975a - pressing ctrl while drawing now locks the draw to cardinal directions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 882
diff changeset
871 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
872 return m_currentKeyboardModifiers;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
873 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
874
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
875 gl::CameraType gl::Renderer::camera() const
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
876 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
877 return m_camera;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
878 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
879
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
880 double gl::Renderer::panning (Axis ax) const
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
881 {
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
882 return (ax == X) ? currentCamera().panningX() : currentCamera().panningY();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
883 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
884
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
885 double gl::Renderer::zoom()
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
886 {
1129
2b20261dc511 Exported GLRenderer cameras into a new class, GLCamera.
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
887 return currentCamera().zoom();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
888 }
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
889
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
890 bool gl::Renderer::isDrawingSelectionScene() const
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
891 {
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
892 return m_isDrawingSelectionScene;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
893 }
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
894
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
895 Qt::MouseButtons gl::Renderer::lastButtons() const
1104
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
896 {
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
897 return m_lastButtons;
edddb9b0db9e Moved document editing methods from GLRenderer to Canvas
Teemu Piippo <teemu@hecknology.net>
parents: 1103
diff changeset
898 }
1108
90d6f4b7782e Moved more editing-related methods to Canvas.
Teemu Piippo <teemu@hecknology.net>
parents: 1107
diff changeset
899
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
900 const Model* gl::Renderer::model() const
1113
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1111
diff changeset
901 {
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1111
diff changeset
902 return m_model;
1125
d8f94e56d42e Moved the definitions of all configuration options into a new text file and made the configuration collector read that.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
903 }
1178
3a88e7a60b63 At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents: 1177
diff changeset
904
3a88e7a60b63 At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents: 1177
diff changeset
905 /*
3a88e7a60b63 At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents: 1177
diff changeset
906 * This virtual function lets derivative classes render something to the fixed camera
3a88e7a60b63 At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents: 1177
diff changeset
907 * before the main brick is rendered.
3a88e7a60b63 At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents: 1177
diff changeset
908 */
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
909 void gl::Renderer::drawFixedCameraBackdrop() {}
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1238
diff changeset
910
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
911 QItemSelectionModel* gl::Renderer::selectionModel() const
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1248
diff changeset
912 {
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1248
diff changeset
913 return m_compiler->selectionModel();
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1248
diff changeset
914 }
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1248
diff changeset
915
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
916 void gl::Renderer::setSelectionModel(QItemSelectionModel* selectionModel)
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1238
diff changeset
917 {
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1244
diff changeset
918 this->m_compiler->setSelectionModel(selectionModel);
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1238
diff changeset
919 }
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1278
diff changeset
920
1436
241d3e452b32 moved GL stuff into a new gl namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1428
diff changeset
921 void gl::Renderer::fullUpdate()
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1278
diff changeset
922 {
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1278
diff changeset
923 this->m_compiler->fullUpdate();
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1278
diff changeset
924 update();
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1278
diff changeset
925 }
1438
Teemu Piippo <teemu@hecknology.net>
parents: 1437
diff changeset
926
Teemu Piippo <teemu@hecknology.net>
parents: 1437
diff changeset
927 void gl::Renderer::closeEvent(QCloseEvent* event)
Teemu Piippo <teemu@hecknology.net>
parents: 1437
diff changeset
928 {
Teemu Piippo <teemu@hecknology.net>
parents: 1437
diff changeset
929 emit closed();
Teemu Piippo <teemu@hecknology.net>
parents: 1437
diff changeset
930 return QGLWidget::closeEvent(event);
Teemu Piippo <teemu@hecknology.net>
parents: 1437
diff changeset
931 }

mercurial