20 #ifndef _STELVERTEXATTRIBUTE_HPP_
21 #define _STELVERTEXATTRIBUTE_HPP_
25 #include <QStringList>
28 #include "VecMath.hpp"
36 AttributeType_Vec4f = 0,
38 AttributeType_Vec3f = 1,
40 AttributeType_Vec2f = 2,
53 inline int attributeDimensions(
const AttributeType type)
55 static const int attributeDimensionsArray [AttributeType_Max] =
57 return attributeDimensionsArray[type];
66 inline int attributeSize(
const AttributeType type)
68 static const int attributeSizeArray [AttributeType_Max] =
70 return attributeSizeArray[type];
77 enum AttributeInterpretation
80 AttributeInterpretation_Position = 0,
82 AttributeInterpretation_Color = 1,
84 AttributeInterpretation_Normal = 2,
86 AttributeInterpretation_TexCoord = 3,
88 AttributeInterpretation_MAX
112 const QString typeStr =
113 attributeString.section(
' ', 0, 0, QString::SectionSkipEmpty);
114 const QString interpretationStr =
115 attributeString.section(
' ', 1, 1, QString::SectionSkipEmpty);
117 if(typeStr ==
"Vec2f") {type = AttributeType_Vec2f;}
118 else if(typeStr ==
"Vec3f") {type = AttributeType_Vec3f;}
119 else if(typeStr ==
"Vec4f") {type = AttributeType_Vec4f;}
122 qDebug() <<
"Unknown vertex attribute type: \"" << typeStr
123 <<
"\" in attribute \"" << attributeString <<
"\"";
124 Q_ASSERT_X(
false, Q_FUNC_INFO,
"Unknown vertex attribute type");
127 if(interpretationStr ==
"Position")
131 else if(interpretationStr ==
"Color")
135 else if(interpretationStr ==
"Normal")
139 else if(interpretationStr ==
"TexCoord")
145 qDebug() <<
"Unknown vertex attribute interpretation: \"" << interpretationStr
146 <<
"\" in attribute \"" << attributeString <<
"\"";
147 Q_ASSERT_X(
false, Q_FUNC_INFO,
"Unknown vertex attribute interpretation");
154 QString attributes(attribsCString);
155 QVector<StelVertexAttribute> result;
156 const QStringList parts = attributes.split(
",");
157 for(
int part = 0; part < parts.size(); ++part)
163 validateAttributes(result);
174 static void validateAttributes(
const QVector<StelVertexAttribute>& attributes)
176 bool vertex, texCoord, normal, color;
177 vertex = texCoord = normal = color =
false;
184 case AttributeInterpretation_Position:
185 Q_ASSERT_X(!vertex, Q_FUNC_INFO,
186 "Vertex type has more than one vertex position attribute");
189 case AttributeInterpretation_TexCoord:
190 Q_ASSERT_X(attributeDimensions(attribute.
type) == 2, Q_FUNC_INFO,
191 "Only 2D texture coordinates are supported at the moment");
192 Q_ASSERT_X(!texCoord,
194 "Vertex type has more than one texture coordinate attribute");
197 case AttributeInterpretation_Normal:
198 Q_ASSERT_X(attributeDimensions(attribute.
type) == 3, Q_FUNC_INFO,
199 "Only 3D vertex normals are supported");
200 Q_ASSERT_X(!normal, Q_FUNC_INFO,
201 "Vertex type has more than one normal attribute");
204 case AttributeInterpretation_Color:
205 Q_ASSERT_X(!color, Q_FUNC_INFO,
206 "Vertex type has more than one color attribute");
210 Q_ASSERT_X(
false, Q_FUNC_INFO,
211 "Unknown vertex attribute interpretation");
215 Q_ASSERT_X(vertex, Q_FUNC_INFO,
216 "Vertex formats without a position attribute are not supported");
239 #define VERTEX_ATTRIBUTES(...)\
240 static const QVector<StelVertexAttribute>& attributes()\
242 static QVector<StelVertexAttribute> attribs =\
243 StelVertexAttribute::parseAttributes(#__VA_ARGS__);\
247 #endif // _STELVERTEXATTRIBUTE_HPP_