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