BsVertexDeclaration.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsColor.h"
  4. #include "BsCoreObject.h"
  5. namespace BansheeEngine
  6. {
  7. /**
  8. * @brief Semantics that are used for identifying the meaning of
  9. * vertex buffer elements.
  10. */
  11. enum VertexElementSemantic
  12. {
  13. VES_POSITION = 1,
  14. VES_BLEND_WEIGHTS = 2,
  15. VES_BLEND_INDICES = 3,
  16. VES_NORMAL = 4,
  17. VES_COLOR = 5,
  18. VES_TEXCOORD = 6,
  19. VES_BITANGENT = 7,
  20. VES_TANGENT = 8,
  21. VES_POSITIONT = 9,
  22. VES_PSIZE = 10
  23. };
  24. /**
  25. * @brief Types used to identify base types of vertex element contents
  26. */
  27. enum VertexElementType
  28. {
  29. VET_FLOAT1 = 0,
  30. VET_FLOAT2 = 1,
  31. VET_FLOAT3 = 2,
  32. VET_FLOAT4 = 3,
  33. VET_COLOR = 4,
  34. VET_SHORT1 = 5,
  35. VET_SHORT2 = 6,
  36. VET_SHORT3 = 7,
  37. VET_SHORT4 = 8,
  38. VET_UBYTE4 = 9,
  39. VET_COLOR_ARGB = 10,
  40. VET_COLOR_ABGR = 11,
  41. VET_UINT4 = 12,
  42. VET_SINT4 = 13
  43. };
  44. /**
  45. * @brief Describes a single vertex element in a vertex declaration.
  46. */
  47. class BS_CORE_EXPORT VertexElement
  48. {
  49. public:
  50. VertexElement() {}
  51. VertexElement(UINT16 source, UINT32 offset, VertexElementType theType,
  52. VertexElementSemantic semantic, UINT16 index = 0);
  53. bool operator== (const VertexElement& rhs) const;
  54. bool operator!= (const VertexElement& rhs) const;
  55. /**
  56. * @brief Returns index of the vertex buffer from which this element is stored.
  57. */
  58. UINT16 getStreamIdx() const { return mSource; }
  59. /**
  60. * @brief Returns an offset into the buffer where this vertex is stored. This value
  61. * might be in bytes but doesn't have to be, it's likely to be render API specific.
  62. */
  63. UINT32 getOffset() const { return mOffset; }
  64. /**
  65. * @brief Gets the base data type of tis element.
  66. */
  67. VertexElementType getType() const { return mType; }
  68. /**
  69. * @brief Gets a semantic that describes what this element contains.
  70. */
  71. VertexElementSemantic getSemantic() const { return mSemantic; }
  72. /**
  73. * @brief Gets an index of this element. Only relevant when you have
  74. * multiple elements with the same semantic, e.g. uv0, uv1.
  75. */
  76. UINT16 getSemanticIdx() const { return mIndex; }
  77. /**
  78. * @brief Returns the size of this element in bytes.
  79. */
  80. UINT32 getSize() const;
  81. /**
  82. * @brief Returns the size of a base element type.
  83. */
  84. static UINT32 getTypeSize(VertexElementType etype);
  85. /**
  86. * @brief Returns the number of values in the provided base element type.
  87. * e.g. float4 has four values.
  88. */
  89. static UINT16 getTypeCount(VertexElementType etype);
  90. /**
  91. * @brief Gets packed color vertex element type used by the active render system.
  92. */
  93. static VertexElementType getBestColorVertexElementType();
  94. protected:
  95. UINT16 mSource;
  96. UINT32 mOffset;
  97. VertexElementType mType;
  98. VertexElementSemantic mSemantic;
  99. UINT16 mIndex;
  100. };
  101. BS_ALLOW_MEMCPY_SERIALIZATION(VertexElement);
  102. /**
  103. * @brief Describes a set of vertex elements, used for describing contents of
  104. * a vertex buffer or inputs to a vertex GPU program.
  105. */
  106. class BS_CORE_EXPORT VertexDeclaration : public IReflectable, public CoreObject
  107. {
  108. public:
  109. typedef List<VertexElement> VertexElementList;
  110. public:
  111. virtual ~VertexDeclaration();
  112. bool operator== (const VertexDeclaration& rhs) const;
  113. bool operator!= (const VertexDeclaration& rhs) const;
  114. /**
  115. * @brief Get the number of elements in the declaration.
  116. */
  117. UINT32 getElementCount() { return (UINT32)mElementList.size(); }
  118. /**
  119. * @brief Returns a list of vertex elements in the declaration.
  120. */
  121. const VertexElementList& getElements() const { return mElementList; }
  122. /**
  123. * @brief Returns a single vertex element at the specified index.
  124. */
  125. const VertexElement* getElement(UINT16 index);
  126. /**
  127. * @brief Attempts to find an element by the given semantic and semantic index. If no element
  128. * can be found null is returned.
  129. */
  130. virtual const VertexElement* findElementBySemantic(VertexElementSemantic sem, UINT16 index = 0);
  131. /**
  132. * @brief Returns a list of all elements that use the provided source index.
  133. */
  134. virtual VertexElementList findElementsBySource(UINT16 source);
  135. /**
  136. * @brief Returns the total size of all vertex elements using the provided source index.
  137. */
  138. virtual UINT32 getVertexSize(UINT16 source);
  139. protected:
  140. friend class HardwareBufferManager;
  141. VertexDeclaration(const VertexElementList& elements);
  142. protected:
  143. VertexElementList mElementList;
  144. /************************************************************************/
  145. /* SERIALIZATION */
  146. /************************************************************************/
  147. public:
  148. friend class VertexDeclarationRTTI;
  149. static RTTITypeBase* getRTTIStatic();
  150. virtual RTTITypeBase* getRTTI() const;
  151. };
  152. }