src/glCompiler.cpp

Tue, 16 Feb 2016 19:59:43 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Tue, 16 Feb 2016 19:59:43 +0200
changeset 1023
9450ac3cd930
parent 1017
fc1c13db9618
child 1035
8a60250175ba
permissions
-rw-r--r--

Split grid stuff into a new class Grid in grid.cpp/grid.h

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
1014
f0a8ecb6a357 Happy new year 2016!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1012
diff changeset
3 * Copyright (C) 2013 - 2016 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 "ldObject.h"
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
24 #include "colors.h"
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
25 #include "ldDocument.h"
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26 #include "miscallenous.h"
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #include "glRenderer.h"
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28 #include "dialogs.h"
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
29 #include "guiutilities.h"
1012
413ecd6b9801 It worx again!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
30 #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
31 #include "grid.h"
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 struct GLErrorInfo
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35 GLenum value;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
36 QString text;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
37 };
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
38
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 static const GLErrorInfo g_GLErrors[] =
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 { GL_NO_ERROR, "No error" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 { GL_INVALID_ENUM, "Unacceptable enumerator passed" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 { GL_INVALID_VALUE, "Numeric argument out of range" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 { 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
45 { GL_INVALID_FRAMEBUFFER_OPERATION, "Framebuffer object is not complete"},
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 { GL_OUT_OF_MEMORY, "Out of memory" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 { GL_STACK_UNDERFLOW, "The operation would have caused an underflow" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 { GL_STACK_OVERFLOW, "The operation would have caused an overflow" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 };
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
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
51 ConfigOption (QString SelectColorBlend = "#0080FF")
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 716
diff changeset
52
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
53 // static QMap<LDObject*, String> g_objectOrigins;
721
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
54
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
55 void CheckGLErrorImpl (const char* file, int line)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
56 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
57 QString errmsg;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 GLenum errnum = glGetError();
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 if (errnum == GL_NO_ERROR)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61 return;
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 for (const GLErrorInfo& err : g_GLErrors)
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 if (err.value == errnum)
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 errmsg = err.text;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 break;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
69 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
70 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
71
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
72 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
73 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
75
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
76 GLCompiler::GLCompiler (GLRenderer* renderer) :
971
c00f9665a9f8 Now compiles and links but crashes shortly after startup.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 970
diff changeset
77 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
78 m_renderer (renderer)
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 needMerge();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 memset (m_vboSizes, 0, sizeof m_vboSizes);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
84
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 void GLCompiler::initialize()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86 {
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
87 initializeOpenGLFunctions();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
88 glGenBuffers (NumVbos, &m_vbo[0]);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
89 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
90 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
91
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
92
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93 GLCompiler::~GLCompiler()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
94 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
95 glDeleteBuffers (NumVbos, &m_vbo[0]);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
96 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
97 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
98
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
99
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 QColor GLCompiler::indexColorForID (int id) const
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
101 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
102 // Calculate a color based from this index. This method caters for
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
103 // 16777216 objects. I don't think that will be exceeded anytime soon. :)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
104 int r = (id / 0x10000) % 0x100,
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
105 g = (id / 0x100) % 0x100,
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
106 b = id % 0x100;
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 return QColor (r, g, b);
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
111
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
112 QColor GLCompiler::getColorForPolygon (LDPolygon& poly, LDObject* topobj, ComplementVboType complement) const
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
113 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
114 QColor qcol;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
115 static const QColor bfcFrontColor (64, 192, 80);
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
116 static const QColor bfcBackColor (208, 64, 64);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
117
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
118 switch (complement)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
119 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
120 case SurfacesVboComplement:
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
121 case NumVboComplements:
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
122 return QColor();
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
123
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
124 case BfcFrontColorsVboComplement:
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
125 qcol = bfcFrontColor;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
126 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
127
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
128 case BfcBackColorsVboComplement:
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
129 qcol = bfcBackColor;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
130 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
131
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
132 case PickColorsVboComplement:
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
133 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
134
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
135 case RandomColorsVboComplement:
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
136 qcol = topobj->randomColor();
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
137 break;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
138
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
139 case NormalColorsVboComplement:
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
140 if (poly.color == MainColor)
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
141 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
142 if (topobj->color() == MainColor)
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
143 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
144 else
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
145 qcol = topobj->color().faceColor();
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
146 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
147 else if (poly.color == EdgeColor)
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
148 {
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
149 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
150 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
151 else
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
152 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
153 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
154
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
155 if (col.isValid())
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
156 qcol = col.faceColor();
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
157 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
158 break;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
159 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
160
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 716
diff changeset
161 if (not qcol.isValid())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
162 {
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 716
diff changeset
163 // 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
164 // not appear pitch-black.
890
903ec1e46298 - backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 889
diff changeset
165 if (poly.num != 2 and poly.num != 5)
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
166 qcol = guiUtilities()->mainColorRepresentation();
890
903ec1e46298 - backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 889
diff changeset
167 else
903ec1e46298 - backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 889
diff changeset
168 qcol = Qt::black;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
169
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
170 // Warn about the unknown color, but only once.
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
171 static QList<int> warnedColors;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
172 if (not warnedColors.contains (poly.color))
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
173 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 print ("Unknown color %1!\n", poly.color);
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
175 warnedColors << poly.color;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
176 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
177
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
178 return qcol;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
179 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
180
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
181 double blendAlpha = 0.0;
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
182
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
183 if (topobj->isSelected())
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
184 blendAlpha = 1.0;
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
185 else if (topobj == m_renderer->objectAtCursor())
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
186 blendAlpha = 0.5;
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
187
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
188 if (blendAlpha != 0.0)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189 {
1017
fc1c13db9618 Renamed ConfigurationValueBag to Configuration and added a pointer to it into HierarchyElement. This helps with the fight against global variables.
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
190 QColor selcolor (m_config->selectColorBlend());
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
191 double denom = blendAlpha + 1.0;
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
192 qcol.setRed ((qcol.red() + (selcolor.red() * blendAlpha)) / denom);
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
193 qcol.setGreen ((qcol.green() + (selcolor.green() * blendAlpha)) / denom);
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
194 qcol.setBlue ((qcol.blue() + (selcolor.blue() * blendAlpha)) / denom);
706
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
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
197 return qcol;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
198 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
199
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
200
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
201 void GLCompiler::needMerge()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
202 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
203 for (int i = 0; i < countof (m_vboChanged); ++i)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
204 m_vboChanged[i] = true;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
207
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
208 void GLCompiler::stageForCompilation (LDObject* obj)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209 {
721
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
210 /*
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
211 g_objectOrigins[obj] = format ("%1:%2 (%3)",
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
212 obj->document()->getDisplayName(), obj->lineNumber(), obj->typeName());
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
213 */
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
214
943
af81220741d9 Commit work done on code cleanup
Teemu Piippo <crimsondusk64@gmail.com>
parents: 920
diff changeset
215 m_staged << obj;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
217
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
218
944
1a6f1997fcbe Replace casts
Teemu Piippo <crimsondusk64@gmail.com>
parents: 943
diff changeset
219 void GLCompiler::unstage (LDObject* obj)
721
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
220 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
221 m_staged.remove (obj);
721
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
222 }
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
223
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
224
945
c310073e4f22 More sharedpointer removal
Teemu Piippo <crimsondusk64@gmail.com>
parents: 944
diff changeset
225 void GLCompiler::compileDocument (LDDocument* doc)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
226 {
985
ed7b31b9f904 Remove "!= nullptr" expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents: 984
diff changeset
227 if (doc)
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
228 {
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
229 for (LDObject* obj : doc->objects())
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
230 compileObject (obj);
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
231 }
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
233
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
234
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 void GLCompiler::compileStaged()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
236 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
237 for (QSetIterator<LDObject*> it (m_staged); it.hasNext();)
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
238 compileObject (it.next());
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 m_staged.clear();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
242
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
243
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 void GLCompiler::prepareVBO (int vbonum)
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 // Compile anything that still awaits it
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247 compileStaged();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
248
716
639a900999bc - removed the debug code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 715
diff changeset
249 if (not m_vboChanged[vbonum])
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
250 return;
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 QVector<GLfloat> vbodata;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
253
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 for (auto it = m_objectInfo.begin(); it != m_objectInfo.end();)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
255 {
984
a7b6f987d269 null -> nullptr
Teemu Piippo <crimsondusk64@gmail.com>
parents: 979
diff changeset
256 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
257 {
784
f82ab4d3c7b4 - made LDDocument use shared pointers, this eliminates a lot of document-related crashes
Santeri Piippo <crimsondusk64@gmail.com>
parents: 772
diff changeset
258 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
259 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
260 }
886
3c83fe3486b1 - fixed endless loop in prepareVBO due to badly incremented iterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 883
diff changeset
261
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
262 if (it.key()->document() == currentDocument() and not it.key()->isHidden())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
263 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
264
3c83fe3486b1 - fixed endless loop in prepareVBO due to badly incremented iterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 883
diff changeset
265 ++it;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
266 }
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 glBindBuffer (GL_ARRAY_BUFFER, m_vbo[vbonum]);
708
3155f2c05f89 - more debugging...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
269 glBufferData (GL_ARRAY_BUFFER, vbodata.size() * sizeof(GLfloat), vbodata.constData(), GL_STATIC_DRAW);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
270 glBindBuffer (GL_ARRAY_BUFFER, 0);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
271 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
272 m_vboChanged[vbonum] = false;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
273 m_vboSizes[vbonum] = vbodata.size();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
274 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
275
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
276
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
277 void GLCompiler::dropObjectInfo (LDObject* obj)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
279 if (m_objectInfo.contains (obj))
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280 {
978
4603d8fd063e Make documents members of the main window
Teemu Piippo <crimsondusk64@gmail.com>
parents: 971
diff changeset
281 m_objectInfo.remove (obj);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
282 needMerge();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
284 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
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 {
984
a7b6f987d269 null -> nullptr
Teemu Piippo <crimsondusk64@gmail.com>
parents: 979
diff changeset
289 if (obj == nullptr or obj->document() == nullptr or obj->document()->isCache())
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.
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
300 case OBJ_Triangle:
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
301 case OBJ_Quad:
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
302 case OBJ_Line:
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
303 case OBJ_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
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
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
312 case OBJ_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
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
325 case OBJ_BezierCurve:
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 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
347 SurfaceVboType surface;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
348 int numverts;
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 {
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
352 case 2: surface = LinesVbo; numverts = 2; break;
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
353 case 3: surface = TrianglesVbo; numverts = 3; break;
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
354 case 4: surface = QuadsVbo; numverts = 4; break;
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
355 case 5: surface = ConditionalLinesVbo; numverts = 2; break;
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
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
359 for (ComplementVboType complement = FirstVboComplement; complement < NumVboComplements; ++complement)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
360 {
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
361 const int vbonum = vboNumber (surface, complement);
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
362 QVector<GLfloat>& vbodata = objinfo->data[vbonum];
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
363 const QColor color = getColorForPolygon (poly, topobj, complement);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
364
890
903ec1e46298 - backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 889
diff changeset
365 for (int vert = 0; vert < numverts; ++vert)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
366 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
367 if (complement == SurfacesVboComplement)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
368 {
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
369 // 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
370 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
371 << -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
372 << -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
373 }
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
374 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
375 {
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
376 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
377 << ((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
378 << ((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
379 << ((GLfloat) color.alpha()) / 255.0f;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
380 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
381 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
382 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
383 }
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
384
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
385
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
386 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
387 {
e62983881460 - fixed crash-on-exit (simply by not running full destruction processing during program termination)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
388 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
389 }
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
390
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
391
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
392 int GLCompiler::vboNumber (SurfaceVboType surface, ComplementVboType complement)
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
393 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
394 return (surface * NumVboComplements) + complement;
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
395 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
396
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
397
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
398 GLuint GLCompiler::vbo (int vbonum) const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
399 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
400 return m_vbo[vbonum];
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
401 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
402
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
403
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
404 int GLCompiler::vboSize (int vbonum) const
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
405 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
406 return m_vboSizes[vbonum];
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
407 }

mercurial