BsRendererMeshData.h 9.3 KB

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