65 { |
64 { |
66 this->setUniformValue(uniformName, value.x, value.y, value.z, value.w); |
65 this->setUniformValue(uniformName, value.x, value.y, value.z, value.w); |
67 } |
66 } |
68 }; |
67 }; |
69 |
68 |
70 struct gl::Polygon |
|
71 { |
|
72 enum Type : qint8 |
|
73 { |
|
74 EdgeLine, |
|
75 Triangle, |
|
76 Quadrilateral, |
|
77 ConditionalEdge |
|
78 } type; |
|
79 glm::vec3 vertices[4]; |
|
80 ldraw::Color color; |
|
81 ModelId id; |
|
82 |
|
83 /** |
|
84 * @return amount of vertices used for geometry |
|
85 */ |
|
86 inline unsigned int numPolygonVertices() const |
|
87 { |
|
88 if (type == Type::ConditionalEdge) |
|
89 return 2; |
|
90 else |
|
91 return numVertices(); |
|
92 } |
|
93 |
|
94 /** |
|
95 * @return amount of vertices |
|
96 */ |
|
97 inline unsigned int numVertices() const |
|
98 { |
|
99 switch (type) |
|
100 { |
|
101 case Type::EdgeLine: |
|
102 return 2; |
|
103 case Type::Triangle: |
|
104 return 3; |
|
105 case Type::ConditionalEdge: |
|
106 case Type::Quadrilateral: |
|
107 return 4; |
|
108 } |
|
109 return 0; |
|
110 } |
|
111 }; |
|
112 |
|
113 Q_DECLARE_METATYPE(gl::Polygon) |
|
114 extern QOpenGLFunctions glfunc; |
69 extern QOpenGLFunctions glfunc; |
115 |
70 |
116 namespace gl |
71 namespace gl |
117 { |
72 { |
118 constexpr Polygon::Type POLYGON_TYPES[] = |
|
119 { |
|
120 Polygon::Type::EdgeLine, |
|
121 Polygon::Type::Triangle, |
|
122 Polygon::Type::Quadrilateral, |
|
123 Polygon::Type::ConditionalEdge |
|
124 }; |
|
125 |
|
126 constexpr int NUM_POLYGON_TYPES = countof(POLYGON_TYPES); |
|
127 |
|
128 inline Polygon edgeLine(const Colored<LineSegment>& seg, ModelId id) |
|
129 { |
|
130 return Polygon{ |
|
131 .type = Polygon::EdgeLine, |
|
132 .vertices = {seg.p1, seg.p2}, |
|
133 .color = seg.color, |
|
134 .id = id, |
|
135 }; |
|
136 } |
|
137 |
|
138 inline Polygon triangle(const Colored<Triangle>& tri, ModelId id) |
|
139 { |
|
140 return Polygon{ |
|
141 .type = Polygon::Triangle, |
|
142 .vertices = {tri.p1, tri.p2, tri.p3}, |
|
143 .color = tri.color, |
|
144 .id = id, |
|
145 }; |
|
146 } |
|
147 |
|
148 inline Polygon quadrilateral(const Colored<Quadrilateral>& quad, ModelId id) |
|
149 { |
|
150 return Polygon{ |
|
151 .type = Polygon::Quadrilateral, |
|
152 .vertices = {quad.p1, quad.p2, quad.p3, quad.p4}, |
|
153 .color = quad.color, |
|
154 .id = id, |
|
155 }; |
|
156 } |
|
157 |
|
158 inline Polygon conditionalEdge(const Colored<ConditionalEdge>& cedge, ModelId id) |
|
159 { |
|
160 return Polygon{ |
|
161 .type = Polygon::ConditionalEdge, |
|
162 .vertices = {cedge.p1, cedge.p2, cedge.c1, cedge.c2}, |
|
163 .color = cedge.color, |
|
164 .id = id, |
|
165 }; |
|
166 } |
|
167 |
|
168 // Vbo names |
|
169 enum class ArrayClass : std::uint8_t |
|
170 { |
|
171 Lines, |
|
172 Triangles, |
|
173 Quads, |
|
174 ConditionalLines |
|
175 }; |
|
176 |
|
177 constexpr ArrayClass ARRAY_CLASSES[] = { |
|
178 ArrayClass::Lines, |
|
179 ArrayClass::Triangles, |
|
180 ArrayClass::Quads, |
|
181 ArrayClass::ConditionalLines, |
|
182 }; |
|
183 constexpr int NUM_ARRAY_CLASSES = countof(ARRAY_CLASSES); |
|
184 |
|
185 // Different ways to render the scene |
73 // Different ways to render the scene |
186 enum class RenderStyle |
74 enum class RenderStyle |
187 { |
75 { |
188 // Normal rendering style |
76 // Normal rendering style |
189 Normal, |
77 Normal, |