Thu, 22 Feb 2018 11:41:58 +0200
Converted magic wand mode and other selection stuff to mvc
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 |
1072 | 3 | * Copyright (C) 2013 - 2017 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" |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | #include "miscallenous.h" |
986
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
24 | #include "guiutilities.h" |
1012 | 25 | #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
|
26 | #include "grid.h" |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
28 | void checkGLError(HierarchyElement* element, QString file, int line) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | { |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
30 | struct ErrorInfo |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
31 | { |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
32 | GLenum value; |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
33 | QString text; |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
34 | }; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
36 | static const ErrorInfo knownErrors[] = |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
37 | { |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
38 | { GL_NO_ERROR, "No error" }, |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
39 | { GL_INVALID_ENUM, "Unacceptable enumerator passed" }, |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
40 | { GL_INVALID_VALUE, "Numeric argument out of range" }, |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
41 | { 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
|
42 | { GL_INVALID_FRAMEBUFFER_OPERATION, "Framebuffer object is not complete"}, |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
43 | { GL_OUT_OF_MEMORY, "Out of memory" }, |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
44 | { GL_STACK_UNDERFLOW, "The operation would have caused an underflow" }, |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
45 | { GL_STACK_OVERFLOW, "The operation would have caused an overflow" }, |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
46 | }; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
48 | GLenum errorNumber = glGetError(); |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
50 | if (errorNumber != GL_NO_ERROR) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | { |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
52 | QString errorMessage; |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
53 | |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
54 | for (const ErrorInfo& error : knownErrors) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | { |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
56 | if (error.value == errorNumber) |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
57 | { |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
58 | errorMessage = error.text; |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
59 | break; |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
60 | } |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | } |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
62 | |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
63 | element->print("OpenGL ERROR: at %1:%2: %3", Basename(file), line, errorMessage); |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | } |
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 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
67 | /* |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
68 | * Constructs a GL compiler. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
69 | */ |
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
|
70 | GLCompiler::GLCompiler (GLRenderer* renderer) : |
971
c00f9665a9f8
Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
970
diff
changeset
|
71 | 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
|
72 | m_renderer (renderer) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | { |
1245 | 74 | connect( |
75 | renderer->model(), | |
76 | SIGNAL(rowsInserted(QModelIndex, int, int)), | |
77 | this, | |
78 | SLOT(handleRowInsertion(QModelIndex, int, int)) | |
79 | ); | |
80 | connect( | |
81 | renderer->model(), | |
82 | SIGNAL(rowsRemoved(QModelIndex, int, int)), | |
83 | this, | |
84 | SLOT(handleRowRemoval(QModelIndex, int, int)) | |
85 | ); | |
86 | connect( | |
87 | renderer->model(), | |
88 | SIGNAL(dataChanged(QModelIndex, QModelIndex, QVector<int>)), | |
89 | this, | |
90 | SLOT(handleDataChange(QModelIndex, QModelIndex)) | |
91 | ); | |
1247 | 92 | connect( |
93 | renderer, | |
94 | SIGNAL(objectHighlightingChanged(QModelIndex, QModelIndex)), | |
95 | this, | |
96 | SLOT(handleObjectHighlightingChanged(QModelIndex, QModelIndex)) | |
97 | ); | |
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
|
98 | 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
|
99 | |
1244 | 100 | for (QModelIndex index : renderer->model()->indices()) |
101 | { | |
102 | print("%1", index); | |
103 | stageForCompilation(index); | |
104 | } | |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
107 | /* |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
108 | * Initializes the VBOs after OpenGL is initialized. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
109 | */ |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | void GLCompiler::initialize() |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | { |
855
e16f1587ef44
- fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents:
852
diff
changeset
|
112 | initializeOpenGLFunctions(); |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
113 | glGenBuffers(countof(m_vbo), &m_vbo[0]); |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
114 | CHECK_GL_ERROR(); |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
117 | /* |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
118 | * Destructs the VBOs when the compiler is deleted. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
119 | */ |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | GLCompiler::~GLCompiler() |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
121 | { |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
122 | glDeleteBuffers(countof(m_vbo), &m_vbo[0]); |
861
83426c5fa732
- major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents:
857
diff
changeset
|
123 | CHECK_GL_ERROR(); |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
126 | /* |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
127 | * 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
|
128 | */ |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
129 | QColor GLCompiler::indexColorForID (qint32 id) const |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | { |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | // Calculate a color based from this index. This method caters for |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | // 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
|
133 | 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
|
134 | 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
|
135 | 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
|
136 | return {r, g, b}; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
139 | /* |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
140 | * Returns the suitable color for the polygon. |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
141 | * - polygon is the polygon to colorise. |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
142 | * - polygonOwner is the LDObject from which the polygon originated. |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
143 | * - subclass provides context for the polygon. |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
144 | */ |
1246 | 145 | QColor GLCompiler::getColorForPolygon( |
146 | LDPolygon& polygon, | |
147 | const QModelIndex& polygonOwnerIndex, | |
148 | VboSubclass subclass | |
149 | ) { | |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
150 | QColor color; |
1246 | 151 | LDObject* polygonOwner = m_renderer->model()->lookup(polygonOwnerIndex); |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
153 | switch (subclass) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | { |
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
|
155 | 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
|
156 | case VboSubclass::Normals: |
1239 | 157 | 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
|
158 | case VboSubclass::_End: |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
159 | // 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
|
160 | 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
|
161 | |
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
|
162 | case VboSubclass::BfcFrontColors: |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
163 | // Use the constant green color for BFC front colors |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
164 | 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
|
165 | |
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
|
166 | case VboSubclass::BfcBackColors: |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
167 | // Use the constant red color for BFC back colors |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
168 | 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
|
169 | |
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
|
170 | case VboSubclass::PickColors: |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
171 | // For the picking scene, determine the color from the owner's ID. |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
172 | return indexColorForID(polygonOwner->id()); |
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
|
173 | |
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
|
174 | case VboSubclass::RandomColors: |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
175 | // 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
|
176 | color = polygonOwner->randomColor(); |
986
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
177 | break; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
179 | case VboSubclass::RegularColors: |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
180 | // For normal colors, use the polygon's color. |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
181 | if (polygon.color == MainColor) |
986
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
182 | { |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
183 | // 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
|
184 | if (polygonOwner->color() == MainColor) |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
185 | { |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
186 | // 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
|
187 | color = guiUtilities()->mainColorRepresentation(); |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
188 | } |
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
|
189 | else |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
190 | { |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
191 | color = polygonOwner->color().faceColor(); |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
192 | } |
986
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
193 | } |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
194 | else if (polygon.color == EdgeColor) |
986
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
195 | { |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
196 | // Edge color is black, unless we have a dark background, in which case lines need to be bright. |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
197 | color = luma(m_config->backgroundColor()) > 40 ? Qt::black : Qt::white; |
986
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
198 | } |
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
199 | else |
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
200 | { |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
201 | // 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
|
202 | color = LDColor {polygon.color}.faceColor(); |
986
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
203 | } |
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
204 | break; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
205 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
206 | |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
207 | 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
|
208 | { |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
209 | // 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
|
210 | 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
|
211 | |
1251
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
1247
diff
changeset
|
212 | 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
|
213 | blendAlpha = 1.0; |
1247 | 214 | 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
|
215 | 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
|
216 | |
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 | 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
|
218 | { |
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 | QColor selectedColor = m_config->selectColorBlend(); |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
220 | double denominator = blendAlpha + 1.0; |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
221 | color.setRed((color.red() + (selectedColor.red() * blendAlpha)) / denominator); |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
222 | color.setGreen((color.green() + (selectedColor.green() * blendAlpha)) / denominator); |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
223 | 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
|
224 | } |
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 | else |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
227 | { |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
228 | // 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
|
229 | if (polygon.num != 2 and polygon.num != 5) |
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
230 | color = guiUtilities()->mainColorRepresentation(); |
890
903ec1e46298
- backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents:
889
diff
changeset
|
231 | else |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
232 | color = Qt::black; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
233 | |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
234 | // 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
|
235 | static QSet<int> warnedColors; |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
236 | if (not warnedColors.contains(polygon.color)) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
237 | { |
1159
6ad8cdcd88d9
print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents:
1146
diff
changeset
|
238 | print(tr("Unknown color %1!\n"), polygon.color); |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
239 | warnedColors.insert(polygon.color); |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
240 | } |
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 | |
1127
3ab9d11dc76e
Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents:
1125
diff
changeset
|
243 | return color; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
244 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
245 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
246 | /* |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
247 | * Tells the compiler that a merge of VBOs is required. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
248 | */ |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | void GLCompiler::needMerge() |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
250 | { |
1065
c8ecddbd99e9
Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents:
1063
diff
changeset
|
251 | for (int i = 0; i < countof (m_vboChanged); ++i) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
252 | m_vboChanged[i] = true; |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
253 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
254 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
255 | /* |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
256 | * Stages the given object for compilation. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
257 | */ |
1245 | 258 | void GLCompiler::stageForCompilation(const QModelIndex& index) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
259 | { |
1244 | 260 | m_staged.insert(index); |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
261 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
262 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
263 | /* |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
264 | * Removes an object from the set of objects to be compiled. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
265 | */ |
1245 | 266 | void GLCompiler::unstage(const QModelIndex& index) |
721
4cf0f6c9082d
- now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents:
717
diff
changeset
|
267 | { |
1244 | 268 | m_staged.remove(index); |
269 | } | |
270 | ||
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
271 | /* |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
272 | * Compiles all staged objects. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
273 | */ |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
274 | void GLCompiler::compileStaged() |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
275 | { |
1244 | 276 | for (const QModelIndex& index : m_staged) |
277 | compileObject(index); | |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
278 | |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
279 | m_staged.clear(); |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
280 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
281 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
282 | /* |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
283 | * Prepares a VBO for rendering. The VBO is merged if needed. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
284 | */ |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
285 | void GLCompiler::prepareVBO (int vbonum) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
286 | { |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
287 | // Compile anything that still awaits it |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
288 | compileStaged(); |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
289 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
290 | if (m_vboChanged[vbonum]) |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
291 | { |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
292 | // Merge the VBO into a vector of floats. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
293 | QVector<GLfloat> vbodata; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
294 | |
1244 | 295 | for ( |
296 | auto iterator = m_objectInfo.begin(); | |
297 | iterator != m_objectInfo.end(); | |
298 | ) { | |
299 | if (not iterator.key().isValid()) | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
300 | { |
1244 | 301 | iterator = m_objectInfo.erase(iterator); |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
302 | } |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
303 | else |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
304 | { |
1245 | 305 | LDObject* object = m_renderer->model()->lookup(iterator.key()); |
1244 | 306 | if (not object->isHidden()) |
307 | vbodata += iterator->data[vbonum]; | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
308 | |
1244 | 309 | ++iterator; |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
310 | } |
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
|
311 | } |
886
3c83fe3486b1
- fixed endless loop in prepareVBO due to badly incremented iterator
Teemu Piippo <crimsondusk64@gmail.com>
parents:
883
diff
changeset
|
312 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
313 | // Transfer the VBO to the graphics processor. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
314 | glBindBuffer (GL_ARRAY_BUFFER, m_vbo[vbonum]); |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
315 | 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
|
316 | glBindBuffer (GL_ARRAY_BUFFER, 0); |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
317 | CHECK_GL_ERROR(); |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
318 | m_vboChanged[vbonum] = false; |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
319 | m_vboSizes[vbonum] = countof(vbodata); |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
320 | } |
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 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
323 | /* |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
324 | * Removes the data related to the given object. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
325 | */ |
1244 | 326 | void GLCompiler::dropObjectInfo(const QModelIndex& index) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
327 | { |
1244 | 328 | if (m_objectInfo.contains(index)) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
329 | { |
1244 | 330 | // If we have data relating to this object, remove it. |
331 | // The VBOs have changed now and need to be merged. | |
332 | m_objectInfo.remove(index); | |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
333 | needMerge(); |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
334 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
335 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
336 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
337 | /* |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
338 | * Makes the compiler forget about the given object completely. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
339 | */ |
1244 | 340 | 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
|
341 | { |
1244 | 342 | dropObjectInfo(index); |
343 | 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
|
344 | } |
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
|
345 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
346 | /* |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
347 | * Compiles a single object. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
348 | */ |
1246 | 349 | void GLCompiler::compileObject(const QModelIndex& index) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
350 | { |
1245 | 351 | LDObject* object = m_renderer->model()->lookup(index); |
1244 | 352 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
353 | if (object == nullptr) |
708
3155f2c05f89
- more debugging...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
354 | return; |
3155f2c05f89
- more debugging...
Santeri Piippo <crimsondusk64@gmail.com>
parents:
706
diff
changeset
|
355 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
356 | ObjectVboData info; |
1244 | 357 | 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
|
358 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
359 | 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
|
360 | { |
1244 | 361 | // Note: We cannot split quads into triangles here, it would mess up the |
362 | // 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
|
363 | case LDObjectType::Triangle: |
1139
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1127
diff
changeset
|
364 | case LDObjectType::Quadrilateral: |
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1127
diff
changeset
|
365 | case LDObjectType::EdgeLine: |
51303023d651
LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents:
1127
diff
changeset
|
366 | 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
|
367 | { |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
368 | LDPolygon* poly = object->getPolygon(); |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
369 | poly->id = object->id(); |
1246 | 370 | 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
|
371 | 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
|
372 | 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
|
373 | } |
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 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
375 | // TODO: try use interfaces to remove these special treatments? |
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::SubfileReference: |
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
|
377 | { |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
378 | LDSubfileReference* subfileReference = static_cast<LDSubfileReference*>(object); |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
379 | auto data = subfileReference->inlinePolygons(); |
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
|
380 | |
9a53d9a379de
- refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
725
diff
changeset
|
381 | for (LDPolygon& poly : data) |
9a53d9a379de
- refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
725
diff
changeset
|
382 | { |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
383 | poly.id = object->id(); |
1246 | 384 | 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
|
385 | } |
9a53d9a379de
- refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
725
diff
changeset
|
386 | 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
|
387 | } |
9a53d9a379de
- refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
725
diff
changeset
|
388 | |
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
|
389 | case LDObjectType::BezierCurve: |
1004
ba4200437179
Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
390 | { |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
391 | 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
|
392 | for (LDPolygon& polygon : curve->rasterizePolygons(grid()->bezierCurveSegments())) |
1004
ba4200437179
Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
393 | { |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
394 | polygon.id = object->id(); |
1246 | 395 | compilePolygon (polygon, index, info); |
1004
ba4200437179
Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
396 | } |
ba4200437179
Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
397 | } |
ba4200437179
Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
398 | break; |
ba4200437179
Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents:
998
diff
changeset
|
399 | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
400 | default: |
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
401 | 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
|
402 | } |
9a53d9a379de
- refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
725
diff
changeset
|
403 | |
1244 | 404 | m_objectInfo[index] = info; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
405 | needMerge(); |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
406 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
407 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
408 | /* |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
409 | * Inserts a single polygon into VBOs. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
410 | */ |
1246 | 411 | void GLCompiler::compilePolygon( |
412 | LDPolygon& poly, | |
413 | const QModelIndex& polygonOwnerIndex, | |
414 | ObjectVboData& objectInfo | |
415 | ) { | |
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
|
416 | VboClass surface; |
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
|
417 | int vertexCount; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
418 | |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
419 | switch (poly.num) |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
420 | { |
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
|
421 | case 2: surface = VboClass::Lines; vertexCount = 2; break; |
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
|
422 | case 3: surface = VboClass::Triangles; vertexCount = 3; break; |
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
|
423 | case 4: surface = VboClass::Quads; vertexCount = 4; break; |
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
|
424 | case 5: surface = VboClass::ConditionalLines; vertexCount = 2; break; |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
425 | default: return; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
426 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
427 | |
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
|
428 | // Determine the normals for the polygon. |
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
|
429 | Vertex normals[4]; |
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
|
430 | auto vertexRing = ring(poly.vertices, vertexCount); |
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
|
431 | |
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
|
432 | for (int i = 0; i < vertexCount; ++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
|
433 | { |
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
|
434 | 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
|
435 | 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
|
436 | const Vertex& v3 = vertexRing[i + 1]; |
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
|
437 | normals[i] = Vertex::crossProduct(v3 - v2, v1 - v2).normalized(); |
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
|
438 | } |
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 | |
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
|
440 | for (VboSubclass complement : iterateEnum<VboSubclass>()) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
441 | { |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
442 | const int vbonum = vboNumber (surface, complement); |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
443 | QVector<GLfloat>& vbodata = objectInfo.data[vbonum]; |
1246 | 444 | const QColor color = getColorForPolygon (poly, polygonOwnerIndex, complement); |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
445 | |
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
|
446 | for (int vert = 0; vert < vertexCount; ++vert) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
447 | { |
1123
15e46ea3151f
Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents:
1122
diff
changeset
|
448 | if (complement == VboSubclass::Surfaces) |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
449 | { |
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
|
450 | // Write coordinates. Apparently Z must be flipped too? |
9a53d9a379de
- refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
725
diff
changeset
|
451 | vbodata << poly.vertices[vert].x() |
9a53d9a379de
- refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
725
diff
changeset
|
452 | << -poly.vertices[vert].y() |
9a53d9a379de
- refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
725
diff
changeset
|
453 | << -poly.vertices[vert].z(); |
9a53d9a379de
- refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
725
diff
changeset
|
454 | } |
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
|
455 | 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
|
456 | { |
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
|
457 | 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
|
458 | << -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
|
459 | << -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
|
460 | } |
1237
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1173
diff
changeset
|
461 | else if (complement == VboSubclass::InvertedNormals) |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1173
diff
changeset
|
462 | { |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1173
diff
changeset
|
463 | vbodata << -normals[vert].x(); |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1173
diff
changeset
|
464 | vbodata << +normals[vert].y(); |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1173
diff
changeset
|
465 | vbodata << +normals[vert].z(); |
40bb00d82e2b
moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents:
1173
diff
changeset
|
466 | } |
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
|
467 | 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
|
468 | { |
9a53d9a379de
- refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents:
725
diff
changeset
|
469 | 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
|
470 | << ((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
|
471 | << ((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
|
472 | << ((GLfloat) color.alpha()) / 255.0f; |
706
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
473 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
474 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
475 | } |
d79083b9f74d
Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
476 | } |
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
|
477 | |
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
|
478 | int GLCompiler::vboNumber (VboClass surface, VboSubclass complement) |
986
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
479 | { |
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
|
480 | 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
|
481 | } |
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
482 | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
483 | |
986
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
484 | GLuint GLCompiler::vbo (int vbonum) const |
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
485 | { |
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
486 | return m_vbo[vbonum]; |
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
487 | } |
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
488 | |
1011
4fdd74a04790
Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents:
1006
diff
changeset
|
489 | |
986
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
490 | int GLCompiler::vboSize (int vbonum) const |
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
491 | { |
525921eae58c
Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents:
985
diff
changeset
|
492 | 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
|
493 | } |
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
|
494 | |
1173
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
495 | /* |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
496 | * Recompiles the entire model. |
6cd85b28f43b
Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents:
1159
diff
changeset
|
497 | */ |
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
|
498 | 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
|
499 | { |
1244 | 500 | for (QModelIndex index : m_renderer->model()->indices()) |
501 | compileObject(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
|
502 | } |
1245 | 503 | |
504 | void GLCompiler::handleRowInsertion(const QModelIndex&, int first, int last) | |
505 | { | |
506 | for (int row = first; row <= last; row += 1) | |
1247 | 507 | m_staged.insert(m_renderer->model()->index(row)); |
1245 | 508 | } |
509 | ||
510 | void GLCompiler::handleRowRemoval(const QModelIndex&, int first, int last) | |
511 | { | |
512 | for (int row = first; row <= last; row += 1) | |
513 | forgetObject(m_renderer->model()->index(row)); | |
514 | } | |
515 | ||
516 | void GLCompiler::handleDataChange(const QModelIndex& topLeft, const QModelIndex& bottomRight) | |
517 | { | |
518 | for (int row = topLeft.row(); row <= bottomRight.row(); row += 1) | |
1247 | 519 | m_staged.insert(m_renderer->model()->index(row)); |
520 | } | |
521 | ||
522 | void GLCompiler::handleObjectHighlightingChanged( | |
523 | const QModelIndex& oldIndex, | |
524 | const QModelIndex& newIndex | |
525 | ) { | |
526 | m_staged.insert(oldIndex); | |
527 | m_staged.insert(newIndex); | |
1245 | 528 | } |
1246 | 529 | |
530 | void GLCompiler::selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) | |
531 | { | |
532 | for (const QModelIndex& index : selected.indexes()) | |
533 | m_staged.insert(index); | |
534 | ||
535 | for (const QModelIndex& index : deselected.indexes()) | |
536 | m_staged.insert(index); | |
537 | ||
538 | m_renderer->update(); | |
539 | } | |
540 | ||
1251
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
1247
diff
changeset
|
541 | QItemSelectionModel* GLCompiler::selectionModel() const |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
1247
diff
changeset
|
542 | { |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
1247
diff
changeset
|
543 | return _selectionModel; |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
1247
diff
changeset
|
544 | } |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
1247
diff
changeset
|
545 | |
1246 | 546 | void GLCompiler::setSelectionModel(QItemSelectionModel* selectionModel) |
547 | { | |
1251
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
1247
diff
changeset
|
548 | if (this->_selectionModel) |
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
1247
diff
changeset
|
549 | disconnect(this->_selectionModel, 0, 0, 0); |
1246 | 550 | |
1251
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
1247
diff
changeset
|
551 | this->_selectionModel = selectionModel; |
1246 | 552 | |
1251
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
1247
diff
changeset
|
553 | if (this->_selectionModel) |
1246 | 554 | { |
555 | connect( | |
1251
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
1247
diff
changeset
|
556 | this->_selectionModel, |
1246 | 557 | SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)), |
558 | this, | |
559 | SLOT(selectionChanged(const QItemSelection&, const QItemSelection&)) | |
560 | ); | |
561 | connect( | |
1251
e75cc5bff076
Converted magic wand mode and other selection stuff to mvc
Santeri Piippo
parents:
1247
diff
changeset
|
562 | this->_selectionModel, |
1246 | 563 | SIGNAL(destroyed(QObject*)), |
564 | this, | |
565 | SLOT(clearSelectionModel()) | |
566 | ); | |
567 | } | |
568 | } | |
569 | ||
570 | void GLCompiler::clearSelectionModel() | |
571 | { | |
572 | this->setSelectionModel(nullptr); | |
573 | } |