49
49
QVector<Vec3d> vertex;
50
50
//! OpenGL compatible array of edge flags to be displayed using vertex arrays.
51
51
QVector<Vec2f> texCoords;
52
//! OpenGL compatible array of vertex colors to be displayed using arrays. (GZ/NEW)
53
//! The color (if exists) shall be multiplied with texture to modulate e.g. for extinction of Milky Way or other large items.
54
QVector<Vec3f> colors;
52
55
//! OpenGL compatible array of indices for the vertex and the textures
53
56
QVector<unsigned short> indices;
59
62
bool isTextured() const {return !texCoords.isEmpty();}
64
bool isColored() const {return !colors.isEmpty();}
61
67
//! call a function for each triangle of the array.
62
//! func should define the following method :
63
//! void operator() (const Vec3d* vertex[3], const Vec2f* tex[3], unsigned int indices[3])
68
//! func should define the following method : // GZ NEW: colors
69
//! void operator() (const Vec3d* vertex[3], const Vec2f* tex[3], const Vec3f* colors[3], unsigned int indices[3])
64
70
//! The method takes arrays of *pointers* as arguments because we can't assume the values are contiguous
65
71
template<class Func>
66
72
inline Func foreachTriangle(Func func) const;
68
//! Create a copy of the array with all the triangles intersecting the projector discontinuty removed.
74
//! Create a copy of the array with all the triangles intersecting the projector discontinuity removed.
69
75
StelVertexArray removeDiscontinuousTriangles(const class StelProjector* prj) const;
72
78
// Below we define a few methods that are templated to be optimized according to different types of VertexArray :
73
79
// The template parameter <bool T> defines whether the array has a texture.
74
80
// The template parameter <bool I> defines whether the array is indexed.
81
// The template parameter <bool C> defines whether the array is colored. // NEW GZ
76
83
const Vec3d* specVertexAt(int i) const {
77
84
return &vertex.at(specIndiceAt<I>(i));
82
89
return T ? &texCoords.at(specIndiceAt<I>(i)) : NULL;
93
template <bool C, bool I>
94
const Vec3f* specColorAt(int i) const {
95
return C ? &colors.at(specIndiceAt<I>(i)) : NULL;
86
99
unsigned int specIndiceAt(unsigned int i) const {
87
100
return I ? indices.at(i) : i;
90
template<bool T, bool I, class Func>
103
template<bool T, bool I, bool C, class Func> // GZ added bool C
91
104
inline Func specForeachTriangle(Func func) const;
99
112
template<class Func>
100
113
Func StelVertexArray::foreachTriangle(Func func) const
102
// Here we just dispach the method into one of the 4 possible cases
115
// Here we just dispatch the method into one of the 8 possible cases // GZ NEW: 8, not 4, cases
103
116
bool textured = isTextured();
117
bool colored = isColored();
104
118
bool useIndice = isIndexed();
108
return specForeachTriangle<true, true, Func>(func);
110
return specForeachTriangle<true, false, Func>(func);
113
return specForeachTriangle<false, true, Func>(func);
115
return specForeachTriangle<false, false, Func>(func);
125
return specForeachTriangle<true, true, true, Func>(func);
127
return specForeachTriangle<true, true, false, Func>(func);
132
return specForeachTriangle<true, false, true, Func>(func);
134
return specForeachTriangle<true, false, false, Func>(func);
142
return specForeachTriangle<false, true, true, Func>(func);
144
return specForeachTriangle<false, true, false, Func>(func);
149
return specForeachTriangle<false, false, true, Func>(func);
151
return specForeachTriangle<false, false, false, Func>(func);
154
Q_ASSERT(0); // GZ. Just make sure...
118
template<bool T, bool I, class Func>
157
template<bool T, bool I, bool C, class Func>
119
158
Func StelVertexArray::specForeachTriangle(Func func) const
121
160
switch (primitiveType)
127
166
func(specVertexAt<I>(i), specVertexAt<I>(i+1), specVertexAt<I>(i+2),
128
167
specTexCoordAt<T, I>(i), specTexCoordAt<T, I>(i+1), specTexCoordAt<T, I>(i+2),
168
specColorAt<C, I>(i), specColorAt<C, I>(i+1), specColorAt<C, I>(i+2),
129
169
specIndiceAt<I>(i), specIndiceAt<I>(i+1), specIndiceAt<I>(i+2));
134
174
const Vec3d* v0 = specVertexAt<I>(0);
135
175
const Vec2f* t0 = specTexCoordAt<T, I>(0);
176
const Vec3f* c0 = specColorAt<C, I>(0);
136
177
unsigned int i0 = specIndiceAt<I>(0);
137
178
for (int i = 1; i < vertex.size() - 1; ++i)
139
180
func(v0, specVertexAt<I>(i), specVertexAt<I>(i+1),
140
181
t0, specTexCoordAt<T, I>(i), specTexCoordAt<T, I>(i+1),
141
i0, specIndiceAt<I>(i), specIndiceAt<I>(i+1));
182
c0, specColorAt<C, I>(i), specColorAt<C, I>(i+1),
183
i0, specIndiceAt<I>(i), specIndiceAt<I>(i+1));
150
192
func(specVertexAt<I>(i-2), specVertexAt<I>(i-1), specVertexAt<I>(i),
151
193
specTexCoordAt<T, I>(i-2), specTexCoordAt<T, I>(i-1), specTexCoordAt<T, I>(i),
194
specColorAt<C, I>(i-2), specColorAt<C, I>(i-1), specColorAt<C, I>(i),
152
195
specIndiceAt<I>(i-2), specIndiceAt<I>(i-1), specIndiceAt<I>(i));
154
197
func(specVertexAt<I>(i-1), specVertexAt<I>(i-2), specVertexAt<I>(i),
155
198
specTexCoordAt<T, I>(i-1), specTexCoordAt<T, I>(i-2), specTexCoordAt<T, I>(i),
199
specColorAt<C, I>(i-1), specColorAt<C, I>(i-2), specColorAt<C, I>(i),
156
200
specIndiceAt<I>(i-1), specIndiceAt<I>(i-2), specIndiceAt<I>(i));
161
Q_ASSERT_X(0, Q_FUNC_INFO, "unsuported primitive type");
205
Q_ASSERT_X(0, Q_FUNC_INFO, "unsupported primitive type");