VertexFormat.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #ifndef VERTEXFORMAT_H_
  2. #define VERTEXFORMAT_H_
  3. namespace gameplay
  4. {
  5. /**
  6. * Defines the format of a vertex layout used by a mesh.
  7. *
  8. * A VertexFormat is immutable and cannot be changed
  9. * once created.
  10. */
  11. class VertexFormat
  12. {
  13. public:
  14. /**
  15. * Defines a set of usages for vertex elements.
  16. */
  17. enum Usage
  18. {
  19. POSITION = 1,
  20. NORMAL = 2,
  21. COLOR = 3,
  22. TANGENT = 4,
  23. BINORMAL = 5,
  24. BLENDWEIGHTS = 6,
  25. BLENDINDICES = 7,
  26. TEXCOORD0 = 8,
  27. TEXCOORD1 = 9,
  28. TEXCOORD2 = 10,
  29. TEXCOORD3 = 11,
  30. TEXCOORD4 = 12,
  31. TEXCOORD5 = 13,
  32. TEXCOORD6 = 14,
  33. TEXCOORD7 = 15
  34. };
  35. /**
  36. * Defines a single element within a vertex format.
  37. *
  38. * All vertex elements are assumed to be of type float, but can
  39. * have a varying number of float values (1-4), which is represented
  40. * by the size attribute. Additionally, vertex elements are assumed
  41. * to be tightly packed.
  42. */
  43. class Element
  44. {
  45. public:
  46. /**
  47. * The vertex element usage semantic.
  48. */
  49. Usage usage;
  50. /**
  51. * The number of values in the vertex element.
  52. */
  53. unsigned int size;
  54. /**
  55. * Constructor.
  56. */
  57. Element();
  58. /**
  59. * Constructor.
  60. *
  61. * @param usage The vertex element usage semantic.
  62. * @param size The number of float values in the vertex element.
  63. */
  64. Element(Usage usage, unsigned int size);
  65. /**
  66. * Compares two vertex elements for equality.
  67. *
  68. * @param e The vertex element to compare.
  69. *
  70. * @return true if this element matches the specified one, false otherwise.
  71. */
  72. bool operator == (const Element& e) const;
  73. /**
  74. * Compares to vertex elements for inequality.
  75. *
  76. * @param e The vertex element to compare.
  77. *
  78. * @return true if this element does not match the specified one, false otherwise.
  79. */
  80. bool operator != (const Element& e) const;
  81. };
  82. /**
  83. * Constructor.
  84. *
  85. * The passed in element array is copied into the new VertexFormat.
  86. *
  87. * @param elements The list of vertex elements defining the vertex format.
  88. * @param elementCount The number of items in the elements array.
  89. */
  90. VertexFormat(const Element* elements, unsigned int elementCount);
  91. /**
  92. * Destructor.
  93. */
  94. ~VertexFormat();
  95. /**
  96. * Gets the vertex element at the specified index.
  97. *
  98. * @param index The index of the element to retrieve.
  99. */
  100. const Element& getElement(unsigned int index) const;
  101. /**
  102. * Gets the number of elements in this VertexFormat.
  103. *
  104. * @return The number of items in the elements array.
  105. */
  106. unsigned int getElementCount() const;
  107. /**
  108. * Gets the size (in bytes) of a single vertex using this format.
  109. */
  110. unsigned int getVertexSize() const;
  111. /**
  112. * Compares two vertex formats for equality.
  113. *
  114. * @param f The vertex format to compare.
  115. *
  116. * @return true if the elements in this VertexFormat matches the specified one, false otherwise.
  117. */
  118. bool operator == (const VertexFormat& f) const;
  119. /**
  120. * Compares to vertex formats for inequality.
  121. *
  122. * @param f The vertex format to compare.
  123. *
  124. * @return true if the elements in this VertexFormat are not equal to the specified one, false otherwise.
  125. */
  126. bool operator != (const VertexFormat& f) const;
  127. /**
  128. * Returns a string representation of a Usage enumeration value.
  129. */
  130. static const char* toString(Usage usage);
  131. private:
  132. std::vector<Element> _elements;
  133. unsigned int _vertexSize;
  134. };
  135. }
  136. #endif