src/glCompiler.cpp

Sun, 12 Feb 2017 16:02:02 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 12 Feb 2017 16:02:02 +0200
changeset 1123
15e46ea3151f
parent 1122
795d1c3554b9
child 1125
d8f94e56d42e
permissions
-rw-r--r--

Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"

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>
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
22 #include "glCompiler.h"
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
970
c8aae45afd85 Commit configuration rework (doesn't work yet, more than most probably doesn't compile either)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
46 ConfigOption (QString SelectColorBlend = "#0080FF")
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 716
diff changeset
47
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
48 void CheckGLErrorImpl (const char* file, int line)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
50 QString errmsg;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51 GLenum errnum = glGetError();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
52
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
53 if (errnum == GL_NO_ERROR)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 return;
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 for (const GLErrorInfo& err : g_GLErrors)
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 if (err.value == errnum)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 errmsg = err.text;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 break;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
63 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
64
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
65 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
66 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
68
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 GLCompiler::GLCompiler (GLRenderer* renderer) :
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
70 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
71 m_renderer (renderer)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
72 {
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
73 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
74 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
75 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
76 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
77 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
78
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
79 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
80 stageForCompilation(object);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
83
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 void GLCompiler::initialize()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 {
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
86 initializeOpenGLFunctions();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
87 glGenBuffers (NumVbos, &m_vbo[0]);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
88 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
91
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 GLCompiler::~GLCompiler()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
94 glDeleteBuffers (NumVbos, &m_vbo[0]);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
95 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
98
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
99 QColor GLCompiler::indexColorForID (int id) const
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 // Calculate a color based from this index. This method caters for
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 // 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
103 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
104 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
105 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
106 return {r, g, b};
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
107 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
108
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
109
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
110 QColor GLCompiler::getColorForPolygon (LDPolygon& poly, LDObject* topobj, VboSubclass complement) const
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
112 QColor qcol;
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
113 static const QColor bfcFrontColor {64, 192, 80};
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
114 static const QColor bfcBackColor {208, 64, 64};
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
115
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
116 switch (complement)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117 {
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
118 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
119 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
120 case VboSubclass::_End:
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
121 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
122
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
123 case VboSubclass::BfcFrontColors:
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
124 qcol = bfcFrontColor;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
125 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
126
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
127 case VboSubclass::BfcBackColors:
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
128 qcol = bfcBackColor;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
129 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
130
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
131 case VboSubclass::PickColors:
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
132 return indexColorForID(topobj->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
133
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
134 case VboSubclass::RandomColors:
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
135 qcol = topobj->randomColor();
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
136 break;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
137
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
138 case VboSubclass::NormalColors:
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
139 if (poly.color == MainColor)
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
140 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
141 if (topobj->color() == MainColor)
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
142 qcol = guiUtilities()->mainColorRepresentation();
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
143 else
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
144 qcol = topobj->color().faceColor();
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
145 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
146 else if (poly.color == EdgeColor)
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
147 {
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
148 qcol = luma(QColor (m_config->backgroundColor())) > 40 ? Qt::black : Qt::white;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
149 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
150 else
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
151 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
152 LDColor col = poly.color;
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
153
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
154 if (col.isValid())
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
155 qcol = col.faceColor();
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
156 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
157 break;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
158 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159
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 if (qcol.isValid())
5f3139c802bf Cleaned up GLCompiler. Among other changes, the compiler no longer has to be told what to compile.
Teemu Piippo <teemu@hecknology.net>
parents: 1098
diff changeset
161 {
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
162 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
163
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
164 if (topobj->isSelected())
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
165 blendAlpha = 1.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
166 else if (topobj == m_renderer->objectAtCursor())
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
167 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
168
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
169 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
170 {
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 QColor selectedColor = m_config->selectColorBlend();
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
172 double denom = blendAlpha + 1.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
173 qcol.setRed((qcol.red() + (selectedColor.red() * blendAlpha)) / denom);
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 qcol.setGreen((qcol.green() + (selectedColor.green() * blendAlpha)) / denom);
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
175 qcol.setBlue((qcol.blue() + (selectedColor.blue() * blendAlpha)) / denom);
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 }
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
177 }
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 else
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 {
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 716
diff changeset
180 // The color was unknown. Use main color to make the polygon at least
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181 // not appear pitch-black.
890
903ec1e46298 - backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 889
diff changeset
182 if (poly.num != 2 and poly.num != 5)
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
183 qcol = guiUtilities()->mainColorRepresentation();
890
903ec1e46298 - backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 889
diff changeset
184 else
903ec1e46298 - backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 889
diff changeset
185 qcol = Qt::black;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
186
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
187 // 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
188 static QSet<int> warnedColors;
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 if (not warnedColors.contains(poly.color))
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
190 {
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
191 print("Unknown color %1!\n", poly.color);
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
192 warnedColors.insert(poly.color);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
193 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
194 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
196 return qcol;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
199
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
200 void GLCompiler::needMerge()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 {
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
202 for (int i = 0; i < countof (m_vboChanged); ++i)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 m_vboChanged[i] = true;
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
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
206
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
207 void GLCompiler::stageForCompilation (LDObject* obj)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
208 {
943
af81220741d9 Commit work done on code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 920
diff changeset
209 m_staged << obj;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
211
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
212
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
213 void GLCompiler::unstage (LDObject* obj)
721
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
214 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
215 m_staged.remove (obj);
721
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
216 }
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
217
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
218
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
219 void GLCompiler::compileStaged()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
220 {
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
221 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
222 compileObject(object);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
223
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
224 m_staged.clear();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
227
1121
be0b5ad128ea Replaced uses of currentDocument() in GLRenderer with m_model
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
228 void GLCompiler::prepareVBO (int vbonum, const Model* model)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
229 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
230 // Compile anything that still awaits it
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 compileStaged();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232
716
639a900999bc - removed the debug code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 715
diff changeset
233 if (not m_vboChanged[vbonum])
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 return;
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 QVector<GLfloat> vbodata;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
237
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
238 for (auto it = m_objectInfo.begin(); it != m_objectInfo.end();)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
239 {
984
a7b6f987d269 null -> nullptr
Teemu Piippo <crimsondusk64@gmail.com>
parents: 979
diff changeset
240 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
241 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 772
diff changeset
242 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
243 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
244 }
886
3c83fe3486b1 - fixed endless loop in prepareVBO due to badly incremented iterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 883
diff changeset
245
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
246 if (it.key()->model() == model and not it.key()->isHidden())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 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
248
3c83fe3486b1 - fixed endless loop in prepareVBO due to badly incremented iterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 883
diff changeset
249 ++it;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
251
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252 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
253 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
254 glBindBuffer (GL_ARRAY_BUFFER, 0);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
255 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
256 m_vboChanged[vbonum] = false;
1065
c8ecddbd99e9 Actually, let's call it countof(). Makes more sense.
Teemu Piippo <teemu@hecknology.net>
parents: 1063
diff changeset
257 m_vboSizes[vbonum] = countof(vbodata);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
258 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
259
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
260
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
261 void GLCompiler::dropObjectInfo(LDObject* object)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
262 {
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
263 if (m_objectInfo.contains(object))
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
264 {
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
265 m_objectInfo.remove(object);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266 needMerge();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
267 }
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
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
270 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
271 {
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
272 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
273 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
274 }
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
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
276
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
277 void GLCompiler::compileObject (LDObject* obj)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 {
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
279 if (obj == nullptr)
708
3155f2c05f89 - more debugging...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
280 return;
3155f2c05f89 - more debugging...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
281
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
282 ObjectVBOInfo info;
713
46377d340c23 - more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents: 708
diff changeset
283 info.isChanged = true;
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
284 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
285
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
286 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
287 {
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
288 // 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
289 // 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
290 case LDObjectType::Triangle:
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
291 case LDObjectType::Quad:
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
292 case LDObjectType::Line:
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
293 case LDObjectType::CondLine:
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
294 {
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 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
296 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
297 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
298 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
299 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
300 }
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
301
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
302 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
303 {
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
304 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
305 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
306
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 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
308 {
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 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
310 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
311 }
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
312 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
313 }
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
314
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
315 case LDObjectType::BezierCurve:
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
316 {
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
317 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
318 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
319 {
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1017
diff changeset
320 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
321 compilePolygon (polygon, obj, &info);
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
322 }
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
323 }
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
324 break;
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
325
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
326 default:
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
327 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
328 }
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
329
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
330 m_objectInfo[obj] = info;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
331 needMerge();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
332 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
333
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
334
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
335 void GLCompiler::compilePolygon (LDPolygon& poly, LDObject* topobj, ObjectVBOInfo* objinfo)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
336 {
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
337 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
338 int vertexCount;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
339
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
340 switch (poly.num)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
341 {
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
342 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
343 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
344 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
345 case 5: surface = VboClass::ConditionalLines; vertexCount = 2; break;
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
346 default: return;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
347 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348
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
349 // 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
350 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
351 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
352
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
353 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
354 {
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
355 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
356 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
357 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
358 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
359 }
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
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
361 for (VboSubclass complement : iterateEnum<VboSubclass>())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362 {
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
363 const int vbonum = vboNumber (surface, complement);
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
364 QVector<GLfloat>& vbodata = objinfo->data[vbonum];
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
365 const QColor color = getColorForPolygon (poly, topobj, complement);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
366
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
367 for (int vert = 0; vert < vertexCount; ++vert)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
368 {
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
369 if (complement == VboSubclass::Surfaces)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
370 {
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 // 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
372 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
373 << -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
374 << -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
375 }
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1122
diff changeset
376 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
377 {
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
378 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
379 << -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
380 << -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
381 }
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
382 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
383 {
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 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
385 << ((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
386 << ((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
387 << ((GLfloat) color.alpha()) / 255.0f;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
388 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
389 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
390 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
391 }
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
392
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
393
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
394 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
395 {
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
396 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
397 }
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
398
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
399
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
400 int GLCompiler::vboNumber (VboClass surface, VboSubclass complement)
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
401 {
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
402 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
403 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
404
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
405
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
406 GLuint GLCompiler::vbo (int vbonum) const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
407 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
408 return m_vbo[vbonum];
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
409 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
410
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
411
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
412 int GLCompiler::vboSize (int vbonum) const
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 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
415 }
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
416
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
417
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
418 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
419 {
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
420 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
421 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
422 }

mercurial