BsRendererMeshData.h 9.3 KB

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