2 #ifndef GLSDK_MESH_VERTEX_WRITER_H
3 #define GLSDK_MESH_VERTEX_WRITER_H
14 #include <glm/glm.hpp>
15 #include <glm/gtc/half_float.hpp>
29 virtual const char *what()
const throw() {
return message.c_str();}
46 template<
typename BaseType>
47 void VerifyType(
const VertexFormat &fmt,
size_t currAttrib);
50 inline void VerifyType<glm::half>(
const VertexFormat &fmt,
size_t currAttrib)
52 VertexDataType eType = fmt.GetAttribDesc(currAttrib).GetVertexDataType();
58 inline void VerifyType<GLfloat>(
const VertexFormat &fmt,
size_t currAttrib)
60 VertexDataType eType = fmt.GetAttribDesc(currAttrib).GetVertexDataType();
62 throw MismatchWriterTypeException(eType,
"float");
66 inline void VerifyType<GLdouble>(
const VertexFormat &fmt,
size_t currAttrib)
68 VertexDataType eType = fmt.GetAttribDesc(currAttrib).GetVertexDataType();
70 throw MismatchWriterTypeException(eType,
"double");
74 inline void VerifyType<GLbyte>(
const VertexFormat &fmt,
size_t currAttrib)
76 VertexDataType eType = fmt.GetAttribDesc(currAttrib).GetVertexDataType();
78 throw MismatchWriterTypeException(eType,
"signed byte");
82 inline void VerifyType<GLubyte>(
const VertexFormat &fmt,
size_t currAttrib)
84 VertexDataType eType = fmt.GetAttribDesc(currAttrib).GetVertexDataType();
86 throw MismatchWriterTypeException(eType,
"unsigned byte");
90 inline void VerifyType<GLshort>(
const VertexFormat &fmt,
size_t currAttrib)
92 VertexDataType eType = fmt.GetAttribDesc(currAttrib).GetVertexDataType();
94 throw MismatchWriterTypeException(eType,
"signed short");
98 inline void VerifyType<GLushort>(
const VertexFormat &fmt,
size_t currAttrib)
100 VertexDataType eType = fmt.GetAttribDesc(currAttrib).GetVertexDataType();
102 throw MismatchWriterTypeException(eType,
"unsigned short");
106 inline void VerifyType<GLint>(
const VertexFormat &fmt,
size_t currAttrib)
108 VertexDataType eType = fmt.GetAttribDesc(currAttrib).GetVertexDataType();
110 throw MismatchWriterTypeException(eType,
"signed int");
114 inline void VerifyType<GLuint>(
const VertexFormat &fmt,
size_t currAttrib)
116 VertexDataType eType = fmt.GetAttribDesc(currAttrib).GetVertexDataType();
118 throw MismatchWriterTypeException(eType,
"unsigned int");
121 template<
typename BaseType>
122 inline void ExtractData(
void *pData,
const glm::detail::tvec4<BaseType> &val);
125 inline void ExtractData<glm::half>(
void *pData,
const glm::detail::tvec4<glm::half> &val)
127 glm::half *theData = (glm::half*)pData;
135 inline void ExtractData<GLfloat>(
void *pData,
const glm::detail::tvec4<GLfloat> &val)
137 GLfloat *theData = (GLfloat*)pData;
145 inline void ExtractData<GLdouble>(
void *pData,
const glm::detail::tvec4<GLdouble> &val)
147 GLdouble *theData = (GLdouble*)pData;
155 inline void ExtractData<GLbyte>(
void *pData,
const glm::detail::tvec4<GLbyte> &val)
157 GLbyte *theData = (GLbyte*)pData;
165 inline void ExtractData<GLubyte>(
void *pData,
const glm::detail::tvec4<GLubyte> &val)
167 GLubyte *theData = (GLubyte*)pData;
175 inline void ExtractData<GLshort>(
void *pData,
const glm::detail::tvec4<GLshort> &val)
177 GLshort *theData = (GLshort*)pData;
185 inline void ExtractData<GLushort>(
void *pData,
const glm::detail::tvec4<GLushort> &val)
187 GLushort *theData = (GLushort*)pData;
195 inline void ExtractData<GLint>(
void *pData,
const glm::detail::tvec4<GLint> &val)
197 GLint *theData = (GLint*)pData;
205 inline void ExtractData<GLuint>(
void *pData,
const glm::detail::tvec4<GLuint> &val)
207 GLuint *theData = (GLuint*)pData;
214 template<
typename BaseType>
struct InfoTraits;
217 struct InfoTraits<GLubyte>
219 static const GLubyte zero;
220 static const GLubyte one;
224 struct InfoTraits<GLbyte>
226 static const GLbyte zero;
227 static const GLbyte one;
231 struct InfoTraits<GLushort>
233 static const GLushort zero;
234 static const GLushort one;
238 struct InfoTraits<GLshort>
240 static const GLshort zero;
241 static const GLshort one;
245 struct InfoTraits<GLuint>
247 static const GLuint zero;
248 static const GLuint one;
252 struct InfoTraits<GLint>
254 static const GLint zero;
255 static const GLint one;
259 struct InfoTraits<glm::half>
261 static const glm::half zero;
262 static const glm::half one;
266 struct InfoTraits<GLfloat>
268 static const GLfloat zero;
269 static const GLfloat one;
273 struct InfoTraits<GLdouble>
275 static const GLdouble zero;
276 static const GLdouble one;
318 template<
typename Sink>
366 template<
typename BaseType>
367 void Attrib(BaseType x)
369 Attrib<BaseType>(glm::detail::tvec4<BaseType>(x,
370 _detail::InfoTraits<BaseType>::zero,
371 _detail::InfoTraits<BaseType>::zero,
372 _detail::InfoTraits<BaseType>::one));
375 template<
typename BaseType>
376 void Attrib(BaseType x, BaseType y)
378 Attrib<BaseType>(glm::detail::tvec4<BaseType>(x, y,
379 _detail::InfoTraits<BaseType>::zero,
380 _detail::InfoTraits<BaseType>::one));
383 template<
typename BaseType>
384 void Attrib(
const glm::detail::tvec2<BaseType> &val)
386 Attrib<BaseType>(glm::detail::tvec4<BaseType>(val,
387 _detail::InfoTraits<BaseType>::zero,
388 _detail::InfoTraits<BaseType>::one));
391 template<
typename BaseType>
392 void Attrib(BaseType x, BaseType y, BaseType z)
394 Attrib<BaseType>(glm::detail::tvec4<BaseType>(x, y, z, _detail::InfoTraits<BaseType>::one));
397 template<
typename BaseType>
398 void Attrib(
const glm::detail::tvec3<BaseType> &val)
400 Attrib<BaseType>(glm::detail::tvec4<BaseType>(val, _detail::InfoTraits<BaseType>::one));
403 template<
typename BaseType>
404 void Attrib(BaseType x, BaseType y, BaseType z, BaseType w)
406 Attrib<BaseType>(glm::detail::tvec4<BaseType>(x, y, z, w));
409 template<
typename BaseType>
410 void Attrib(
const glm::detail::tvec4<BaseType> &val)
412 _detail::VerifyType<BaseType>(Owner()->GetVertexFormat(), m_currAttrib);
413 char theData[
sizeof(GLdouble) * 4];
414 _detail::ExtractData(theData, val);
415 Owner()->WriteAttribute(theData,
sizeof(BaseType), m_currAttrib);
416 IncrementCurrAttrib();
427 void IncrementCurrAttrib()
430 if(Owner()->GetVertexFormat().GetNumAttribs() == m_currAttrib)
434 Sink *Owner() {
return static_cast<Sink*
>(
this);}
435 const Sink *Owner()
const {
return static_cast<const Sink*
>(
this);}
445 #endif //GLSDK_MESH_VERTEX_WRITER_H