src/glCompiler.cpp

Thu, 11 Jan 2018 15:09:44 +0200

author
Santeri Piippo
date
Thu, 11 Jan 2018 15:09:44 +0200
changeset 1231
ce0c9f2e6b9c
parent 1224
5a31b6d4bf81
child 1232
7eb8b59577d0
permissions
-rw-r--r--

begin rendering rework

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
1222
34def2630300 happy new year 2018
Santeri Piippo
parents: 1217
diff changeset
3 * Copyright (C) 2013 - 2018 Teemu Piippo
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
4 *
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
9 *
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
14 *
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
19 #define GL_GLEXT_PROTOTYPES
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
20 #include <GL/glu.h>
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21 #include <GL/glext.h>
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"
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
28 #include "guiutilities.h"
1012
413ecd6b9801 It worx again!
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1011
diff changeset
29 #include "documentmanager.h"
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
31 static const QColor bfcFrontColor {64, 192, 80};
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
32 static const QColor bfcBackColor {208, 64, 64};
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
33
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
34 struct GLErrorInfo
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 GLenum value;
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
37 QString text;
706
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
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
40 static const GLErrorInfo g_GLErrors[] =
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 { GL_NO_ERROR, "No error" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43 { GL_INVALID_ENUM, "Unacceptable enumerator passed" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 { GL_INVALID_VALUE, "Numeric argument out of range" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 { 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
46 { GL_INVALID_FRAMEBUFFER_OPERATION, "Framebuffer object is not complete"},
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
47 { GL_OUT_OF_MEMORY, "Out of memory" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
48 { GL_STACK_UNDERFLOW, "The operation would have caused an underflow" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
49 { GL_STACK_OVERFLOW, "The operation would have caused an overflow" },
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50 };
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
52 ConfigOption(QString SelectColorBlend = "#0080FF")
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 716
diff changeset
53
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
54 void CheckGLErrorImpl(const char* file, int line)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55 {
789
4b7306f52bb5 - String -> QString
Santeri Piippo <crimsondusk64@gmail.com>
parents: 786
diff changeset
56 QString errmsg;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
57 GLenum errnum = glGetError();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 if (errnum == GL_NO_ERROR)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 return;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
61
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
62 for (const GLErrorInfo& err : g_GLErrors)
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 if (err.value == errnum)
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
65 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
66 errmsg = err.text;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
67 break;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
68 }
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
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
71 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
72 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
73
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
74
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
75 GLCompiler::GLCompiler(LDDocument* document, GLRenderer* renderer) :
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
76 document {document},
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
77 renderer {renderer} {}
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
78
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
79
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 void GLCompiler::initialize()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 {
855
e16f1587ef44 - fixed compilation on windows systems
Santeri Piippo <crimsondusk64@gmail.com>
parents: 852
diff changeset
82 initializeOpenGLFunctions();
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
83 glGenBuffers(NumVbos, &vboIndices[0]);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
84 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
86
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
87
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 GLCompiler::~GLCompiler()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
90 glDeleteBuffers(NumVbos, &vboIndices[0]);
861
83426c5fa732 - major identifier renaming
Teemu Piippo <crimsondusk64@gmail.com>
parents: 857
diff changeset
91 CHECK_GL_ERROR();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
92 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
93
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
94 /*
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
95 * Returns a color that represents this object index. There are 256³ possible
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
96 * colors, so that many indices can be bijectively addressed with colorss.
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
97 */
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
98 QColor GLCompiler::indexColorForID(int id) const
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
99 {
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
100 int red = (id / 0x10000) % 0x100;
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
101 int green = (id / 0x100) % 0x100;
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
102 int blue = id % 0x100;
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
103
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
104 return {red, green, blue};
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
105 }
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
106
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
107
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
108 QColor blend(QColor baseColor, QColor blendColor, double intensity)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
109 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
110 double red = baseColor.redF();
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
111 red += blendColor.redF() * intensity;
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
112 red /= (intensity + 1.0);
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
113 double green = baseColor.greenF();
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
114 green += blendColor.greenF() * intensity;
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
115 green /= (intensity + 1.0);
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
116 double blue = baseColor.blueF();
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
117 blue += blendColor.blueF() * intensity;
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
118 blue /= (intensity + 1.0);
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
119 return {int(round(red)), int(round(green)), int(round(blue))};
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
120 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
121
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
122
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
123 QColor GLCompiler::getColorForPolygon(LDPolygon& poly, LDObject* topobj, ComplementVboType complement) const
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
124 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
125 QColor color;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
126
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
127 switch(complement)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
128 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
129 case SurfacesVboComplement:
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
130 case NumVboComplements:
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
131 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
132
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
133 case BfcFrontColorsVboComplement:
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
134 color = bfcFrontColor;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
135 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
136
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
137 case BfcBackColorsVboComplement:
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
138 color = bfcBackColor;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
139 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
140
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
141 case PickColorsVboComplement:
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
142 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
143
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
144 case RandomColorsVboComplement:
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
145 color = topobj->randomColor();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
146 break;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
147
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
148 case NormalColorsVboComplement:
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
149 if (poly.color == MainColor)
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 if (topobj->color() == MainColor)
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
152 color = 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
153 else
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
154 color = topobj->color().faceColor();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
155 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
156 else if (poly.color == EdgeColor)
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
157 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
158 if (luma(config->backgroundColor()) > 40)
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
159 color = Qt::black;
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
160 else
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
161 color = Qt::white;
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
162 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
163 else
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
164 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
165 LDColor colorInfo = 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
166
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
167 if (colorInfo.isValid())
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
168 color = colorInfo.faceColor();
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
169 }
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
170 break;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
171 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
172
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
173 if (not color.isValid())
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
174 {
717
fdc285e5952f - reimplemented vertex snapping
Santeri Piippo <crimsondusk64@gmail.com>
parents: 716
diff changeset
175 // 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
176 // not appear pitch-black.
890
903ec1e46298 - backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 889
diff changeset
177 if (poly.num != 2 and poly.num != 5)
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
178 color = mainColorRepresentation();
890
903ec1e46298 - backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 889
diff changeset
179 else
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
180 color = Qt::black;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
181
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
182 // Warn about the unknown color, but only once.
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
183 static QSet<int> warnedColors;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
184 if (not warnedColors.contains(poly.color))
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
185 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
186 print("Unknown color %1!\n", poly.color);
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
187 warnedColors.insert(poly.color);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
188 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
189
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
190 return color;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
191 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
192
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
193 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
194
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
195 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
196 blendAlpha = 1.0;
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
197 else if (topobj == 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
198 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
199
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
200 color = blend(color, config->selectColorBlend(), blendAlpha);
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
201 return color;
706
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
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
204
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
205 void GLCompiler::needMerge()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
206 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
207 for (bool& changed_flag : this->vboChanged)
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
208 changed_flag = true;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
209 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
210
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
211
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
212 void GLCompiler::stageForCompilation(LDObject* obj)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
213 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
214 stagedObjects << obj;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
215 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
216
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
217
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
218 void GLCompiler::unstage(LDObject* obj)
721
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
219 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
220 stagedObjects.remove(obj);
721
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
221 }
4cf0f6c9082d - now works with selection subfiling
Santeri Piippo <crimsondusk64@gmail.com>
parents: 717
diff changeset
222
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
223
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
224 void GLCompiler::compileDocument(LDDocument* document)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
225 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
226 if (document)
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
227 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
228 for (LDObject* obj : document->objects())
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
229 compileObject(obj);
946
9cbd658b63f9 Cleanup progresses
Teemu Piippo <crimsondusk64@gmail.com>
parents: 945
diff changeset
230 }
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
231 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
232
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
233
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
234 void GLCompiler::compileStaged()
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
235 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
236 for (QSetIterator<LDObject*> it(stagedObjects); it.hasNext();)
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
237 compileObject(it.next());
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
238
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
239 stagedObjects.clear();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
240 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
241
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
242
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
243 void GLCompiler::prepareVBO(int vbonum)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
244 {
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
245 // Compile anything that still awaits it
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
246 compileStaged();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
247
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
248 if (not vboChanged[vbonum])
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
249 {
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
250 print("Merging %1", vbonum);
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
251 QVector<GLfloat> vbodata;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
252
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
253 for (auto it = objectInfo.begin(); it != objectInfo.end();)
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 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
255 if (it.key() == nullptr)
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
256 {
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
257 it = objectInfo.erase(it);
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
258 }
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
259 else
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
260 {
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
261 if (not it.key()->isHidden())
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
262 vbodata += it->data[vbonum];
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
263
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
264 ++it;
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
265 }
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
266 }
886
3c83fe3486b1 - fixed endless loop in prepareVBO due to badly incremented iterator
Teemu Piippo <crimsondusk64@gmail.com>
parents: 883
diff changeset
267
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
268 glBindBuffer(GL_ARRAY_BUFFER, vboIndices[vbonum]);
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
269 glBufferData(
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
270 GL_ARRAY_BUFFER,
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
271 vbodata.size() * sizeof(GLfloat),
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
272 vbodata.constData(),
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
273 GL_STATIC_DRAW);
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
274 glBindBuffer(GL_ARRAY_BUFFER, 0);
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
275 CHECK_GL_ERROR();
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
276 vboChanged[vbonum] = false;
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
277 vboSizes[vbonum] = vbodata.size();
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
278 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
279 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
280
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
281
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
282 void GLCompiler::dropObjectInfo(LDObject* obj)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
283 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
284 if (objectInfo.contains(obj))
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
285 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
286 objectInfo.remove(obj);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
287 needMerge();
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
288 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
289 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
290
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
291
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
292 void GLCompiler::compileObject(LDObject* obj)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
293 {
984
a7b6f987d269 null -> nullptr
Teemu Piippo <crimsondusk64@gmail.com>
parents: 979
diff changeset
294 if (obj == nullptr or obj->document() == nullptr or obj->document()->isCache())
708
3155f2c05f89 - more debugging...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
295 return;
3155f2c05f89 - more debugging...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 706
diff changeset
296
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
297 ObjectVBOInfo info;
713
46377d340c23 - more debug stuff....
Santeri Piippo <crimsondusk64@gmail.com>
parents: 708
diff changeset
298 info.isChanged = true;
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
299 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
300
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
301 switch(obj->type())
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
302 {
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
303 // 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
304 // Quads must go into separate vbos.
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
305 case OBJ_Triangle:
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
306 case OBJ_Quad:
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
307 case OBJ_Line:
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
308 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
309 {
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 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
311 poly->id = obj->id();
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
312 compilePolygon(*poly, obj, &info);
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
313 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
314 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
315 }
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
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
317 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
318 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
319 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
320 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
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 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
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 poly.id = obj->id();
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
325 compilePolygon(poly, obj, &info);
726
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
326 }
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
327 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
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
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
330 case OBJ_BezierCurve:
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
331 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
332 LDBezierCurve* curve = static_cast<LDBezierCurve*>(obj);
1006
a6b462051ae0 Copyright header fix, some minor stuff
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1005
diff changeset
333 for (LDPolygon& poly : curve->rasterizePolygons())
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
334 {
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
335 poly.id = obj->id();
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
336 compilePolygon(poly, obj, &info);
1004
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
337 }
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
338 }
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
339 break;
ba4200437179 Bézier curves now render in 3D
Teemu Piippo <crimsondusk64@gmail.com>
parents: 998
diff changeset
340
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
341 default:
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
342 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
343 }
9a53d9a379de - refactored the gl compiler a tad, made selection blend work with BFC/random colors
Santeri Piippo <crimsondusk64@gmail.com>
parents: 725
diff changeset
344
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
345 objectInfo[obj] = info;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
346 needMerge();
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
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
349
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
350 void GLCompiler::compilePolygon(LDPolygon& poly, LDObject* topobj, ObjectVBOInfo* objinfo)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
351 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
352 SurfaceVboType surface;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
353 int numverts;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
354
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
355 switch(poly.num)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
356 {
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
357 case 2: surface = LinesVbo; numverts = 2; break;
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
358 case 3: surface = TrianglesVbo; numverts = 3; break;
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
359 case 4: surface = QuadsVbo; numverts = 4; break;
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
360 case 5: surface = ConditionalLinesVbo; numverts = 2; break;
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
361 default: return;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
362 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
363
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
364 for (ComplementVboType complement = FirstVboComplement; complement < NumVboComplements; ++complement)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
365 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
366 const int vbonum = vboNumber(surface, complement);
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
367 QVector<GLfloat>& vbodata = objinfo->data[vbonum];
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
368 const QColor color = getColorForPolygon(poly, topobj, complement);
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
369
890
903ec1e46298 - backed out work done on bfc (re-committing later)
Teemu Piippo <crimsondusk64@gmail.com>
parents: 889
diff changeset
370 for (int vert = 0; vert < numverts; ++vert)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
371 {
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
372 if (complement == SurfacesVboComplement)
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
373 {
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
374 // 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
375 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
376 << -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
377 << -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
378 }
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 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
380 {
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
381 vbodata <<((GLfloat) color.red()) / 255.0f
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
382 <<((GLfloat) color.green()) / 255.0f
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
383 <<((GLfloat) color.blue()) / 255.0f
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
384 <<((GLfloat) color.alpha()) / 255.0f;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
385 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
386 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
387 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
388 }
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
389
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
390 int GLCompiler::vboNumber(SurfaceVboType surface, ComplementVboType complement)
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
391 {
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
392 return (surface * NumVboComplements) + 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
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
395
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
396 GLuint GLCompiler::vbo(int vbonum) const
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
397 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
398 return vboIndices[vbonum];
986
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
1011
4fdd74a04790 Rename LDSubfile to LDSubfileReference
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1006
diff changeset
401
1217
314e12e23c3a fix paren style
Santeri Piippo
parents: 1215
diff changeset
402 int GLCompiler::vboSize(int vbonum) const
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 985
diff changeset
403 {
1231
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
404 return vboSizes[vbonum];
ce0c9f2e6b9c begin rendering rework
Santeri Piippo
parents: 1224
diff changeset
405 }

mercurial