Unofficial OpenGL Software Development Kit: C:/Projects/distro/glsdk_0_5_1/glmesh/include/glmesh/VertexFormat.h Source File

Unofficial OpenGL Software Development Kit 0.5.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VertexFormat.h
Go to the documentation of this file.
1
2 #ifndef GLSDK_MESH_VERTEX_FORMAT_H
3 #define GLSDK_MESH_VERTEX_FORMAT_H
4
10 #include <vector>
11 #include <string>
12 #include <exception>
13 #include <boost/noncopyable.hpp>
14
15 namespace glmesh
16 {
19
21 class VertexFormatException : public std::exception
22 {
23 public:
24 virtual ~VertexFormatException() throw() {}
25
26 virtual const char *what() const throw() {return message.c_str();}
27
28 protected:
29 std::string message;
30 };
31
33 class AttributeDataInvalidException : public VertexFormatException
34 {
35 public:
36 AttributeDataInvalidException(int numComponentsGiven);
37
38 AttributeDataInvalidException(const std::string &msg)
39 {
40 message = msg;
41 }
42 };
43
45 class AttributeDataUnsupportedException : public VertexFormatException
46 {
47 public:
48 AttributeDataUnsupportedException(unsigned int requestedAttrib, GLint maxAttribs);
49
50 AttributeDataUnsupportedException(const std::string &msg)
51 {
52 message = msg;
53 }
54 };
55
57 class AttributeIndexMultipleRefException : public VertexFormatException
58 {
59 public:
60 AttributeIndexMultipleRefException(unsigned int attribIndex);
61 };
62
63
65
68
72 enum VertexDataType
73 {
74 VDT_HALF_FLOAT,
75 VDT_SINGLE_FLOAT,
76 VDT_DOUBLE_FLOAT,
77
78 VDT_SIGN_BYTE,
79 VDT_UNSIGN_BYTE,
80 VDT_SIGN_SHORT,
81 VDT_UNSIGN_SHORT,
82 VDT_SIGN_INT,
83 VDT_UNSIGN_INT,
84
85 NUM_VERTEX_DATA_TYPES,
86 };
87
98 enum AttribDataType
99 {
100 ADT_FLOAT,
101 ADT_NORM_FLOAT,
102 ADT_INTEGER,
103 ADT_DOUBLE,
104
105 NUM_ATTRIB_DATA_TYPES,
106 };
107
108
119 class AttribDesc
120 {
121 public:
132 AttribDesc(unsigned int attribIndex, unsigned int numComponents,
133 VertexDataType vertType, AttribDataType attribType);
134
136 unsigned int GetAttribIndex() const {return m_attribIndex;}
137
139 unsigned int GetNumComponents() const {return m_numComponents;}
140
142 VertexDataType GetVertexDataType() const {return m_vertType;}
143
145 AttribDataType GetAttribDataType() const {return m_attribType;}
146
148 size_t ByteSize() const;
149
150 private:
151 unsigned int m_attribIndex;
152 unsigned int m_numComponents;
153 VertexDataType m_vertType;
154 AttribDataType m_attribType;
155 };
156
158 typedef std::vector<AttribDesc> AttributeList;
159
161 struct SeparateAttribFormatTag {};
162
164 const SeparateAttribFormatTag sepFormat;
165
191 class VertexFormat
192 {
193 public:
199 VertexFormat();
200
208 VertexFormat(const AttributeList &attribs);
209
211 size_t GetVertexByteSize() const {return m_vertexSize;}
212
214 size_t GetNumAttribs() const {return m_attribs.size();}
215
218 AttribDesc GetAttribDesc(size_t attribIx) const;
219
222 size_t GetAttribByteOffset(size_t attribIx) const;
223
239 void BindAttributes(size_t baseOffset) const;
240
257 void BindAttribute(size_t baseOffset, size_t attribIx) const;
258
278 void BindAttribFormats(GLuint bindingIndex) const;
279
297 void BindAttribFormat( size_t attribIx, GLuint bindingIndex ) const;
298
306 void DisableAttributes() const;
307
341 class Enable : public boost::noncopyable
342 {
343 public:
349 Enable(const VertexFormat &fmt, size_t baseOffset);
350
363 Enable(const VertexFormat &fmt, GLuint bindingIndex, SeparateAttribFormatTag);
364
366 ~Enable();
367
368 private:
369 const VertexFormat &m_fmt;
370 };
371
372 private:
373 AttributeList m_attribs;
374 std::vector<size_t> m_attribOffsets;
375 size_t m_vertexSize;
376 };
377
379 }
380
381
382 #endif //GLSDK_MESH_VERTEX_FORMAT_H