src/glShared.h

Sun, 10 Jun 2018 21:48:58 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sun, 10 Jun 2018 21:48:58 +0300
changeset 1400
ae83213bdd63
parent 1371
b8df4748d04e
child 1404
16eb4257e662
permissions
-rw-r--r--

refactored LDPolygon

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
1326
69a90bd2dba2 Happy new year 2018
Teemu Piippo <teemu@hecknology.net>
parents: 1315
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
740
dbf9f1294d94 - apply #pragma once to glShared.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 739
diff changeset
19 #pragma once
1049
71946fed475a Removed the USE_QT5 macro now that we're Qt5 only.
Teemu Piippo <teemu@hecknology.net>
parents: 1036
diff changeset
20 #include <QOpenGLFunctions>
1151
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
21 #include <QGenericMatrix>
1023
9450ac3cd930 Split grid stuff into a new class Grid in grid.cpp/grid.h
Teemu Piippo <crimsondusk64@gmail.com>
parents: 1014
diff changeset
22 #include "basics.h"
1400
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
23 #include "colors.h"
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
24 #include "generics/enums.h"
1315
23d48a709ffc moved Vertex and BoundingBox into new code units
Teemu Piippo <teemu@hecknology.net>
parents: 1313
diff changeset
25 #include "types/vertex.h"
856
6bdc03091441 - and fixed compilation on linux systems too
Teemu Piippo <crimsondusk64@gmail.com>
parents: 855
diff changeset
26
1151
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
27 inline void glMultMatrixf(const GLRotationMatrix& matrix)
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
28 {
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
29 glMultMatrixf(matrix.constData());
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
30 }
0eddb5bcf25b Made fixed cameras matrix-based. This simplifies some math.
Teemu Piippo <teemu@hecknology.net>
parents: 1123
diff changeset
31
1371
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
32 inline void glTranslatef(const Vertex& vertex)
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
33 {
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
34 glTranslatef(vertex.x, vertex.y, vertex.z);
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
35 }
b8df4748d04e automatically center the model in the renderer
Teemu Piippo <teemu@hecknology.net>
parents: 1326
diff changeset
36
1178
3a88e7a60b63 At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents: 1177
diff changeset
37 inline void glVertex(const Vertex& vertex)
3a88e7a60b63 At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents: 1177
diff changeset
38 {
1313
4baed9f54de3 reworked Vertex, no longer a QVector3D subclass
Teemu Piippo <teemu@hecknology.net>
parents: 1305
diff changeset
39 glVertex3f(vertex.x, vertex.y, vertex.z);
1178
3a88e7a60b63 At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents: 1177
diff changeset
40 }
3a88e7a60b63 At long last, the grid is finally now rendered onto the viewport. Woop!
Teemu Piippo <teemu@hecknology.net>
parents: 1177
diff changeset
41
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
42 class LDObject;
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
43
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
44 struct LDPolygon
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
45 {
1400
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
46 enum class Type : qint8 { InvalidPolygon, EdgeLine, Triangle, Quadrilateral, ConditionalEdge };
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
47 Type type = Type::InvalidPolygon;
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
48 Vertex vertices[4];
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
49 LDColor color;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
50
1305
31627acdd4b5 Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents: 1278
diff changeset
51 inline int numPolygonVertices() const
31627acdd4b5 Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents: 1278
diff changeset
52 {
1400
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
53 if (type == Type::ConditionalEdge)
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
54 return 2;
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
55 else
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
56 return numVertices();
1305
31627acdd4b5 Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents: 1278
diff changeset
57 }
31627acdd4b5 Bfc red/green view almost completely fixed
Teemu Piippo <teemu@hecknology.net>
parents: 1278
diff changeset
58
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59 inline int numVertices() const
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
60 {
1400
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
61 switch (type)
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
62 {
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
63 case Type::EdgeLine:
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
64 return 2;
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
65
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
66 case Type::Triangle:
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
67 return 3;
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
68
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
69 case Type::ConditionalEdge:
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
70 case Type::Quadrilateral:
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
71 return 4;
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
72
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
73 case Type::InvalidPolygon:
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
74 return 0;
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
75 }
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
76
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
77 return 0;
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
78 }
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
79
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
80 bool isValid() const
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
81 {
ae83213bdd63 refactored LDPolygon
Teemu Piippo <teemu@hecknology.net>
parents: 1371
diff changeset
82 return type != Type::InvalidPolygon;
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 }
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
84 };
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85
1245
338d66111168 more work on mvc
Santeri Piippo
parents: 1237
diff changeset
86 Q_DECLARE_METATYPE(LDPolygon)
338d66111168 more work on mvc
Santeri Piippo
parents: 1237
diff changeset
87
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
88 enum class VboClass
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
89 {
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
90 Lines,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
91 Triangles,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
92 Quads,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
93 ConditionalLines,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
94 _End
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
95 };
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
96
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
97 MAKE_ITERABLE_ENUM(VboClass)
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
98
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
99 enum class VboSubclass
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
100 {
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
101 Surfaces,
1173
6cd85b28f43b Cleanup ColorSelector::colorButtonClicked()
Teemu Piippo <teemu@hecknology.net>
parents: 1151
diff changeset
102 RegularColors,
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
103 PickColors,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
104 BfcFrontColors,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
105 BfcBackColors,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
106 RandomColors,
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
107 Normals,
1237
40bb00d82e2b moved matrix calculations, added inverted normals for BFC back sides
Santeri Piippo
parents: 1178
diff changeset
108 InvertedNormals,
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
109 _End
706
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
110 };
d79083b9f74d Merge ../ldforge into gl
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
111
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
112 MAKE_ITERABLE_ENUM(VboSubclass)
1033
32153a1dbb15 - Refactoring...
Teemu Piippo <teemu@compsta2.com>
parents: 1023
diff changeset
113
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
114 enum
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
115 {
1123
15e46ea3151f Reworked iterable enums: they all are enum classes now and the end value is marked with "_End"
Teemu Piippo <teemu@hecknology.net>
parents: 1119
diff changeset
116 NumVbos = EnumLimits<VboClass>::Count * EnumLimits<VboSubclass>::Count
986
525921eae58c Refactor GLRenderer and GLCompiler
Teemu Piippo <crimsondusk64@gmail.com>
parents: 968
diff changeset
117 };

mercurial