]> git.lizzy.rs Git - irrlicht.git/blob - include/IMeshBuffer.h
Drop IrrCompileConfig (#163)
[irrlicht.git] / include / IMeshBuffer.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_MESH_BUFFER_H_INCLUDED__\r
6 #define __I_MESH_BUFFER_H_INCLUDED__\r
7 \r
8 #include "IReferenceCounted.h"\r
9 #include "SMaterial.h"\r
10 #include "aabbox3d.h"\r
11 #include "S3DVertex.h"\r
12 #include "SVertexIndex.h"\r
13 #include "EHardwareBufferFlags.h"\r
14 #include "EPrimitiveTypes.h"\r
15 \r
16 namespace irr\r
17 {\r
18 namespace scene\r
19 {\r
20         //! Struct for holding a mesh with a single material.\r
21         /** A part of an IMesh which has the same material on each face of that\r
22         group. Logical groups of an IMesh need not be put into separate mesh\r
23         buffers, but can be. Separately animated parts of the mesh must be put\r
24         into separate mesh buffers.\r
25         Some mesh buffer implementations have limitations on the number of\r
26         vertices the buffer can hold. In that case, logical grouping can help.\r
27         Moreover, the number of vertices should be optimized for the GPU upload,\r
28         which often depends on the type of gfx card. Typical figures are\r
29         1000-10000 vertices per buffer.\r
30         SMeshBuffer is a simple implementation of a MeshBuffer, which supports\r
31         up to 65535 vertices.\r
32 \r
33         Since meshbuffers are used for drawing, and hence will be exposed\r
34         to the driver, chances are high that they are grab()'ed from somewhere.\r
35         It's therefore required to dynamically allocate meshbuffers which are\r
36         passed to a video driver and only drop the buffer once it's not used in\r
37         the current code block anymore.\r
38         */\r
39         class IMeshBuffer : public virtual IReferenceCounted\r
40         {\r
41         public:\r
42 \r
43                 //! Get the material of this meshbuffer\r
44                 /** \return Material of this buffer. */\r
45                 virtual video::SMaterial& getMaterial() = 0;\r
46 \r
47                 //! Get the material of this meshbuffer\r
48                 /** \return Material of this buffer. */\r
49                 virtual const video::SMaterial& getMaterial() const = 0;\r
50 \r
51                 //! Get type of vertex data which is stored in this meshbuffer.\r
52                 /** \return Vertex type of this buffer. */\r
53                 virtual video::E_VERTEX_TYPE getVertexType() const = 0;\r
54 \r
55                 //! Get access to vertex data. The data is an array of vertices.\r
56                 /** Which vertex type is used can be determined by getVertexType().\r
57                 \return Pointer to array of vertices. */\r
58                 virtual const void* getVertices() const = 0;\r
59 \r
60                 //! Get access to vertex data. The data is an array of vertices.\r
61                 /** Which vertex type is used can be determined by getVertexType().\r
62                 \return Pointer to array of vertices. */\r
63                 virtual void* getVertices() = 0;\r
64 \r
65                 //! Get amount of vertices in meshbuffer.\r
66                 /** \return Number of vertices in this buffer. */\r
67                 virtual u32 getVertexCount() const = 0;\r
68 \r
69                 //! Get type of index data which is stored in this meshbuffer.\r
70                 /** \return Index type of this buffer. */\r
71                 virtual video::E_INDEX_TYPE getIndexType() const =0;\r
72 \r
73                 //! Get access to indices.\r
74                 /** \return Pointer to indices array. */\r
75                 virtual const u16* getIndices() const = 0;\r
76 \r
77                 //! Get access to indices.\r
78                 /** \return Pointer to indices array. */\r
79                 virtual u16* getIndices() = 0;\r
80 \r
81                 //! Get amount of indices in this meshbuffer.\r
82                 /** \return Number of indices in this buffer. */\r
83                 virtual u32 getIndexCount() const = 0;\r
84 \r
85                 //! Get the axis aligned bounding box of this meshbuffer.\r
86                 /** \return Axis aligned bounding box of this buffer. */\r
87                 virtual const core::aabbox3df& getBoundingBox() const = 0;\r
88 \r
89                 //! Set axis aligned bounding box\r
90                 /** \param box User defined axis aligned bounding box to use\r
91                 for this buffer. */\r
92                 virtual void setBoundingBox(const core::aabbox3df& box) = 0;\r
93 \r
94                 //! Recalculates the bounding box. Should be called if the mesh changed.\r
95                 virtual void recalculateBoundingBox() = 0;\r
96 \r
97                 //! returns position of vertex i\r
98                 virtual const core::vector3df& getPosition(u32 i) const = 0;\r
99 \r
100                 //! returns position of vertex i\r
101                 virtual core::vector3df& getPosition(u32 i) = 0;\r
102 \r
103                 //! returns normal of vertex i\r
104                 virtual const core::vector3df& getNormal(u32 i) const = 0;\r
105 \r
106                 //! returns normal of vertex i\r
107                 virtual core::vector3df& getNormal(u32 i) = 0;\r
108 \r
109                 //! returns texture coord of vertex i\r
110                 virtual const core::vector2df& getTCoords(u32 i) const = 0;\r
111 \r
112                 //! returns texture coord of vertex i\r
113                 virtual core::vector2df& getTCoords(u32 i) = 0;\r
114 \r
115                 //! Append the vertices and indices to the current buffer\r
116                 /** Only works for compatible vertex types.\r
117                 \param vertices Pointer to a vertex array.\r
118                 \param numVertices Number of vertices in the array.\r
119                 \param indices Pointer to index array.\r
120                 \param numIndices Number of indices in array. */\r
121                 virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) = 0;\r
122 \r
123                 //! Append the meshbuffer to the current buffer\r
124                 /** Only works for compatible vertex types\r
125                 \param other Buffer to append to this one. */\r
126                 virtual void append(const IMeshBuffer* const other) = 0;\r
127 \r
128                 //! get the current hardware mapping hint\r
129                 virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const = 0;\r
130 \r
131                 //! get the current hardware mapping hint\r
132                 virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const = 0;\r
133 \r
134                 //! set the hardware mapping hint, for driver\r
135                 virtual void setHardwareMappingHint( E_HARDWARE_MAPPING newMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX ) = 0;\r
136 \r
137                 //! flags the meshbuffer as changed, reloads hardware buffers\r
138                 virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX) = 0;\r
139 \r
140                 //! Get the currently used ID for identification of changes.\r
141                 /** This shouldn't be used for anything outside the VideoDriver. */\r
142                 virtual u32 getChangedID_Vertex() const = 0;\r
143 \r
144                 //! Get the currently used ID for identification of changes.\r
145                 /** This shouldn't be used for anything outside the VideoDriver. */\r
146                 virtual u32 getChangedID_Index() const = 0;\r
147 \r
148                 //! Used by the VideoDriver to remember the buffer link.\r
149                 virtual void setHWBuffer(void *ptr) const = 0;\r
150                 virtual void *getHWBuffer() const = 0;\r
151 \r
152                 //! Describe what kind of primitive geometry is used by the meshbuffer\r
153                 /** Note: Default is EPT_TRIANGLES. Using other types is fine for rendering.\r
154                 But meshbuffer manipulation functions might expect type EPT_TRIANGLES\r
155                 to work correctly. Also mesh writers will generally fail (badly!) with other\r
156                 types than EPT_TRIANGLES. */\r
157                 virtual void setPrimitiveType(E_PRIMITIVE_TYPE type) = 0;\r
158 \r
159                 //! Get the kind of primitive geometry which is used by the meshbuffer\r
160                 virtual E_PRIMITIVE_TYPE getPrimitiveType() const = 0;\r
161 \r
162                 //! Calculate how many geometric primitives are used by this meshbuffer\r
163                 virtual u32 getPrimitiveCount() const\r
164                 {\r
165                         const u32 indexCount = getIndexCount();\r
166                         switch (getPrimitiveType())\r
167                         {\r
168                 case scene::EPT_POINTS:         return indexCount;\r
169                 case scene::EPT_LINE_STRIP:     return indexCount-1;\r
170                 case scene::EPT_LINE_LOOP:      return indexCount;\r
171                 case scene::EPT_LINES:          return indexCount/2;\r
172                 case scene::EPT_TRIANGLE_STRIP: return (indexCount-2);\r
173                 case scene::EPT_TRIANGLE_FAN:   return (indexCount-2);\r
174                 case scene::EPT_TRIANGLES:      return indexCount/3;\r
175                 case scene::EPT_QUAD_STRIP:     return (indexCount-2)/2;\r
176                 case scene::EPT_QUADS:          return indexCount/4;\r
177                 case scene::EPT_POLYGON:        return indexCount; // (not really primitives, that would be 1, works like line_strip)\r
178                 case scene::EPT_POINT_SPRITES:  return indexCount;\r
179                         }\r
180                         return 0;\r
181                 }\r
182 \r
183         };\r
184 \r
185 } // end namespace scene\r
186 } // end namespace irr\r
187 \r
188 #endif\r