]> git.lizzy.rs Git - irrlicht.git/blob - include/SSharedMeshBuffer.h
Add some missing constants to the GL binding
[irrlicht.git] / include / SSharedMeshBuffer.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 __S_SHARED_MESH_BUFFER_H_INCLUDED__\r
6 #define __S_SHARED_MESH_BUFFER_H_INCLUDED__\r
7 \r
8 #include "irrArray.h"\r
9 #include "IMeshBuffer.h"\r
10 \r
11 namespace irr\r
12 {\r
13 namespace scene\r
14 {\r
15         //! Implementation of the IMeshBuffer interface with shared vertex list\r
16         struct SSharedMeshBuffer : public IMeshBuffer\r
17         {\r
18                 //! constructor\r
19                 SSharedMeshBuffer() \r
20                         : IMeshBuffer()\r
21                         , Vertices(0), ChangedID_Vertex(1), ChangedID_Index(1)\r
22                         , MappingHintVertex(EHM_NEVER), MappingHintIndex(EHM_NEVER)\r
23                         , PrimitiveType(EPT_TRIANGLES)\r
24                 {\r
25                         #ifdef _DEBUG\r
26                         setDebugName("SSharedMeshBuffer");\r
27                         #endif\r
28                 }\r
29 \r
30                 //! constructor\r
31                 SSharedMeshBuffer(core::array<video::S3DVertex> *vertices) : IMeshBuffer(), Vertices(vertices), ChangedID_Vertex(1), ChangedID_Index(1), MappingHintVertex(EHM_NEVER), MappingHintIndex(EHM_NEVER)\r
32                 {\r
33                         #ifdef _DEBUG\r
34                         setDebugName("SSharedMeshBuffer");\r
35                         #endif\r
36                 }\r
37 \r
38                 //! returns the material of this meshbuffer\r
39                 virtual const video::SMaterial& getMaterial() const _IRR_OVERRIDE_\r
40                 {\r
41                         return Material;\r
42                 }\r
43 \r
44                 //! returns the material of this meshbuffer\r
45                 virtual video::SMaterial& getMaterial() _IRR_OVERRIDE_\r
46                 {\r
47                         return Material;\r
48                 }\r
49 \r
50                 //! returns pointer to vertices\r
51                 virtual const void* getVertices() const _IRR_OVERRIDE_\r
52                 {\r
53                         if (Vertices)\r
54                                 return Vertices->const_pointer();\r
55                         else\r
56                                 return 0;\r
57                 }\r
58 \r
59                 //! returns pointer to vertices\r
60                 virtual void* getVertices() _IRR_OVERRIDE_\r
61                 {\r
62                         if (Vertices)\r
63                                 return Vertices->pointer();\r
64                         else\r
65                                 return 0;\r
66                 }\r
67 \r
68                 //! returns amount of vertices\r
69                 virtual u32 getVertexCount() const _IRR_OVERRIDE_\r
70                 {\r
71                         if (Vertices)\r
72                                 return Vertices->size();\r
73                         else\r
74                                 return 0;\r
75                 }\r
76 \r
77                 //! returns pointer to indices\r
78                 virtual const u16* getIndices() const _IRR_OVERRIDE_\r
79                 {\r
80                         return Indices.const_pointer();\r
81                 }\r
82 \r
83                 //! returns pointer to indices\r
84                 virtual u16* getIndices() _IRR_OVERRIDE_\r
85                 {\r
86                         return Indices.pointer();\r
87                 }\r
88 \r
89                 //! returns amount of indices\r
90                 virtual u32 getIndexCount() const _IRR_OVERRIDE_\r
91                 {\r
92                         return Indices.size();\r
93                 }\r
94 \r
95                 //! Get type of index data which is stored in this meshbuffer.\r
96                 virtual video::E_INDEX_TYPE getIndexType() const _IRR_OVERRIDE_\r
97                 {\r
98                         return video::EIT_16BIT;\r
99                 }\r
100 \r
101                 //! returns an axis aligned bounding box\r
102                 virtual const core::aabbox3d<f32>& getBoundingBox() const _IRR_OVERRIDE_\r
103                 {\r
104                         return BoundingBox;\r
105                 }\r
106 \r
107                 //! set user axis aligned bounding box\r
108                 virtual void setBoundingBox( const core::aabbox3df& box) _IRR_OVERRIDE_\r
109                 {\r
110                         BoundingBox = box;\r
111                 }\r
112 \r
113                 //! returns which type of vertex data is stored.\r
114                 virtual video::E_VERTEX_TYPE getVertexType() const _IRR_OVERRIDE_\r
115                 {\r
116                         return video::EVT_STANDARD;\r
117                 }\r
118 \r
119                 //! recalculates the bounding box. should be called if the mesh changed.\r
120                 virtual void recalculateBoundingBox() _IRR_OVERRIDE_\r
121                 {\r
122                         if (!Vertices || Vertices->empty() || Indices.empty())\r
123                                 BoundingBox.reset(0,0,0);\r
124                         else\r
125                         {\r
126                                 BoundingBox.reset((*Vertices)[Indices[0]].Pos);\r
127                                 for (u32 i=1; i<Indices.size(); ++i)\r
128                                         BoundingBox.addInternalPoint((*Vertices)[Indices[i]].Pos);\r
129                         }\r
130                 }\r
131 \r
132                 //! returns position of vertex i\r
133                 virtual const core::vector3df& getPosition(u32 i) const _IRR_OVERRIDE_\r
134                 {\r
135                         _IRR_DEBUG_BREAK_IF(!Vertices);\r
136                         return (*Vertices)[Indices[i]].Pos;\r
137                 }\r
138 \r
139                 //! returns position of vertex i\r
140                 virtual core::vector3df& getPosition(u32 i) _IRR_OVERRIDE_\r
141                 {\r
142                         _IRR_DEBUG_BREAK_IF(!Vertices);\r
143                         return (*Vertices)[Indices[i]].Pos;\r
144                 }\r
145 \r
146                 //! returns normal of vertex i\r
147                 virtual const core::vector3df& getNormal(u32 i) const _IRR_OVERRIDE_\r
148                 {\r
149                         _IRR_DEBUG_BREAK_IF(!Vertices);\r
150                         return (*Vertices)[Indices[i]].Normal;\r
151                 }\r
152 \r
153                 //! returns normal of vertex i\r
154                 virtual core::vector3df& getNormal(u32 i) _IRR_OVERRIDE_\r
155                 {\r
156                         _IRR_DEBUG_BREAK_IF(!Vertices);\r
157                         return (*Vertices)[Indices[i]].Normal;\r
158                 }\r
159 \r
160                 //! returns texture coord of vertex i\r
161                 virtual const core::vector2df& getTCoords(u32 i) const _IRR_OVERRIDE_\r
162                 {\r
163                         _IRR_DEBUG_BREAK_IF(!Vertices);\r
164                         return (*Vertices)[Indices[i]].TCoords;\r
165                 }\r
166 \r
167                 //! returns texture coord of vertex i\r
168                 virtual core::vector2df& getTCoords(u32 i) _IRR_OVERRIDE_\r
169                 {\r
170                         _IRR_DEBUG_BREAK_IF(!Vertices);\r
171                         return (*Vertices)[Indices[i]].TCoords;\r
172                 }\r
173 \r
174                 //! append the vertices and indices to the current buffer\r
175                 virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices)  _IRR_OVERRIDE_ {}\r
176                 //! append the meshbuffer to the current buffer\r
177                 virtual void append(const IMeshBuffer* const other) _IRR_OVERRIDE_ {}\r
178 \r
179                 //! get the current hardware mapping hint\r
180                 virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const _IRR_OVERRIDE_\r
181                 {\r
182                         return MappingHintVertex;\r
183                 }\r
184 \r
185                 //! get the current hardware mapping hint\r
186                 virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const _IRR_OVERRIDE_\r
187                 {\r
188                         return MappingHintIndex;\r
189                 }\r
190 \r
191                 //! set the hardware mapping hint, for driver\r
192                 virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX ) _IRR_OVERRIDE_\r
193                 {\r
194                         if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_VERTEX)\r
195                                 MappingHintVertex=NewMappingHint;\r
196                         if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_INDEX)\r
197                                 MappingHintIndex=NewMappingHint;\r
198                 }\r
199 \r
200                 //! Describe what kind of primitive geometry is used by the meshbuffer\r
201                 virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) _IRR_OVERRIDE_\r
202                 {\r
203                         PrimitiveType = type;\r
204                 }\r
205 \r
206                 //! Get the kind of primitive geometry which is used by the meshbuffer\r
207                 virtual E_PRIMITIVE_TYPE getPrimitiveType() const _IRR_OVERRIDE_\r
208                 {\r
209                         return PrimitiveType;\r
210                 }\r
211 \r
212                 //! flags the mesh as changed, reloads hardware buffers\r
213                 virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) _IRR_OVERRIDE_\r
214                 {\r
215                         if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_VERTEX)\r
216                                 ++ChangedID_Vertex;\r
217                         if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_INDEX)\r
218                                 ++ChangedID_Index;\r
219                 }\r
220 \r
221                 //! Get the currently used ID for identification of changes.\r
222                 /** This shouldn't be used for anything outside the VideoDriver. */\r
223                 virtual u32 getChangedID_Vertex() const _IRR_OVERRIDE_ {return ChangedID_Vertex;}\r
224 \r
225                 //! Get the currently used ID for identification of changes.\r
226                 /** This shouldn't be used for anything outside the VideoDriver. */\r
227                 virtual u32 getChangedID_Index() const _IRR_OVERRIDE_ {return ChangedID_Index;}\r
228 \r
229                 //! Material of this meshBuffer\r
230                 video::SMaterial Material;\r
231 \r
232                 //! Shared Array of vertices\r
233                 core::array<video::S3DVertex> *Vertices;\r
234 \r
235                 //! Array of indices\r
236                 core::array<u16> Indices;\r
237 \r
238                 //! ID used for hardware buffer management\r
239                 u32 ChangedID_Vertex;\r
240 \r
241                 //! ID used for hardware buffer management\r
242                 u32 ChangedID_Index;\r
243 \r
244                 //! Bounding box\r
245                 core::aabbox3df BoundingBox;\r
246 \r
247                 //! hardware mapping hint\r
248                 E_HARDWARE_MAPPING MappingHintVertex;\r
249                 E_HARDWARE_MAPPING MappingHintIndex;\r
250 \r
251                 //! Primitive type used for rendering (triangles, lines, ...)\r
252                 E_PRIMITIVE_TYPE PrimitiveType;\r
253         };\r
254 \r
255 \r
256 } // end namespace scene\r
257 } // end namespace irr\r
258 \r
259 #endif\r
260 \r