src/glcompiler.cpp

Mon, 04 Jun 2018 23:12:40 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Mon, 04 Jun 2018 23:12:40 +0300
changeset 1391
5fa4bf1fc781
parent 1380
bc799b965418
child 1392
0541d9b21968
permissions
-rw-r--r--

added work done on cylinders

706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
d79083b9f74d Merge ../ldforge into gl
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
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #define GL_GLEXT_PROTOTYPES
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <GL/glu.h>
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <GL/glext.h>
1146
bb728c124d47 Renamed glCompiler.cpp → glcompiler.cpp
Teemu Piippo <teemu@hecknology.net>
parents: 1139
diff changeset
22 #include "glcompiler.h"
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
23 #include "guiutilities.h"
1012
413ecd6b9801 It worx again!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
24 #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
25 #include "grid.h"
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1305
diff changeset
26 #include "algorithms/invert.h"
1319
39d7a9642eea reorganized headers
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
27 #include "generics/ring.h"
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
29 void checkGLError(HierarchyElement* element, QString file, int line)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 {
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
31 struct ErrorInfo
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
32 {
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
33 GLenum value;
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
34 QString text;
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
35 };
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
37 static const ErrorInfo knownErrors[] =
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
38 {
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
39 { GL_NO_ERROR, "No error" },
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
40 { GL_INVALID_ENUM, "Unacceptable enumerator passed" },
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
41 { GL_INVALID_VALUE, "Numeric argument out of range" },
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
42 { GL_INVALID_OPERATION, "The operation is not allowed to be done in this state" },
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
43 { GL_INVALID_FRAMEBUFFER_OPERATION, "Framebuffer object is not complete"},
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
44 { GL_OUT_OF_MEMORY, "Out of memory" },
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
45 { GL_STACK_UNDERFLOW, "The operation would have caused an underflow" },
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
46 { GL_STACK_OVERFLOW, "The operation would have caused an overflow" },
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
47 };
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
49 GLenum errorNumber = glGetError();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
51 if (errorNumber != GL_NO_ERROR)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 {
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
53 QString errorMessage;
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
54
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
55 for (const ErrorInfo& error : knownErrors)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 {
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
57 if (error.value == errorNumber)
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
58 {
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
59 errorMessage = error.text;
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
60 break;
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
61 }
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 }
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
63
1380
bc799b965418 added a status bar and moved printed messages there
Teemu Piippo <teemu@hecknology.net>
parents: 1372
diff changeset
64 print("OpenGL ERROR: at %1:%2: %3", file, line, errorMessage);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
68 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
69 * Constructs a GL compiler.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
70 */
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
71 GLCompiler::GLCompiler (GLRenderer* renderer) :
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
72 HierarchyElement (renderer),
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
73 m_renderer (renderer)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 {
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
75 connect(
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
76 renderer->model(),
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
77 SIGNAL(rowsInserted(QModelIndex, int, int)),
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
78 this,
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
79 SLOT(handleRowInsertion(QModelIndex, int, int))
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
80 );
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
81 connect(
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
82 renderer->model(),
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
83 SIGNAL(rowsAboutToBeRemoved(QModelIndex, int, int)),
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
84 this,
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
85 SLOT(handleRowRemoval(QModelIndex, int, int))
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
86 );
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
87 connect(
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
88 renderer->model(),
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
89 SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector<int>)),
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
90 this,
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
91 SLOT(handleDataChange(QModelIndex, QModelIndex))
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
92 );
1247
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
93 connect(
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
94 renderer,
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
95 SIGNAL(objectHighlightingChanged(QModelIndex, QModelIndex)),
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
96 this,
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
97 SLOT(handleObjectHighlightingChanged(QModelIndex, QModelIndex))
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
98 );
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: 1098
diff changeset
99 connect(m_window, SIGNAL(gridChanged()), this, SLOT(recompile()));
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
100
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
101 for (QModelIndex index : renderer->model()->indices())
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
102 {
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
103 print("%1", index);
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
104 stageForCompilation(index);
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
105 }
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
108 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
109 * Initializes the VBOs after OpenGL is initialized.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
110 */
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 void GLCompiler::initialize()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 {
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
113 initializeOpenGLFunctions();
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
114 glGenBuffers(countof(m_vbo), &m_vbo[0]);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
115 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
118 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
119 * Destructs the VBOs when the compiler is deleted.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
120 */
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121 GLCompiler::~GLCompiler()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
122 {
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
123 glDeleteBuffers(countof(m_vbo), &m_vbo[0]);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
124 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
125 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
127 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
128 * Returns an index color for the LDObject ID given. This color represents the object in the picking scene.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
129 */
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
130 QColor GLCompiler::indexColorForID (qint32 id) const
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
131 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
132 // Calculate a color based from this index. This method caters for
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
133 // 16777216 objects. I don't think that will be exceeded anytime soon. :)
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: 1098
diff changeset
134 int r = (id / 0x10000) % 0x100;
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
135 int g = (id / 0x100) % 0x100;
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
136 int b = id % 0x100;
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
137 return {r, g, b};
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
139
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
140 /*
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
141 * Returns the suitable color for the polygon.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
142 * - polygon is the polygon to colorise.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
143 * - polygonOwner is the LDObject from which the polygon originated.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
144 * - subclass provides context for the polygon.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
145 */
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
146 QColor GLCompiler::getColorForPolygon(
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
147 LDPolygon& polygon,
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
148 const QModelIndex& polygonOwnerIndex,
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
149 VboSubclass subclass
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
150 ) {
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
151 QColor color;
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
152 LDObject* polygonOwner = m_renderer->model()->lookup(polygonOwnerIndex);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
153
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
154 switch (subclass)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
155 {
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: 1122
diff changeset
156 case VboSubclass::Surfaces:
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1122
diff changeset
157 case VboSubclass::Normals:
1239
f1cf9d2d463a add missing switch case
Santeri Piippo
parents: 1237
diff changeset
158 case VboSubclass::InvertedNormals:
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: 1122
diff changeset
159 case VboSubclass::_End:
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
160 // Surface and normal VBOs contain vertex data, not colors. So we can't return anything meaningful.
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: 1098
diff changeset
161 return {};
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
162
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: 1122
diff changeset
163 case VboSubclass::BfcFrontColors:
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
164 // Use the constant green color for BFC front colors
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
165 return {64, 192, 80};
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
166
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: 1122
diff changeset
167 case VboSubclass::BfcBackColors:
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
168 // Use the constant red color for BFC back colors
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
169 return {208, 64, 64};
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
170
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: 1122
diff changeset
171 case VboSubclass::PickColors:
1278
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1276
diff changeset
172 // For the picking scene, use unique picking colors provided by the model.
6e1ea24e5a5e moved LDObject indices from a global array into Model
Santeri Piippo
parents: 1276
diff changeset
173 return m_renderer->model()->pickingColorForObject(polygonOwnerIndex);
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
174
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: 1122
diff changeset
175 case VboSubclass::RandomColors:
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
176 // For the random color scene, the owner object has rolled up a random color. Use that.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
177 color = polygonOwner->randomColor();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
178 break;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
180 case VboSubclass::RegularColors:
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
181 // For normal colors, use the polygon's color.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
182 if (polygon.color == MainColor)
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
183 {
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
184 // If it's the main color, use the polygon owner's color.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
185 if (polygonOwner->color() == MainColor)
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
186 {
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
187 // If that also is the main color, then we whatever the user has configured the main color to look like.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
188 color = guiUtilities()->mainColorRepresentation();
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
189 }
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
190 else
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
191 {
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
192 color = polygonOwner->color().faceColor();
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
193 }
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
194 }
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
195 else if (polygon.color == EdgeColor)
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
196 {
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
197 // Edge color is black, unless we have a dark background, in which case lines need to be bright.
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
198 color = luma(config::backgroundColor()) > 40 ? Qt::black : Qt::white;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
199 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
200 else
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
201 {
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
202 // Not main or edge color, use the polygon's color as is.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
203 color = LDColor {polygon.color}.faceColor();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
204 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
205 break;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
208 if (color.isValid())
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: 1098
diff changeset
209 {
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
210 // We may wish to apply blending on the color to indicate selection or highlight.
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: 1098
diff changeset
211 double blendAlpha = 0.0;
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
212
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
213 if (this->_selectionModel and this->_selectionModel->isSelected(polygonOwnerIndex))
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: 1098
diff changeset
214 blendAlpha = 1.0;
1247
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
215 else if (polygonOwnerIndex == m_renderer->objectAtCursor())
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: 1098
diff changeset
216 blendAlpha = 0.5;
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
217
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
218 if (blendAlpha != 0.0)
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
219 {
1323
05b3e173c900 Config is now a namespace
Teemu Piippo <teemu@hecknology.net>
parents: 1319
diff changeset
220 QColor selectedColor = config::selectColorBlend();
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
221 double denominator = blendAlpha + 1.0;
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
222 color.setRed((color.red() + (selectedColor.red() * blendAlpha)) / denominator);
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
223 color.setGreen((color.green() + (selectedColor.green() * blendAlpha)) / denominator);
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
224 color.setBlue((color.blue() + (selectedColor.blue() * blendAlpha)) / denominator);
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: 1098
diff changeset
225 }
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
226 }
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
227 else
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
228 {
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
229 // The color was unknown. Use main color to make the polygon at least not appear pitch-black.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
230 if (polygon.num != 2 and polygon.num != 5)
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
231 color = guiUtilities()->mainColorRepresentation();
890
903ec1e46298 - backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 889
diff changeset
232 else
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
233 color = Qt::black;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 // Warn about the unknown color, but only once.
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: 1098
diff changeset
236 static QSet<int> warnedColors;
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
237 if (not warnedColors.contains(polygon.color))
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238 {
1159
6ad8cdcd88d9 print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
239 print(tr("Unknown color %1!\n"), polygon.color);
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
240 warnedColors.insert(polygon.color);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
243
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
244 return color;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
247 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
248 * Tells the compiler that a merge of VBOs is required.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
249 */
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 void GLCompiler::needMerge()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251 {
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
252 for (int i = 0; i < countof (m_vboChanged); ++i)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253 m_vboChanged[i] = true;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
254 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
256 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
257 * Stages the given object for compilation.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
258 */
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
259 void GLCompiler::stageForCompilation(const QModelIndex& index)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 {
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
261 m_staged.insert(index);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
264 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
265 * Removes an object from the set of objects to be compiled.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
266 */
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
267 void GLCompiler::unstage(const QModelIndex& index)
721
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
268 {
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
269 m_staged.remove(index);
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
270 }
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
271
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
272 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
273 * Compiles all staged objects.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
274 */
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275 void GLCompiler::compileStaged()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 {
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
277 for (const QModelIndex& index : m_staged)
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
278 compileObject(index);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280 m_staged.clear();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
281 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
282
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
283 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
284 * Prepares a VBO for rendering. The VBO is merged if needed.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
285 */
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
286 void GLCompiler::prepareVBO (int vbonum)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288 // Compile anything that still awaits it
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289 compileStaged();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
291 if (m_vboChanged[vbonum])
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
292 {
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
293 // Merge the VBO into a vector of floats.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
294 QVector<GLfloat> vbodata;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
295
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
296 for (
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
297 auto iterator = m_objectInfo.begin();
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
298 iterator != m_objectInfo.end();
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
299 ) {
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
300 if (not iterator.key().isValid())
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
301 {
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
302 iterator = m_objectInfo.erase(iterator);
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
303 }
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
304 else
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
305 {
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
306 LDObject* object = m_renderer->model()->lookup(iterator.key());
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
307 if (not object->isHidden())
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
308 vbodata += iterator->data[vbonum];
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
309
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
310 ++iterator;
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
311 }
883
69b8adc9a669 - fixed: due to a shared pointer called via reference called dismiss() in LDDocument::closeInitialFile, this could cause LDDocuments to delete themselves in setImplicit(true) as no shared pointers were left inside closeInitialFile to keep the refcount up.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 861
diff changeset
312 }
886
3c83fe3486b1 - fixed endless loop in prepareVBO due to badly incremented iterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 883
diff changeset
313
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
314 // Transfer the VBO to the graphics processor.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
315 glBindBuffer (GL_ARRAY_BUFFER, m_vbo[vbonum]);
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
316 glBufferData (GL_ARRAY_BUFFER, countof(vbodata) * sizeof(GLfloat), vbodata.constData(), GL_STATIC_DRAW);
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
317 glBindBuffer (GL_ARRAY_BUFFER, 0);
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
318 CHECK_GL_ERROR();
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
319 m_vboChanged[vbonum] = false;
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
320 m_vboSizes[vbonum] = countof(vbodata);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
321 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
322 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
323
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
324 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
325 * Removes the data related to the given object.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
326 */
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
327 void GLCompiler::dropObjectInfo(const QModelIndex& index)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
328 {
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
329 if (m_objectInfo.contains(index))
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330 {
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
331 // If we have data relating to this object, remove it.
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
332 // The VBOs have changed now and need to be merged.
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
333 m_objectInfo.remove(index);
1371
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
334 this->needBoundingBoxRebuild = true;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
335 needMerge();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
337 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
338
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
339 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
340 * Makes the compiler forget about the given object completely.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
341 */
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
342 void GLCompiler::forgetObject(QModelIndex index)
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: 1098
diff changeset
343 {
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
344 dropObjectInfo(index);
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
345 unstage(index);
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: 1098
diff changeset
346 }
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
347
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
348 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
349 * Compiles a single object.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
350 */
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
351 void GLCompiler::compileObject(const QModelIndex& index)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
352 {
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
353 LDObject* object = m_renderer->model()->lookup(index);
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
354
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
355 if (object == nullptr)
708
3155f2c05f89 - more debugging...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
356 return;
3155f2c05f89 - more debugging...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
357
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
358 ObjectVboData info;
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
359 dropObjectInfo(index);
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
360
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
361 switch (object->type())
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
362 {
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
363 // Note: We cannot split quads into triangles here, it would mess up the
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
364 // wireframe view. Quads must go into separate vbos.
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: 1122
diff changeset
365 case LDObjectType::Triangle:
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1127
diff changeset
366 case LDObjectType::Quadrilateral:
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1127
diff changeset
367 case LDObjectType::EdgeLine:
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1127
diff changeset
368 case LDObjectType::ConditionalEdge:
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
369 {
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
370 LDPolygon* poly = object->getPolygon();
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
371 compilePolygon (*poly, index, info);
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
372 delete poly;
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
373 break;
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
374 }
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
375
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: 1122
diff changeset
376 case LDObjectType::BezierCurve:
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
377 {
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
378 LDBezierCurve* curve = static_cast<LDBezierCurve*>(object);
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
379 for (LDPolygon& polygon : curve->rasterizePolygons(grid()->bezierCurveSegments()))
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
380 compilePolygon (polygon, index, info);
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
381 }
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
382 break;
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
383
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
384 default:
1391
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents: 1380
diff changeset
385 if (object->isRasterizable())
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents: 1380
diff changeset
386 {
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents: 1380
diff changeset
387 auto data = object->rasterizePolygons(m_documents, m_renderer->model()->winding());
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents: 1380
diff changeset
388
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents: 1380
diff changeset
389 for (LDPolygon& poly : data)
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents: 1380
diff changeset
390 compilePolygon(poly, index, info);
5fa4bf1fc781 added work done on cylinders
Teemu Piippo <teemu@hecknology.net>
parents: 1380
diff changeset
391 }
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
392 break;
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
393 }
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
394
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
395 m_objectInfo[index] = info;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
396 needMerge();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
397 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
399 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
400 * Inserts a single polygon into VBOs.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
401 */
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
402 void GLCompiler::compilePolygon(
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
403 LDPolygon& poly,
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
404 const QModelIndex& polygonOwnerIndex,
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
405 ObjectVboData& objectInfo
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
406 ) {
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1305
diff changeset
407 if (m_renderer->model()->winding() == Clockwise)
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1305
diff changeset
408 ::invertPolygon(poly);
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1305
diff changeset
409
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: 1122
diff changeset
410 VboClass surface;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
411
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
412 switch (poly.num)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
413 {
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
414 case 2:
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
415 surface = VboClass::Lines;
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
416 break;
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
417
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
418 case 3:
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
419 surface = VboClass::Triangles;
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
420 break;
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
421
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
422 case 4:
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
423 surface = VboClass::Quads;
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
424 break;
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
425
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
426 case 5:
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
427 surface = VboClass::ConditionalLines;
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
428 break;
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
429
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
430 default:
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
431 return;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
432 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
433
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: 1113
diff changeset
434 // Determine the normals for the polygon.
1313
4baed9f54de3 reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents: 1306
diff changeset
435 QVector3D normals[4];
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
436 auto vertexRing = ring(poly.vertices, poly.numPolygonVertices());
1122
795d1c3554b9 Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents: 1121
diff changeset
437
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
438 for (int i = 0; i < poly.numPolygonVertices(); ++i)
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: 1113
diff changeset
439 {
1122
795d1c3554b9 Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents: 1121
diff changeset
440 const Vertex& v1 = vertexRing[i - 1];
795d1c3554b9 Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents: 1121
diff changeset
441 const Vertex& v2 = vertexRing[i];
795d1c3554b9 Added the RingAdapter class and interfacing ring() function and simplified some math in GLCompiler with it
Teemu Piippo <teemu@hecknology.net>
parents: 1121
diff changeset
442 const Vertex& v3 = vertexRing[i + 1];
1313
4baed9f54de3 reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents: 1306
diff changeset
443 normals[i] = QVector3D::crossProduct(v3 - v2, v1 - v2).normalized();
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: 1113
diff changeset
444 }
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: 1113
diff changeset
445
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
446 // Transform vertices so that they're suitable for GL rendering
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
447 for (int i = 0; i < poly.numPolygonVertices(); i += 1)
1371
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
448 {
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
449 poly.vertices[i].y = -poly.vertices[i].y;
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
450 poly.vertices[i].z = -poly.vertices[i].z;
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
451
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
452 // Add these vertices to the bounding box (unless we're going to do it over
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
453 // from scratch afterwards)
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
454 if (not this->needBoundingBoxRebuild)
1371
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
455 this->boundingBox.consider(poly.vertices[i]);
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
456 }
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
457
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: 1122
diff changeset
458 for (VboSubclass complement : iterateEnum<VboSubclass>())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
459 {
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
460 const int vbonum = vboNumber (surface, complement);
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
461 QVector<GLfloat>& vbodata = objectInfo.data[vbonum];
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
462 const QColor color = getColorForPolygon (poly, polygonOwnerIndex, complement);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
463
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
464 for (int vert = 0; vert < poly.numPolygonVertices(); ++vert)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
465 {
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: 1122
diff changeset
466 if (complement == VboSubclass::Surfaces)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
467 {
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
468 // Write coordinates. Apparently Z must be flipped too?
1313
4baed9f54de3 reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents: 1306
diff changeset
469 vbodata << poly.vertices[vert].x
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
470 << poly.vertices[vert].y
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
471 << poly.vertices[vert].z;
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
472 }
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: 1122
diff changeset
473 else if (complement == VboSubclass::Normals)
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: 1113
diff changeset
474 {
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: 1113
diff changeset
475 vbodata << normals[vert].x()
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: 1113
diff changeset
476 << -normals[vert].y()
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: 1113
diff changeset
477 << -normals[vert].z();
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: 1113
diff changeset
478 }
1237
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1173
diff changeset
479 else if (complement == VboSubclass::InvertedNormals)
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1173
diff changeset
480 {
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1173
diff changeset
481 vbodata << -normals[vert].x();
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1173
diff changeset
482 vbodata << +normals[vert].y();
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1173
diff changeset
483 vbodata << +normals[vert].z();
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1173
diff changeset
484 }
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
485 else
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
486 {
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
487 vbodata << ((GLfloat) color.red()) / 255.0f
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
488 << ((GLfloat) color.green()) / 255.0f
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
489 << ((GLfloat) color.blue()) / 255.0f
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
490 << ((GLfloat) color.alpha()) / 255.0f;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
491 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
492 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
493 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
494 }
857
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
495
1371
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
496 /*
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
497 * Returns the center point of the model.
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
498 */
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
499 Vertex GLCompiler::modelCenter()
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
500 {
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
501 // If there's something still queued for compilation, we need to build those first so
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
502 // that they get into the bounding box.
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
503 this->compileStaged();
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
504
1371
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
505 // If the bounding box is invalid, rebuild it now.
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
506 if (this->needBoundingBoxRebuild)
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
507 {
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
508 this->boundingBox = {};
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
509 QMapIterator<QPersistentModelIndex, ObjectVboData> iterator {m_objectInfo};
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
510
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
511 while (iterator.hasNext())
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
512 {
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
513 iterator.next();
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
514
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
515 for (VboClass vboclass : {
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
516 VboClass::Lines,
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
517 VboClass::Triangles,
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
518 VboClass::Quads,
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
519 VboClass::ConditionalLines
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
520 }) {
1371
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
521 // Read in the surface vertices and add them to the bounding box.
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
522 int vbonum = vboNumber(vboclass, VboSubclass::Surfaces);
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
523 const auto& vector = iterator.value().data[vbonum];
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
524
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
525 for (int i = 0; i + 2 < countof(vector); i += 3)
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
526 this->boundingBox.consider({vector[i], vector[i + 1], vector[i + 2]});
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
527 }
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
528 }
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
529
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
530 this->needBoundingBoxRebuild = false;
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
531 }
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
532
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
533 if (not this->boundingBox.isEmpty())
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
534 return this->boundingBox.center();
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
535 else
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
536 return {};
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
537 }
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
538
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: 1122
diff changeset
539 int GLCompiler::vboNumber (VboClass surface, VboSubclass complement)
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
540 {
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: 1122
diff changeset
541 return (static_cast<int>(surface) * EnumLimits<VboSubclass>::Count) + static_cast<int>(complement);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
542 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
543
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
544
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
545 GLuint GLCompiler::vbo (int vbonum) const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
546 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
547 return m_vbo[vbonum];
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
548 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
549
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
550
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
551 int GLCompiler::vboSize (int vbonum) const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
552 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
553 return m_vboSizes[vbonum];
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: 1098
diff changeset
554 }
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
555
1306
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1305
diff changeset
556 void GLCompiler::fullUpdate()
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1305
diff changeset
557 {
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1305
diff changeset
558 m_objectInfo.clear();
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1305
diff changeset
559 recompile();
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1305
diff changeset
560 }
be85306198a2 red/green view rework complete
Teemu Piippo <teemu@hecknology.net>
parents: 1305
diff changeset
561
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
562 /*
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
563 * Recompiles the entire model.
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1159
diff changeset
564 */
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: 1098
diff changeset
565 void GLCompiler::recompile()
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
566 {
1244
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
567 for (QModelIndex index : m_renderer->model()->indices())
68e126e8c629 begin model rework
Santeri Piippo
parents: 1239
diff changeset
568 compileObject(index);
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
569
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
570 emit sceneChanged();
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: 1098
diff changeset
571 }
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
572
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
573 void GLCompiler::handleRowInsertion(const QModelIndex&, int first, int last)
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
574 {
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
575 for (int row = first; row <= last; row += 1)
1247
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
576 m_staged.insert(m_renderer->model()->index(row));
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
577
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
578 emit sceneChanged();
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
579 }
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
580
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
581 void GLCompiler::handleRowRemoval(const QModelIndex&, int first, int last)
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
582 {
1282
c6bc95cbf4a3 fixed removing objects causing some other objects to disappear
Santeri Piippo
parents: 1278
diff changeset
583 for (int row = last; row >= first; row -= 1)
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
584 forgetObject(m_renderer->model()->index(row));
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
585
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
586 this->needBoundingBoxRebuild = true;
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
587 emit sceneChanged();
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
588 }
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
589
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
590 void GLCompiler::handleDataChange(const QModelIndex& topLeft, const QModelIndex& bottomRight)
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
591 {
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
592 for (int row = topLeft.row(); row <= bottomRight.row(); row += 1)
1247
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
593 m_staged.insert(m_renderer->model()->index(row));
1371
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
594
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1332
diff changeset
595 this->needBoundingBoxRebuild = true;
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
596 emit sceneChanged();
1247
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
597 }
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
598
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
599 void GLCompiler::handleObjectHighlightingChanged(
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
600 const QModelIndex& oldIndex,
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
601 const QModelIndex& newIndex
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
602 ) {
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
603 m_staged.insert(oldIndex);
7e1ce2fc066b converted highlighting to mvc
Santeri Piippo
parents: 1246
diff changeset
604 m_staged.insert(newIndex);
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
605 emit sceneChanged();
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1244
diff changeset
606 }
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
607
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
608 void GLCompiler::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected)
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
609 {
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
610 for (const QModelIndex& index : selected.indexes())
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
611 m_staged.insert(index);
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
612
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
613 for (const QModelIndex& index : deselected.indexes())
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
614 m_staged.insert(index);
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
615
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
616 m_renderer->update();
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
617 emit sceneChanged();
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
618 }
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
619
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
620 QItemSelectionModel* GLCompiler::selectionModel() const
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
621 {
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
622 return _selectionModel;
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
623 }
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
624
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
625 void GLCompiler::setSelectionModel(QItemSelectionModel* selectionModel)
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
626 {
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
627 if (this->_selectionModel)
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
628 disconnect(this->_selectionModel, 0, 0, 0);
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
629
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
630 this->_selectionModel = selectionModel;
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
631
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
632 if (this->_selectionModel)
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
633 {
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
634 connect(
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
635 this->_selectionModel,
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
636 SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
637 this,
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
638 SLOT(selectionChanged(const QItemSelection&, const QItemSelection&))
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
639 );
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
640 connect(
1251
e75cc5bff076 Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents: 1247
diff changeset
641 this->_selectionModel,
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
642 SIGNAL(destroyed(QObject*)),
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
643 this,
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
644 SLOT(clearSelectionModel())
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
645 );
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
646 }
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
647
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
648 emit sceneChanged();
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
649 }
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
650
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
651 void GLCompiler::clearSelectionModel()
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
652 {
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
653 this->setSelectionModel(nullptr);
1372
641060842b92 fixed the scene bounding box not getting updated as it should
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
654 emit sceneChanged();
1246
0054d13ed614 used mvc selection models
Santeri Piippo
parents: 1245
diff changeset
655 }

mercurial