BsRendererMeshData.h 9.5 KB

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