BsRendererMeshData.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #pragma once
  2. #include "BsCorePrerequisites.h"
  3. #include "BsMeshData.h"
  4. namespace BansheeEngine
  5. {
  6. /**
  7. * @brief Available vertex layouts (Combinations other than those provided are allowed).
  8. */
  9. enum class VertexLayout
  10. {
  11. Position = 0x01,
  12. Color = 0x02,
  13. Normal = 0x04,
  14. Tangent = 0x08,
  15. BoneWeights = 0x10,
  16. UV0 = 0x20,
  17. UV1 = 0x40,
  18. PC = Position | Color,
  19. PU = Position | UV0,
  20. PCU = Position | Color | UV0,
  21. PCN = Position | Color | Normal,
  22. PCNU = Position | Color | Normal | UV0,
  23. PCNT = Position | Color | Normal | Tangent,
  24. PCNTU = Position | Color | Normal | Tangent | UV0,
  25. PN = Position | Normal,
  26. PNU = Position | Normal | UV0,
  27. PNT = Position | Normal | Tangent,
  28. PNTU = Position | Normal | Tangent | UV0,
  29. };
  30. /**
  31. * @brief Wrapper around MeshData that constructs the default mesh data structure
  32. * expected by the renderer and other engine systems. Data will be compressed and
  33. * uncompressed when written to and read to as needed to comply with wanted format.
  34. *
  35. * @note This is the default implementation while the Renderer plugins can override it by overriding
  36. * createMeshData method in their Renderer implementation.
  37. */
  38. class BS_CORE_EXPORT RendererMeshData
  39. {
  40. public:
  41. /**
  42. * @brief Reads the vertex positions into the provided output buffer.
  43. * Data will be copied and potentially uncompressed to fit the output
  44. * format as needed.
  45. *
  46. * @param buffer Pre-allocated buffer to output the position data to.
  47. * @param size Size of the pre-allocated buffer. Must be big enough to fit
  48. * all contents (numVertices * sizeof(Vector3)).
  49. */
  50. void getPositions(Vector3* buffer, UINT32 size);
  51. /**
  52. * @brief Writes the vertex positions from the provided output buffer.
  53. * Data will be copied and potentially compressed to fit the internal
  54. * mesh data format as needed.
  55. *
  56. * @param buffer Pre-allocated buffer to read the position data from.
  57. * @param size Size of the input buffer. Must be (numVertices * sizeof(Vector3)).
  58. */
  59. void setPositions(Vector3* buffer, UINT32 size);
  60. /**
  61. * @brief Reads the vertex normals into the provided output buffer.
  62. * Data will be copied and potentially uncompressed to fit the output
  63. * format as needed.
  64. *
  65. * @param buffer Pre-allocated buffer to output the normal data to.
  66. * @param size Size of the pre-allocated buffer. Must be big enough to fit
  67. * all contents (numVertices * sizeof(Vector3)).
  68. */
  69. void getNormals(Vector3* buffer, UINT32 size);
  70. /**
  71. * @brief Writes the vertex normals from the provided output buffer.
  72. * Data will be copied and potentially compressed to fit the internal
  73. * mesh data format as needed.
  74. *
  75. * @param buffer Pre-allocated buffer to read the normal data from.
  76. * @param size Size of the input buffer. Must be (numVertices * sizeof(Vector3)).
  77. */
  78. void setNormals(Vector3* buffer, UINT32 size);
  79. /**
  80. * @brief Reads the vertex tangents into the provided output buffer.
  81. * Data will be copied and potentially uncompressed to fit the output
  82. * format as needed.
  83. *
  84. * @param buffer Pre-allocated buffer to output the tangent data to.
  85. * @param size Size of the pre-allocated buffer. Must be big enough to fit
  86. * all contents (numVertices * sizeof(Vector4)).
  87. */
  88. void getTangents(Vector4* buffer, UINT32 size);
  89. /**
  90. * @brief Writes the vertex tangents from the provided output buffer.
  91. * Data will be copied and potentially compressed to fit the internal
  92. * mesh data format as needed.
  93. *
  94. * @param buffer Pre-allocated buffer to read the tangent data from.
  95. * @param size Size of the input buffer. Must be (numVertices * sizeof(Vector4)).
  96. */
  97. void setTangents(Vector4* buffer, UINT32 size);
  98. /**
  99. * @brief Reads the vertex colors into the provided output buffer.
  100. * Data will be copied and potentially uncompressed to fit the output
  101. * format as needed.
  102. *
  103. * @param buffer Pre-allocated buffer to output the color data to.
  104. * @param size Size of the pre-allocated buffer. Must be big enough to fit
  105. * all contents (numVertices * sizeof(Color)).
  106. */
  107. void getColors(Color* buffer, UINT32 size);
  108. /**
  109. * @brief Writes the vertex colors from the provided output buffer.
  110. * Data will be copied and potentially compressed to fit the internal
  111. * mesh data format as needed.
  112. *
  113. * @param buffer Pre-allocated buffer to read the color data from.
  114. * @param size Size of the input buffer. Must be (numVertices * sizeof(Color)).
  115. */
  116. void setColors(Color* buffer, UINT32 size);
  117. /**
  118. * @brief Writes the vertex colors from the provided output buffer.
  119. * Data will be copied and potentially compressed to fit the internal
  120. * mesh data format as needed.
  121. *
  122. * @param buffer Pre-allocated buffer to read the color data from. Colors should be in RGBA format.
  123. * @param size Size of the input buffer. Must be (numVertices * sizeof(UINT32)).
  124. */
  125. void setColors(UINT32* buffer, UINT32 size);
  126. /**
  127. * @brief Reads the first UV channel coordinates into the provided output buffer.
  128. * Data will be copied and potentially uncompressed to fit the output
  129. * format as needed.
  130. *
  131. * @param buffer Pre-allocated buffer to output the coordinate data to.
  132. * @param size Size of the pre-allocated buffer. Must be big enough to fit
  133. * all contents (numVertices * sizeof(Vector2)).
  134. */
  135. void getUV0(Vector2* buffer, UINT32 size);
  136. /**
  137. * @brief Writes the first UV channel coordinates from the provided output buffer.
  138. * Data will be copied and potentially compressed to fit the internal
  139. * mesh data format as needed.
  140. *
  141. * @param buffer Pre-allocated buffer to read the coordinate data from.
  142. * @param size Size of the input buffer. Must be (numVertices * sizeof(Vector2)).
  143. */
  144. void setUV0(Vector2* buffer, UINT32 size);
  145. /**
  146. * @brief Reads the second UV channel coordinates into the provided output buffer.
  147. * Data will be copied and potentially uncompressed to fit the output
  148. * format as needed.
  149. *
  150. * @param buffer Pre-allocated buffer to output the coordinate data to.
  151. * @param size Size of the pre-allocated buffer. Must be big enough to fit
  152. * all contents (numVertices * sizeof(Vector2)).
  153. */
  154. void getUV1(Vector2* buffer, UINT32 size);
  155. /**
  156. * @brief Writes the second UV channel coordinates from the provided output buffer.
  157. * Data will be copied and potentially compressed to fit the internal
  158. * mesh data format as needed.
  159. *
  160. * @param buffer Pre-allocated buffer to read the coordinate data from.
  161. * @param size Size of the input buffer. Must be (numVertices * sizeof(Vector2)).
  162. */
  163. void setUV1(Vector2* buffer, UINT32 size);
  164. /**
  165. * @brief Reads the bone weights and indices into the provided output buffer.
  166. * Data will be copied and potentially uncompressed to fit the output
  167. * format as needed.
  168. *
  169. * @param buffer Pre-allocated buffer to output the bone weight data to.
  170. * @param size Size of the pre-allocated buffer. Must be big enough to fit
  171. * all contents (numVertices * sizeof(BoneWeight)).
  172. */
  173. void getBoneWeights(BoneWeight* buffer, UINT32 size);
  174. /**
  175. * @brief Writes the bone weights and indices from the provided output buffer.
  176. * Data will be copied and potentially compressed to fit the internal
  177. * mesh data format as needed.
  178. *
  179. * @param buffer Pre-allocated buffer to read the bone weight data from.
  180. * @param size Size of the input buffer. Must be (numVertices * sizeof(BoneWeight)).
  181. */
  182. void setBoneWeights(BoneWeight* buffer, UINT32 size);
  183. /**
  184. * @brief Reads the indices into the provided output buffer.
  185. * Data will be copied and potentially uncompressed to fit the output
  186. * format as needed.
  187. *
  188. * @param buffer Pre-allocated buffer to output the index data to.
  189. * @param size Size of the pre-allocated buffer. Must be big enough to fit
  190. * all contents (numVertices * sizeof(INT32)).
  191. */
  192. void getIndices(UINT32* buffer, UINT32 size);
  193. /**
  194. * @brief Writes the indices from the provided output buffer.
  195. * Data will be copied and potentially compressed to fit the internal
  196. * mesh data format as needed.
  197. *
  198. * @param buffer Pre-allocated buffer to read the index data from.
  199. * @param size Size of the input buffer. Must be (numVertices * sizeof(INT32)).
  200. */
  201. void setIndices(UINT32* buffer, UINT32 size);
  202. /**
  203. * @brief Returns the underlying MeshData structure.
  204. */
  205. MeshDataPtr getData() const { return mMeshData; }
  206. /**
  207. * @brief Creates a new empty mesh data structure.
  208. */
  209. static RendererMeshDataPtr create(UINT32 numVertices, UINT32 numIndices, VertexLayout layout, IndexType indexType = IT_32BIT);
  210. /**
  211. * @brief Creates a new mesh data structure using an existing mesh data buffer.
  212. */
  213. static RendererMeshDataPtr create(const MeshDataPtr& meshData);
  214. /**
  215. * @brief Creates a vertex descriptor from a vertex layout enum.
  216. */
  217. static VertexDataDescPtr vertexLayoutVertexDesc(VertexLayout type);
  218. private:
  219. friend class CoreRenderer;
  220. RendererMeshData(UINT32 numVertices, UINT32 numIndices, VertexLayout layout, IndexType indexType = IT_32BIT);
  221. RendererMeshData(const MeshDataPtr& meshData);
  222. MeshDataPtr mMeshData;
  223. };
  224. }