]> git.lizzy.rs Git - irrlicht.git/blob - include/SSkinMeshBuffer.h
Fix COSOperator::getSystemMemory
[irrlicht.git] / include / SSkinMeshBuffer.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __I_SKIN_MESH_BUFFER_H_INCLUDED__\r
6 #define __I_SKIN_MESH_BUFFER_H_INCLUDED__\r
7 \r
8 #include "IMeshBuffer.h"\r
9 #include "S3DVertex.h"\r
10 \r
11 \r
12 namespace irr\r
13 {\r
14 namespace scene\r
15 {\r
16 \r
17 \r
18 //! A mesh buffer able to choose between S3DVertex2TCoords, S3DVertex and S3DVertexTangents at runtime\r
19 struct SSkinMeshBuffer : public IMeshBuffer\r
20 {\r
21         //! Default constructor\r
22         SSkinMeshBuffer(video::E_VERTEX_TYPE vt=video::EVT_STANDARD) :\r
23                 ChangedID_Vertex(1), ChangedID_Index(1), VertexType(vt),\r
24                 PrimitiveType(EPT_TRIANGLES),\r
25                 MappingHint_Vertex(EHM_NEVER), MappingHint_Index(EHM_NEVER),\r
26                 BoundingBoxNeedsRecalculated(true)\r
27         {\r
28                 #ifdef _DEBUG\r
29                 setDebugName("SSkinMeshBuffer");\r
30                 #endif\r
31         }\r
32 \r
33         //! Get Material of this buffer.\r
34         virtual const video::SMaterial& getMaterial() const _IRR_OVERRIDE_\r
35         {\r
36                 return Material;\r
37         }\r
38 \r
39         //! Get Material of this buffer.\r
40         virtual video::SMaterial& getMaterial() _IRR_OVERRIDE_\r
41         {\r
42                 return Material;\r
43         }\r
44 \r
45         //! Get standard vertex at given index\r
46         virtual video::S3DVertex *getVertex(u32 index)\r
47         {\r
48                 switch (VertexType)\r
49                 {\r
50                         case video::EVT_2TCOORDS:\r
51                                 return (video::S3DVertex*)&Vertices_2TCoords[index];\r
52                         case video::EVT_TANGENTS:\r
53                                 return (video::S3DVertex*)&Vertices_Tangents[index];\r
54                         default:\r
55                                 return &Vertices_Standard[index];\r
56                 }\r
57         }\r
58 \r
59         //! Get pointer to vertex array\r
60         virtual const void* getVertices() const _IRR_OVERRIDE_\r
61         {\r
62                 switch (VertexType)\r
63                 {\r
64                         case video::EVT_2TCOORDS:\r
65                                 return Vertices_2TCoords.const_pointer();\r
66                         case video::EVT_TANGENTS:\r
67                                 return Vertices_Tangents.const_pointer();\r
68                         default:\r
69                                 return Vertices_Standard.const_pointer();\r
70                 }\r
71         }\r
72 \r
73         //! Get pointer to vertex array\r
74         virtual void* getVertices() _IRR_OVERRIDE_\r
75         {\r
76                 switch (VertexType)\r
77                 {\r
78                         case video::EVT_2TCOORDS:\r
79                                 return Vertices_2TCoords.pointer();\r
80                         case video::EVT_TANGENTS:\r
81                                 return Vertices_Tangents.pointer();\r
82                         default:\r
83                                 return Vertices_Standard.pointer();\r
84                 }\r
85         }\r
86 \r
87         //! Get vertex count\r
88         virtual u32 getVertexCount() const _IRR_OVERRIDE_\r
89         {\r
90                 switch (VertexType)\r
91                 {\r
92                         case video::EVT_2TCOORDS:\r
93                                 return Vertices_2TCoords.size();\r
94                         case video::EVT_TANGENTS:\r
95                                 return Vertices_Tangents.size();\r
96                         default:\r
97                                 return Vertices_Standard.size();\r
98                 }\r
99         }\r
100 \r
101         //! Get type of index data which is stored in this meshbuffer.\r
102         /** \return Index type of this buffer. */\r
103         virtual video::E_INDEX_TYPE getIndexType() const _IRR_OVERRIDE_\r
104         {\r
105                 return video::EIT_16BIT;\r
106         }\r
107 \r
108         //! Get pointer to index array\r
109         virtual const u16* getIndices() const _IRR_OVERRIDE_\r
110         {\r
111                 return Indices.const_pointer();\r
112         }\r
113 \r
114         //! Get pointer to index array\r
115         virtual u16* getIndices() _IRR_OVERRIDE_\r
116         {\r
117                 return Indices.pointer();\r
118         }\r
119 \r
120         //! Get index count\r
121         virtual u32 getIndexCount() const _IRR_OVERRIDE_\r
122         {\r
123                 return Indices.size();\r
124         }\r
125 \r
126         //! Get bounding box\r
127         virtual const core::aabbox3d<f32>& getBoundingBox() const _IRR_OVERRIDE_\r
128         {\r
129                 return BoundingBox;\r
130         }\r
131 \r
132         //! Set bounding box\r
133         virtual void setBoundingBox( const core::aabbox3df& box) _IRR_OVERRIDE_\r
134         {\r
135                 BoundingBox = box;\r
136         }\r
137 \r
138         //! Recalculate bounding box\r
139         virtual void recalculateBoundingBox() _IRR_OVERRIDE_\r
140         {\r
141                 if(!BoundingBoxNeedsRecalculated)\r
142                         return;\r
143 \r
144                 BoundingBoxNeedsRecalculated = false;\r
145 \r
146                 switch (VertexType)\r
147                 {\r
148                         case video::EVT_STANDARD:\r
149                         {\r
150                                 if (Vertices_Standard.empty())\r
151                                         BoundingBox.reset(0,0,0);\r
152                                 else\r
153                                 {\r
154                                         BoundingBox.reset(Vertices_Standard[0].Pos);\r
155                                         for (u32 i=1; i<Vertices_Standard.size(); ++i)\r
156                                                 BoundingBox.addInternalPoint(Vertices_Standard[i].Pos);\r
157                                 }\r
158                                 break;\r
159                         }\r
160                         case video::EVT_2TCOORDS:\r
161                         {\r
162                                 if (Vertices_2TCoords.empty())\r
163                                         BoundingBox.reset(0,0,0);\r
164                                 else\r
165                                 {\r
166                                         BoundingBox.reset(Vertices_2TCoords[0].Pos);\r
167                                         for (u32 i=1; i<Vertices_2TCoords.size(); ++i)\r
168                                                 BoundingBox.addInternalPoint(Vertices_2TCoords[i].Pos);\r
169                                 }\r
170                                 break;\r
171                         }\r
172                         case video::EVT_TANGENTS:\r
173                         {\r
174                                 if (Vertices_Tangents.empty())\r
175                                         BoundingBox.reset(0,0,0);\r
176                                 else\r
177                                 {\r
178                                         BoundingBox.reset(Vertices_Tangents[0].Pos);\r
179                                         for (u32 i=1; i<Vertices_Tangents.size(); ++i)\r
180                                                 BoundingBox.addInternalPoint(Vertices_Tangents[i].Pos);\r
181                                 }\r
182                                 break;\r
183                         }\r
184                 }\r
185         }\r
186 \r
187         //! Get vertex type\r
188         virtual video::E_VERTEX_TYPE getVertexType() const _IRR_OVERRIDE_\r
189         {\r
190                 return VertexType;\r
191         }\r
192 \r
193         //! Convert to 2tcoords vertex type\r
194         void convertTo2TCoords()\r
195         {\r
196                 if (VertexType==video::EVT_STANDARD)\r
197                 {\r
198                         for(u32 n=0;n<Vertices_Standard.size();++n)\r
199                         {\r
200                                 video::S3DVertex2TCoords Vertex;\r
201                                 Vertex.Color=Vertices_Standard[n].Color;\r
202                                 Vertex.Pos=Vertices_Standard[n].Pos;\r
203                                 Vertex.Normal=Vertices_Standard[n].Normal;\r
204                                 Vertex.TCoords=Vertices_Standard[n].TCoords;\r
205                                 Vertices_2TCoords.push_back(Vertex);\r
206                         }\r
207                         Vertices_Standard.clear();\r
208                         VertexType=video::EVT_2TCOORDS;\r
209                 }\r
210         }\r
211 \r
212         //! Convert to tangents vertex type\r
213         void convertToTangents()\r
214         {\r
215                 if (VertexType==video::EVT_STANDARD)\r
216                 {\r
217                         for(u32 n=0;n<Vertices_Standard.size();++n)\r
218                         {\r
219                                 video::S3DVertexTangents Vertex;\r
220                                 Vertex.Color=Vertices_Standard[n].Color;\r
221                                 Vertex.Pos=Vertices_Standard[n].Pos;\r
222                                 Vertex.Normal=Vertices_Standard[n].Normal;\r
223                                 Vertex.TCoords=Vertices_Standard[n].TCoords;\r
224                                 Vertices_Tangents.push_back(Vertex);\r
225                         }\r
226                         Vertices_Standard.clear();\r
227                         VertexType=video::EVT_TANGENTS;\r
228                 }\r
229                 else if (VertexType==video::EVT_2TCOORDS)\r
230                 {\r
231                         for(u32 n=0;n<Vertices_2TCoords.size();++n)\r
232                         {\r
233                                 video::S3DVertexTangents Vertex;\r
234                                 Vertex.Color=Vertices_2TCoords[n].Color;\r
235                                 Vertex.Pos=Vertices_2TCoords[n].Pos;\r
236                                 Vertex.Normal=Vertices_2TCoords[n].Normal;\r
237                                 Vertex.TCoords=Vertices_2TCoords[n].TCoords;\r
238                                 Vertices_Tangents.push_back(Vertex);\r
239                         }\r
240                         Vertices_2TCoords.clear();\r
241                         VertexType=video::EVT_TANGENTS;\r
242                 }\r
243         }\r
244 \r
245         //! returns position of vertex i\r
246         virtual const core::vector3df& getPosition(u32 i) const _IRR_OVERRIDE_\r
247         {\r
248                 switch (VertexType)\r
249                 {\r
250                         case video::EVT_2TCOORDS:\r
251                                 return Vertices_2TCoords[i].Pos;\r
252                         case video::EVT_TANGENTS:\r
253                                 return Vertices_Tangents[i].Pos;\r
254                         default:\r
255                                 return Vertices_Standard[i].Pos;\r
256                 }\r
257         }\r
258 \r
259         //! returns position of vertex i\r
260         virtual core::vector3df& getPosition(u32 i) _IRR_OVERRIDE_\r
261         {\r
262                 switch (VertexType)\r
263                 {\r
264                         case video::EVT_2TCOORDS:\r
265                                 return Vertices_2TCoords[i].Pos;\r
266                         case video::EVT_TANGENTS:\r
267                                 return Vertices_Tangents[i].Pos;\r
268                         default:\r
269                                 return Vertices_Standard[i].Pos;\r
270                 }\r
271         }\r
272 \r
273         //! returns normal of vertex i\r
274         virtual const core::vector3df& getNormal(u32 i) const _IRR_OVERRIDE_\r
275         {\r
276                 switch (VertexType)\r
277                 {\r
278                         case video::EVT_2TCOORDS:\r
279                                 return Vertices_2TCoords[i].Normal;\r
280                         case video::EVT_TANGENTS:\r
281                                 return Vertices_Tangents[i].Normal;\r
282                         default:\r
283                                 return Vertices_Standard[i].Normal;\r
284                 }\r
285         }\r
286 \r
287         //! returns normal of vertex i\r
288         virtual core::vector3df& getNormal(u32 i) _IRR_OVERRIDE_\r
289         {\r
290                 switch (VertexType)\r
291                 {\r
292                         case video::EVT_2TCOORDS:\r
293                                 return Vertices_2TCoords[i].Normal;\r
294                         case video::EVT_TANGENTS:\r
295                                 return Vertices_Tangents[i].Normal;\r
296                         default:\r
297                                 return Vertices_Standard[i].Normal;\r
298                 }\r
299         }\r
300 \r
301         //! returns texture coords of vertex i\r
302         virtual const core::vector2df& getTCoords(u32 i) const _IRR_OVERRIDE_\r
303         {\r
304                 switch (VertexType)\r
305                 {\r
306                         case video::EVT_2TCOORDS:\r
307                                 return Vertices_2TCoords[i].TCoords;\r
308                         case video::EVT_TANGENTS:\r
309                                 return Vertices_Tangents[i].TCoords;\r
310                         default:\r
311                                 return Vertices_Standard[i].TCoords;\r
312                 }\r
313         }\r
314 \r
315         //! returns texture coords of vertex i\r
316         virtual core::vector2df& getTCoords(u32 i) _IRR_OVERRIDE_\r
317         {\r
318                 switch (VertexType)\r
319                 {\r
320                         case video::EVT_2TCOORDS:\r
321                                 return Vertices_2TCoords[i].TCoords;\r
322                         case video::EVT_TANGENTS:\r
323                                 return Vertices_Tangents[i].TCoords;\r
324                         default:\r
325                                 return Vertices_Standard[i].TCoords;\r
326                 }\r
327         }\r
328 \r
329         //! append the vertices and indices to the current buffer\r
330         virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) _IRR_OVERRIDE_ {}\r
331 \r
332         //! append the meshbuffer to the current buffer\r
333         virtual void append(const IMeshBuffer* const other) _IRR_OVERRIDE_ {}\r
334 \r
335         //! get the current hardware mapping hint for vertex buffers\r
336         virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const _IRR_OVERRIDE_\r
337         {\r
338                 return MappingHint_Vertex;\r
339         }\r
340 \r
341         //! get the current hardware mapping hint for index buffers\r
342         virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const _IRR_OVERRIDE_\r
343         {\r
344                 return MappingHint_Index;\r
345         }\r
346 \r
347         //! set the hardware mapping hint, for driver\r
348         virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX ) _IRR_OVERRIDE_\r
349         {\r
350                 if (Buffer==EBT_VERTEX)\r
351                         MappingHint_Vertex=NewMappingHint;\r
352                 else if (Buffer==EBT_INDEX)\r
353                         MappingHint_Index=NewMappingHint;\r
354                 else if (Buffer==EBT_VERTEX_AND_INDEX)\r
355                 {\r
356                         MappingHint_Vertex=NewMappingHint;\r
357                         MappingHint_Index=NewMappingHint;\r
358                 }\r
359         }\r
360 \r
361         //! Describe what kind of primitive geometry is used by the meshbuffer\r
362         virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) _IRR_OVERRIDE_\r
363         {\r
364                 PrimitiveType = type;\r
365         }\r
366 \r
367         //! Get the kind of primitive geometry which is used by the meshbuffer\r
368         virtual E_PRIMITIVE_TYPE getPrimitiveType() const _IRR_OVERRIDE_\r
369         {\r
370                 return PrimitiveType;\r
371         }\r
372 \r
373         //! flags the mesh as changed, reloads hardware buffers\r
374         virtual void setDirty(E_BUFFER_TYPE Buffer=EBT_VERTEX_AND_INDEX) _IRR_OVERRIDE_\r
375         {\r
376                 if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_VERTEX)\r
377                         ++ChangedID_Vertex;\r
378                 if (Buffer==EBT_VERTEX_AND_INDEX || Buffer==EBT_INDEX)\r
379                         ++ChangedID_Index;\r
380         }\r
381 \r
382         virtual u32 getChangedID_Vertex() const _IRR_OVERRIDE_ {return ChangedID_Vertex;}\r
383 \r
384         virtual u32 getChangedID_Index() const _IRR_OVERRIDE_ {return ChangedID_Index;}\r
385 \r
386         //! Call this after changing the positions of any vertex.\r
387         void boundingBoxNeedsRecalculated(void) { BoundingBoxNeedsRecalculated = true; }\r
388 \r
389         core::array<video::S3DVertexTangents> Vertices_Tangents;\r
390         core::array<video::S3DVertex2TCoords> Vertices_2TCoords;\r
391         core::array<video::S3DVertex> Vertices_Standard;\r
392         core::array<u16> Indices;\r
393 \r
394         u32 ChangedID_Vertex;\r
395         u32 ChangedID_Index;\r
396 \r
397         //ISkinnedMesh::SJoint *AttachedJoint;\r
398         core::matrix4 Transformation;\r
399 \r
400         video::SMaterial Material;\r
401         video::E_VERTEX_TYPE VertexType;\r
402 \r
403         core::aabbox3d<f32> BoundingBox;\r
404 \r
405         //! Primitive type used for rendering (triangles, lines, ...)\r
406         E_PRIMITIVE_TYPE PrimitiveType;\r
407 \r
408         // hardware mapping hint\r
409         E_HARDWARE_MAPPING MappingHint_Vertex:3;\r
410         E_HARDWARE_MAPPING MappingHint_Index:3;\r
411 \r
412         bool BoundingBoxNeedsRecalculated:1;\r
413 };\r
414 \r
415 \r
416 } // end namespace scene\r
417 } // end namespace irr\r
418 \r
419 #endif\r
420 \r