VertexFormat.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #ifndef VERTEXFORMAT_H_
  2. #define VERTEXFORMAT_H_
  3. #include "Ref.h"
  4. namespace gameplay
  5. {
  6. /**
  7. * Defines the format of a vertex layout used by a mesh.
  8. *
  9. * A VertexFormat is immutable and cannot be changed
  10. * once created.
  11. */
  12. class VertexFormat : public Ref
  13. {
  14. public:
  15. /**
  16. * Defines a set of usages for vertex elements.
  17. */
  18. enum Usage
  19. {
  20. POSITION = 1,
  21. NORMAL = 2,
  22. COLOR = 3,
  23. TANGENT = 4,
  24. BINORMAL = 5,
  25. BLENDWEIGHTS = 6,
  26. BLENDINDICES = 7,
  27. TEXCOORD0 = 8,
  28. TEXCOORD1 = 9,
  29. TEXCOORD2 = 10,
  30. TEXCOORD3 = 11,
  31. TEXCOORD4 = 12,
  32. TEXCOORD5 = 13,
  33. TEXCOORD6 = 14,
  34. TEXCOORD7 = 15
  35. };
  36. /**
  37. * Defines a single element within a vertex format.
  38. *
  39. * All vertex elements are assumed to be of type float, but can
  40. * have a varying number of float values (1-4), which is represented
  41. * by the size attribute. Additionally, vertex elements are assumed
  42. * to be tightly packed.
  43. */
  44. class Element
  45. {
  46. public:
  47. /**
  48. * The vertex element usage semantic.
  49. */
  50. Usage usage;
  51. /**
  52. * The number of values in the vertex element.
  53. */
  54. unsigned int size;
  55. /**
  56. * Constructor.
  57. */
  58. Element();
  59. /**
  60. * Constructor.
  61. *
  62. * @param usage The vertex element usage semantic.
  63. * @param size The number of float values in the vertex element.
  64. */
  65. Element(Usage usage, unsigned int size);
  66. };
  67. /**
  68. * Returns a unique VertexFormat for the request vertex element layout.
  69. *
  70. * @param elements The list of vertex elements defining the vertex format.
  71. * @param elementCount The number of items in the elements array.
  72. *
  73. * @return A unique VertexFormat object.
  74. */
  75. static VertexFormat* create(const Element* elements, unsigned int elementCount);
  76. /**
  77. * Returns the vertex element at the specified index.
  78. *
  79. * index The index of the element to retreive.
  80. */
  81. const Element& getElement(unsigned int index) const;
  82. /**
  83. * Returns the number of elements in this VertexFormat.
  84. *
  85. * @return The number of items in the elements array.
  86. */
  87. unsigned int getElementCount() const;
  88. /**
  89. * Returns the size (in bytes) of a single vertex using this format.
  90. */
  91. unsigned int getVertexSize() const;
  92. private:
  93. /**
  94. * Constructor.
  95. */
  96. VertexFormat();
  97. /**
  98. * Destructor.
  99. */
  100. ~VertexFormat();
  101. Element* _elements;
  102. unsigned int _elementCount;
  103. unsigned int _vertexSize;
  104. };
  105. }
  106. #endif