BsVertexDeclaration.h 5.1 KB

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