Fri, 07 Feb 2020 01:58:34 +0200
added selection highlighting
19 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013 - 2018 Teemu Piippo | |
4 | * | |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
19 | #pragma once | |
20 | #include <QColor> | |
21 | #include <QOpenGLFunctions> | |
22 | #include <QGenericMatrix> | |
23 | #include "basics.h" | |
24 | #include "colors.h" | |
25 | ||
26 | namespace gl | |
27 | { | |
28 | // Transformation matrices for projection cameras. | |
29 | static const QMatrix4x4 topCameraMatrix = {}; | |
30 | static const QMatrix4x4 frontCameraMatrix = {1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1}; | |
31 | static const QMatrix4x4 leftCameraMatrix = {0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 1}; | |
32 | static const QMatrix4x4 bottomCameraMatrix = {1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1}; | |
33 | static const QMatrix4x4 backCameraMatrix = {-1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1}; | |
34 | static const QMatrix4x4 rightCameraMatrix = {0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1}; | |
35 | static constexpr QRgb BlackRgb = 0xff000000; | |
36 | struct Polygon; | |
37 | } | |
38 | ||
39 | struct gl::Polygon | |
40 | { | |
41 | enum Type : qint8 | |
42 | { | |
43 | EdgeLine, | |
44 | Triangle, | |
45 | Quadrilateral, | |
46 | ConditionalEdge | |
47 | }; | |
48 | Type type; | |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
49 | glm::vec3 vertices[4]; |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
50 | ldraw::Color color; |
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
51 | ldraw::Id id; |
19 | 52 | |
53 | /** | |
54 | * @return amount of vertices used for geometry | |
55 | */ | |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
56 | inline unsigned int numPolygonVertices() const |
19 | 57 | { |
58 | if (type == Type::ConditionalEdge) | |
59 | return 2; | |
60 | else | |
61 | return numVertices(); | |
62 | } | |
63 | ||
64 | /** | |
65 | * @return amount of vertices | |
66 | */ | |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
67 | inline unsigned int numVertices() const |
19 | 68 | { |
69 | switch (type) | |
70 | { | |
71 | case Type::EdgeLine: | |
72 | return 2; | |
73 | case Type::Triangle: | |
74 | return 3; | |
75 | case Type::ConditionalEdge: | |
76 | case Type::Quadrilateral: | |
77 | return 4; | |
78 | } | |
22
6da867fa5429
commit work on GL rendering
Teemu Piippo <teemu@hecknology.net>
parents:
21
diff
changeset
|
79 | return 0; |
19 | 80 | } |
81 | }; | |
82 | ||
83 | Q_DECLARE_METATYPE(gl::Polygon) | |
84 | ||
85 | namespace gl | |
86 | { | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
87 | inline Polygon edgeLine(const glm::vec3& v_1, const glm::vec3& v_2, ldraw::Color color, ldraw::Id id) |
19 | 88 | { |
21 | 89 | return {Polygon::EdgeLine, {v_1, v_2}, color, id}; |
19 | 90 | } |
91 | ||
21 | 92 | inline Polygon triangle( |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
93 | const glm::vec3& v_1, |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
94 | const glm::vec3& v_2, |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
95 | const glm::vec3& v_3, |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
96 | ldraw::Color color, |
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
97 | ldraw::Id id) |
19 | 98 | { |
21 | 99 | return {Polygon::Triangle, {v_1, v_2, v_3}, color, id}; |
19 | 100 | } |
101 | ||
102 | inline Polygon quadrilateral( | |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
103 | const glm::vec3& v_1, |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
104 | const glm::vec3& v_2, |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
105 | const glm::vec3& v_3, |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
106 | const glm::vec3& v_4, |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
107 | ldraw::Color color, |
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
108 | ldraw::Id id) |
19 | 109 | { |
21 | 110 | return {Polygon::Quadrilateral, {v_1, v_2, v_3, v_4}, color, id}; |
19 | 111 | } |
112 | ||
113 | inline Polygon conditionalEdge( | |
33
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
114 | const glm::vec3& v_1, |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
115 | const glm::vec3& v_2, |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
116 | const glm::vec3& control_1, |
4c41bfe2ec6e
replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents:
26
diff
changeset
|
117 | const glm::vec3& control_2, |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
118 | ldraw::Color color, |
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
119 | ldraw::Id id) |
19 | 120 | { |
21 | 121 | return {Polygon::ConditionalEdge, {v_1, v_2, control_1, control_2}, color, id}; |
19 | 122 | } |
123 | ||
124 | // Vbo names | |
26 | 125 | enum class ArrayClass : std::uint8_t |
19 | 126 | { |
127 | Lines, | |
128 | Triangles, | |
129 | Quads, | |
130 | ConditionalLines | |
131 | }; | |
35
98906a94732f
renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents:
34
diff
changeset
|
132 | |
26 | 133 | constexpr ArrayClass ARRAY_CLASSES[] = {ArrayClass::Lines, ArrayClass::Triangles, ArrayClass::Quads, ArrayClass::ConditionalLines}; |
134 | constexpr int NUM_ARRAY_CLASSES = countof(ARRAY_CLASSES); | |
19 | 135 | |
136 | enum class RenderStyle | |
137 | { | |
138 | Normal, | |
139 | Wireframe, | |
140 | BfcRedGreen, | |
46 | 141 | RandomColors, |
142 | PickScene | |
19 | 143 | }; |
37 | 144 | |
145 | // These are also defined in shaders | |
146 | enum class FragmentStyle | |
147 | { | |
148 | Normal = 0, | |
149 | BfcGreen = 1, | |
150 | BfcRed = 2, | |
151 | RandomColors = 3, | |
46 | 152 | Id = 4, |
37 | 153 | }; |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
154 | |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
155 | // User options for rendering |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
156 | struct RenderPreferences |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
157 | { |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
158 | gl::RenderStyle style = gl::RenderStyle::Normal; |
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
159 | QColor mainColor{255, 255, 64}; |
40
30cb5e836736
added configurable background color
Teemu Piippo <teemu@hecknology.net>
parents:
39
diff
changeset
|
160 | QColor backgroundColor{48, 48, 48}; |
48
3c10f0e2fbe0
added selection highlighting
Teemu Piippo <teemu@hecknology.net>
parents:
46
diff
changeset
|
161 | QColor selectedColor{32, 32, 255}; |
44
c6114b3af3a6
added configurable line thickness
Teemu Piippo <teemu@hecknology.net>
parents:
41
diff
changeset
|
162 | GLfloat lineThickness = 2.0f; |
45
272c84c7c87e
added configurable line anti-aliasing
Teemu Piippo <teemu@hecknology.net>
parents:
44
diff
changeset
|
163 | bool lineAntiAliasing = true; |
39
caac957e9834
Main color is now configurable
Teemu Piippo <teemu@hecknology.net>
parents:
37
diff
changeset
|
164 | }; |
19 | 165 | } |