~ubuntu-branches/debian/sid/stellarium/sid

« back to all changes in this revision

Viewing changes to src/core/StelVertexArray.hpp

  • Committer: Package Import Robot
  • Author(s): Tomasz Buchert
  • Date: 2015-01-20 19:20:13 UTC
  • mfrom: (1.2.17)
  • Revision ID: package-import@ubuntu.com-20150120192013-n9d3rxliaam647ay
Tags: 0.13.2-1
ImportedĀ UpstreamĀ versionĀ 0.13.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
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;
54
57
 
58
61
 
59
62
        bool isTextured() const {return !texCoords.isEmpty();}
60
63
 
 
64
        bool isColored() const {return !colors.isEmpty();}
 
65
 
 
66
 
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;
67
73
 
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;
70
76
 
71
77
private:
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
75
82
        template <bool I>
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;
83
90
        }
84
91
 
 
92
        // NEW GZ
 
93
        template <bool C, bool I>
 
94
        const Vec3f* specColorAt(int i) const {
 
95
                return C ? &colors.at(specIndiceAt<I>(i)) : NULL;
 
96
        }
 
97
 
85
98
        template<bool I>
86
99
        unsigned int specIndiceAt(unsigned int i) const {
87
100
                return I ? indices.at(i) : i;
88
101
        }
89
102
 
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;
92
105
 
93
106
};
99
112
template<class Func>
100
113
Func StelVertexArray::foreachTriangle(Func func) const
101
114
{
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();
105
119
 
106
120
        if (textured)
107
 
                if (useIndice)
108
 
                        return specForeachTriangle<true, true, Func>(func);
109
 
                else
110
 
                        return specForeachTriangle<true, false, Func>(func);
111
 
        else
112
 
                if (useIndice)
113
 
                        return specForeachTriangle<false, true, Func>(func);
114
 
                else
115
 
                        return specForeachTriangle<false, false, Func>(func);
 
121
        {
 
122
                if (useIndice)
 
123
                {
 
124
                        if (colored)
 
125
                                return specForeachTriangle<true, true, true, Func>(func);
 
126
                        else
 
127
                                return specForeachTriangle<true, true, false, Func>(func);
 
128
                }
 
129
                else // not indiced
 
130
                {
 
131
                        if (colored)
 
132
                                return specForeachTriangle<true, false, true, Func>(func);
 
133
                        else
 
134
                                return specForeachTriangle<true, false, false, Func>(func);
 
135
                }
 
136
        }
 
137
        else // not textured
 
138
        {
 
139
                if (useIndice)
 
140
                {
 
141
                        if (colored)
 
142
                                return specForeachTriangle<false, true, true, Func>(func);
 
143
                        else
 
144
                                return specForeachTriangle<false, true, false, Func>(func);
 
145
                }
 
146
                else // not indiced
 
147
                {
 
148
                        if (colored)
 
149
                                return specForeachTriangle<false, false, true, Func>(func);
 
150
                        else
 
151
                                return specForeachTriangle<false, false, false, Func>(func);
 
152
                }
 
153
        }
 
154
        Q_ASSERT(0); // GZ. Just make sure...
116
155
}
117
156
 
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
120
159
{
121
160
        switch (primitiveType)
126
165
                        {
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));
130
170
                        }
131
171
                        break;
133
173
                {
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)
138
179
                        {
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));
142
184
                        }
143
185
                        break;
144
186
                }
149
191
                                if (i % 2 == 0)
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));
153
196
                                else
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));
157
201
                        }
158
202
                        break;
159
203
                }
160
204
                default:
161
 
                        Q_ASSERT_X(0, Q_FUNC_INFO, "unsuported primitive type");
 
205
                        Q_ASSERT_X(0, Q_FUNC_INFO, "unsupported primitive type");
162
206
        }
163
207
        return func;
164
208
}