]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/vertexformat.h
Check the flat qualifier from the correct member
[libs/gl.git] / source / core / vertexformat.h
index 68c3e4c9a38828f42cba32729dae126ee3f75187..e8ba702db1746c4c4b0ec5357f0f13fe6bf4fc77 100644 (file)
@@ -1,14 +1,15 @@
 #ifndef MSP_GL_VERTEXFORMAT_H_
 #define MSP_GL_VERTEXFORMAT_H_
 
-#include <msp/core/inttypes.h>
+#include <cstdint>
 #include <msp/strings/lexicalcast.h>
 #include "datatype.h"
 
 namespace Msp {
 namespace GL {
 
-/** A single vertex attribute.  Commonly used attributes are named by their
+/**
+A single vertex attribute.  Commonly used attributes are named by their
 semantical meaning in the standard shaders.  Texture coordinates and generic
 attributes can additionally be given an index.  There are four texture
 coordinate attributes available.  The number of available generic attributes
@@ -29,9 +30,9 @@ nnnn nn_f gsss iccc
       └────────────╴Attribute index (semantic)
 
 This information is presented for internal documentation purposes only; it is
-inadvisable for programs to rely on it.
+inadvisable for applications to rely on it.
 */
-enum VertexAttribute
+enum VertexAttribute: std::uint16_t
 {
        VERTEX2 = 0x01C2,
        VERTEX3 = 0x01C3,
@@ -60,6 +61,10 @@ enum VertexAttribute
        GENERIC_I2 = 0x28CA,
        GENERIC_I3 = 0x28CB,
        GENERIC_I4 = 0x28CC,
+       PADDING1 = 0xF811,
+       PADDING2 = 0xF812,
+       PADDING3 = 0xF813,
+       PADDING4 = 0xF814,
        RAW_ATTRIB1 = 0xFDC1,
        RAW_ATTRIB2 = 0xFDC2,
        RAW_ATTRIB3 = 0xFDC3,
@@ -70,16 +75,20 @@ enum VertexAttribute
        RAW_ATTRIB_I4 = 0xFCCC
 };
 
+/**
+Describes the attributes of a vertex.  Up to 15 attributes are allowed.
+*/
 class VertexFormat
 {
-private:
-       enum { MAX_ATTRIBUTES = 15 };
+public:
+       static constexpr unsigned MAX_ATTRIBUTES = 15;
 
-       UInt8 count;
-       UInt16 attributes[MAX_ATTRIBUTES];
+private:
+       std::uint8_t count = 0;
+       VertexAttribute attributes[MAX_ATTRIBUTES];
 
 public:
-       VertexFormat();
+       VertexFormat() = default;
        VertexFormat(VertexAttribute);
 
        VertexFormat operator,(VertexAttribute) const;
@@ -88,10 +97,17 @@ public:
        bool operator==(const VertexFormat &) const;
        bool operator!=(const VertexFormat &other) const { return !(*this==other); }
 
+       unsigned size() const { return count; }
        bool empty() const { return !count; }
-       const UInt16 *begin() const { return attributes; }
-       const UInt16 *end() const { return attributes+count; }
+       const VertexAttribute *begin() const { return attributes; }
+       const VertexAttribute *end() const { return attributes+count; }
+
+       /** Returns the displacement from one vertex to the next. */
        unsigned stride() const;
+
+       /** Returns the offset of an attribute within a vertex.  A stored attribute
+       must have the same semantic and type and at least as many components as
+       requested to be considered a match. */
        int offset(VertexAttribute) const;
 };
 
@@ -108,24 +124,29 @@ VertexAttribute make_indexed_attribute(VertexAttribute, unsigned);
 inline VertexAttribute operator,(VertexAttribute a, unsigned i)
 { return make_indexed_attribute(a, i); }
 
-inline unsigned get_attribute_semantic(UInt16 a)
+inline unsigned get_attribute_semantic(VertexAttribute a)
 { return a>>10; }
 
-inline DataType get_attribute_source_type(UInt16 a)
+inline DataType get_attribute_source_type(VertexAttribute a)
 { return static_cast<DataType>((a&0x70)>>4 | (a&0x180)<<1); }
 
-inline unsigned get_attribute_component_count(UInt16 a)
+inline unsigned get_attribute_component_count(VertexAttribute a)
 { return a&7; }
 
-inline unsigned get_attribute_size(UInt16 a)
+inline unsigned get_attribute_size(VertexAttribute a)
 { return get_attribute_component_count(a)*get_type_size(get_attribute_source_type(a)); }
 
-inline bool is_integer_attribute(UInt16 a)
+inline bool is_integer_attribute(VertexAttribute a)
 { return a&8; }
 
+inline bool is_padding(VertexAttribute a)
+{ return get_attribute_semantic(a)==get_attribute_semantic(PADDING1); }
+
 void operator>>(const LexicalConverter &, VertexAttribute &);
 
 } // namespace GL
 } // namespace Msp
 
+#include "vertexformat_backend.h"
+
 #endif