src/glcompiler.cpp

Thu, 23 Feb 2017 20:18:39 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 23 Feb 2017 20:18:39 +0200
changeset 1159
6ad8cdcd88d9
parent 1146
bb728c124d47
child 1173
6cd85b28f43b
permissions
-rw-r--r--

print() is no longer a global function but is tied to HierarchyElement.

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
9ce9496427f2 Happy new year 2017!
Teemu Piippo <teemu@hecknology.net>
parents: 1065
diff changeset
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
413ecd6b9801 It worx again!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
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
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 struct GLErrorInfo
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
29 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 GLenum value;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
31 QString text;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32 };
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 static const GLErrorInfo g_GLErrors[] =
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 { GL_NO_ERROR, "No error" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 { GL_INVALID_ENUM, "Unacceptable enumerator passed" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38 { GL_INVALID_VALUE, "Numeric argument out of range" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 { GL_INVALID_OPERATION, "The operation is not allowed to be done in this state" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 { GL_INVALID_FRAMEBUFFER_OPERATION, "Framebuffer object is not complete"},
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 { GL_OUT_OF_MEMORY, "Out of memory" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 { GL_STACK_UNDERFLOW, "The operation would have caused an underflow" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 { GL_STACK_OVERFLOW, "The operation would have caused an overflow" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 };
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45
1159
6ad8cdcd88d9 print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
46 void CheckGLErrorImpl (HierarchyElement* element, const char* file, int line)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
48 QString errmsg;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 GLenum errnum = glGetError();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 if (errnum == GL_NO_ERROR)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52 return;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 for (const GLErrorInfo& err : g_GLErrors)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 if (err.value == errnum)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 errmsg = err.text;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 break;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62
1159
6ad8cdcd88d9 print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
63 element->print ("OpenGL ERROR: at %1:%2: %3", Basename (QString (file)), line, errmsg);
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
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
66
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
67 GLCompiler::GLCompiler (GLRenderer* renderer) :
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
68 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
69 m_renderer (renderer)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 {
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
71 connect(renderer->model(), SIGNAL(objectAdded(LDObject*)), this, SLOT(compileObject(LDObject*)));
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
72 connect(renderer->model(), SIGNAL(objectModified(LDObject*)), this, SLOT(compileObject(LDObject*)));
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
73 connect(renderer->model(), SIGNAL(aboutToRemoveObject(LDObject*)), this, SLOT(forgetObject(LDObject*)), Qt::DirectConnection);
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
74 connect(renderer, SIGNAL(objectHighlightingChanged(LDObject*)), this, SLOT(compileObject(LDObject*)));
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
75 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
76
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
77 for (LDObject* object : renderer->model()->objects())
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
78 stageForCompilation(object);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
79 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
81
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 void GLCompiler::initialize()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 {
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
84 initializeOpenGLFunctions();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
85 glGenBuffers (NumVbos, &m_vbo[0]);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
86 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
89
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 GLCompiler::~GLCompiler()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
92 glDeleteBuffers (NumVbos, &m_vbo[0]);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
93 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
96
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 QColor GLCompiler::indexColorForID (int id) const
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 // Calculate a color based from this index. This method caters for
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 // 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
101 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
102 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
103 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
104 return {r, g, b};
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
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
107 /*
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
108 * Returns the suitable color for the polygon.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
109 * - polygon is the polygon to colorise.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
110 * - polygonOwner is the LDObject from which the polygon originated.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
111 * - subclass provides context for the polygon.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
112 */
1159
6ad8cdcd88d9 print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
113 QColor GLCompiler::getColorForPolygon(LDPolygon& polygon, LDObject* polygonOwner, VboSubclass subclass)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 {
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
115 QColor color;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
116
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
117 switch (subclass)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
118 {
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
119 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
120 case VboSubclass::Normals:
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
121 case VboSubclass::_End:
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
122 // 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
123 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
124
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
125 case VboSubclass::BfcFrontColors:
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
126 // Use the constant green color for BFC front colors
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
127 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
128
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
129 case VboSubclass::BfcBackColors:
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
130 // Use the constant red color for BFC back colors
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
131 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
132
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
133 case VboSubclass::PickColors:
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
134 // 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
135 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
136
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
137 case VboSubclass::RandomColors:
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
138 // 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
139 color = polygonOwner->randomColor();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
140 break;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
141
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
142 case VboSubclass::NormalColors:
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
143 // For normal colors, use the polygon's color.
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
144 if (polygon.color == MainColor)
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
145 {
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
146 // 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
147 if (polygonOwner->color() == MainColor)
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
148 {
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
149 // 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
150 color = guiUtilities()->mainColorRepresentation();
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
151 }
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
152 else
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
153 {
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
154 color = polygonOwner->color().faceColor();
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
155 }
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
156 }
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
157 else if (polygon.color == EdgeColor)
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
158 {
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
159 // 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
160 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
161 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
162 else
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
163 {
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
164 // 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
165 color = LDColor {polygon.color}.faceColor();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
166 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
167 break;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
168 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
170 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
171 {
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
172 // 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
173 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
174
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
175 if (polygonOwner->isSelected())
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
176 blendAlpha = 1.0;
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
177 else if (polygonOwner == 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
178 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
179
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
180 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
181 {
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
182 QColor selectedColor = m_config->selectColorBlend();
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
183 double denominator = blendAlpha + 1.0;
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
184 color.setRed((color.red() + (selectedColor.red() * blendAlpha)) / denominator);
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
185 color.setGreen((color.green() + (selectedColor.green() * blendAlpha)) / denominator);
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
186 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
187 }
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
188 }
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
189 else
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 {
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
191 // 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
192 if (polygon.num != 2 and polygon.num != 5)
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
193 color = guiUtilities()->mainColorRepresentation();
890
903ec1e46298 - backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 889
diff changeset
194 else
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
195 color = Qt::black;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197 // 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
198 static QSet<int> warnedColors;
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
199 if (not warnedColors.contains(polygon.color))
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 {
1159
6ad8cdcd88d9 print() is no longer a global function but is tied to HierarchyElement.
Teemu Piippo <teemu@hecknology.net>
parents: 1146
diff changeset
201 print(tr("Unknown color %1!\n"), polygon.color);
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
202 warnedColors.insert(polygon.color);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205
1127
3ab9d11dc76e Commented GLCompiler::getColorForPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1125
diff changeset
206 return color;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
207 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
209
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 void GLCompiler::needMerge()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211 {
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
212 for (int i = 0; i < countof (m_vboChanged); ++i)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 m_vboChanged[i] = true;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
214 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
216
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
217 void GLCompiler::stageForCompilation (LDObject* obj)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
218 {
943
af81220741d9 Commit work done on code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 920
diff changeset
219 m_staged << obj;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
221
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
222
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
223 void GLCompiler::unstage (LDObject* obj)
721
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
224 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
225 m_staged.remove (obj);
721
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
226 }
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
227
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
228
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 void GLCompiler::compileStaged()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 {
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
231 for (LDObject* object : m_staged)
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
232 compileObject(object);
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 m_staged.clear();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
237
1121
be0b5ad128ea Replaced uses of currentDocument() in GLRenderer with m_model
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
238 void GLCompiler::prepareVBO (int vbonum, const Model* model)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 // Compile anything that still awaits it
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 compileStaged();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242
716
639a900999bc - removed the debug code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 715
diff changeset
243 if (not m_vboChanged[vbonum])
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 return;
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 QVector<GLfloat> vbodata;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247
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
248 for (auto it = m_objectInfo.begin(); it != m_objectInfo.end();)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
249 {
984
a7b6f987d269 null -> nullptr
Teemu Piippo <crimsondusk64@gmail.com>
parents: 979
diff changeset
250 if (it.key() == nullptr)
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
251 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 772
diff changeset
252 it = m_objectInfo.erase (it);
886
3c83fe3486b1 - fixed endless loop in prepareVBO due to badly incremented iterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 883
diff changeset
253 continue;
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
254 }
886
3c83fe3486b1 - fixed endless loop in prepareVBO due to badly incremented iterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 883
diff changeset
255
1098
0b837bed121d LDGLData merged into GLRenderer since it only deals with one document now. GLRenderer generalised from rendering documents to models.
Teemu Piippo <teemu@hecknology.net>
parents: 1086
diff changeset
256 if (it.key()->model() == model and not it.key()->isHidden())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
257 vbodata += it->data[vbonum];
886
3c83fe3486b1 - fixed endless loop in prepareVBO due to badly incremented iterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 883
diff changeset
258
3c83fe3486b1 - fixed endless loop in prepareVBO due to badly incremented iterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 883
diff changeset
259 ++it;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
260 }
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 glBindBuffer (GL_ARRAY_BUFFER, m_vbo[vbonum]);
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
263 glBufferData (GL_ARRAY_BUFFER, countof(vbodata) * sizeof(GLfloat), vbodata.constData(), GL_STATIC_DRAW);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 glBindBuffer (GL_ARRAY_BUFFER, 0);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
265 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266 m_vboChanged[vbonum] = false;
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
267 m_vboSizes[vbonum] = countof(vbodata);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
268 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
269
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
270
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
271 void GLCompiler::dropObjectInfo(LDObject* object)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272 {
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
273 if (m_objectInfo.contains(object))
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 {
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
275 m_objectInfo.remove(object);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
276 needMerge();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
277 }
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
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
280 void GLCompiler::forgetObject(LDObject* object)
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
281 {
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
282 dropObjectInfo(object);
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
283 m_staged.remove(object);
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
284 }
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
285
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
286
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
287 void GLCompiler::compileObject (LDObject* obj)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288 {
1073
a0a0d581309b Major overhaul of object→document relationship: added the Model class which models the object buffer. Each object is to be included in a model (an invariant that currently does not hold). A document is a subclass of a model. The LDObject is also now agnostic about selection, and the selection is now a set. A lot of things are probably broken now but it's a major step forward.
Teemu Piippo <teemu@hecknology.net>
parents: 1072
diff changeset
289 if (obj == nullptr)
708
3155f2c05f89 - more debugging...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
290 return;
3155f2c05f89 - more debugging...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
291
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
292 ObjectVBOInfo info;
713
46377d340c23 - more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents: 708
diff changeset
293 info.isChanged = true;
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
294 dropObjectInfo (obj);
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
295
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
296 switch (obj->type())
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
297 {
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
298 // Note: We cannot split quads into triangles here, it would mess up the wireframe view.
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
299 // 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
300 case LDObjectType::Triangle:
1139
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1127
diff changeset
301 case LDObjectType::Quadrilateral:
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1127
diff changeset
302 case LDObjectType::EdgeLine:
51303023d651 LDObject subclass renaming:
Teemu Piippo <teemu@hecknology.net>
parents: 1127
diff changeset
303 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
304 {
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
305 LDPolygon* poly = obj->getPolygon();
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
306 poly->id = obj->id();
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
307 compilePolygon (*poly, obj, &info);
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
308 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
309 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
310 }
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
311
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
312 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
313 {
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
314 LDSubfileReference* ref = static_cast<LDSubfileReference*> (obj);
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
315 auto data = ref->inlinePolygons();
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
316
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
317 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
318 {
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
319 poly.id = obj->id();
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
320 compilePolygon (poly, obj, &info);
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
321 }
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
322 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
323 }
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
324
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
325 case LDObjectType::BezierCurve:
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
326 {
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
327 LDBezierCurve* curve = static_cast<LDBezierCurve*> (obj);
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
328 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
329 {
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
330 polygon.id = obj->id();
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
331 compilePolygon (polygon, obj, &info);
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
332 }
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
333 }
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
334 break;
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
335
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
336 default:
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
337 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
338 }
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
339
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340 m_objectInfo[obj] = info;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 needMerge();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
342 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
343
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
344
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
345 void GLCompiler::compilePolygon (LDPolygon& poly, LDObject* topobj, ObjectVBOInfo* objinfo)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 {
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
347 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
348 int vertexCount;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
349
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
350 switch (poly.num)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351 {
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
352 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
353 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
354 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
355 case 5: surface = VboClass::ConditionalLines; vertexCount = 2; break;
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
356 default: return;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
357 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
358
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
359 // 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
360 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
361 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
362
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
363 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
364 {
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
365 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
366 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
367 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
368 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
369 }
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
370
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
371 for (VboSubclass complement : iterateEnum<VboSubclass>())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
372 {
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
373 const int vbonum = vboNumber (surface, complement);
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
374 QVector<GLfloat>& vbodata = objinfo->data[vbonum];
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
375 const QColor color = getColorForPolygon (poly, topobj, complement);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
376
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
377 for (int vert = 0; vert < vertexCount; ++vert)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
378 {
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
379 if (complement == VboSubclass::Surfaces)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 {
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
381 // 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
382 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
383 << -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
384 << -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
385 }
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
386 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
387 {
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
388 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
389 << -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
390 << -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
391 }
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
392 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
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 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
395 << ((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
396 << ((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
397 << ((GLfloat) color.alpha()) / 255.0f;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
398 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
399 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
400 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
401 }
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
402
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
403
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
404 void GLCompiler::setRenderer (GLRenderer* renderer)
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
405 {
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
406 m_renderer = renderer;
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
407 }
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
408
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
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 int GLCompiler::vboNumber (VboClass surface, VboSubclass complement)
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
411 {
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
412 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
413 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
414
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
415
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
416 GLuint GLCompiler::vbo (int vbonum) const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
417 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
418 return m_vbo[vbonum];
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
419 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
420
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
421
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
422 int GLCompiler::vboSize (int vbonum) const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
423 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
424 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
425 }
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
426
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
427
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
428 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
429 {
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
430 for (LDObject* object : m_renderer->model()->objects())
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
431 compileObject(object);
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
432 }

mercurial