1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#ifndef __S_SHARED_MESH_BUFFER_H_INCLUDED__
6
#define __S_SHARED_MESH_BUFFER_H_INCLUDED__
9
#include "IMeshBuffer.h"
15
//! Implementation of the IMeshBuffer interface with shared vertex list
16
struct SSharedMeshBuffer : public IMeshBuffer
19
SSharedMeshBuffer() : IMeshBuffer(), Vertices(0), ChangedID_Vertex(1), ChangedID_Index(1), MappingHintVertex(EHM_NEVER), MappingHintIndex(EHM_NEVER)
22
setDebugName("SSharedMeshBuffer");
27
SSharedMeshBuffer(core::array<video::S3DVertex> *vertices) : IMeshBuffer(), Vertices(vertices)
30
setDebugName("SSharedMeshBuffer");
34
//! returns the material of this meshbuffer
35
virtual const video::SMaterial& getMaterial() const
40
//! returns the material of this meshbuffer
41
virtual video::SMaterial& getMaterial()
46
//! returns pointer to vertices
47
virtual const void* getVertices() const
50
return Vertices->const_pointer();
55
//! returns pointer to vertices
56
virtual void* getVertices()
59
return Vertices->pointer();
64
//! returns amount of vertices
65
virtual u32 getVertexCount() const
68
return Vertices->size();
73
//! returns pointer to Indices
74
virtual const u16* getIndices() const
76
return Indices.const_pointer();
79
//! returns pointer to Indices
80
virtual u16* getIndices()
82
return Indices.pointer();
85
//! returns amount of indices
86
virtual u32 getIndexCount() const
88
return Indices.size();
91
//! returns an axis aligned bounding box
92
virtual const core::aabbox3d<f32>& getBoundingBox() const
97
//! set user axis aligned bounding box
98
virtual void setBoundingBox( const core::aabbox3df& box)
103
//! returns which type of vertex data is stored.
104
virtual video::E_VERTEX_TYPE getVertexType() const
106
return video::EVT_STANDARD;
109
//! recalculates the bounding box. should be called if the mesh changed.
110
virtual void recalculateBoundingBox()
112
if (!Vertices || Vertices->empty() || Indices.empty())
113
BoundingBox.reset(0,0,0);
116
BoundingBox.reset((*Vertices)[Indices[0]].Pos);
117
for (u32 i=1; i<Indices.size(); ++i)
118
BoundingBox.addInternalPoint((*Vertices)[Indices[i]].Pos);
122
//! append the vertices and indices to the current buffer
123
virtual void append(const void* const vertices, u32 numVertices, const u16* const indices, u32 numIndices) {}
125
//! append the meshbuffer to the current buffer
126
virtual void append(const IMeshBuffer* const other) {}
129
//! get the current hardware mapping hint
130
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Vertex() const
132
return MappingHintVertex;
135
//! get the current hardware mapping hint
136
virtual E_HARDWARE_MAPPING getHardwareMappingHint_Index() const
138
return MappingHintIndex;
141
//! set the hardware mapping hint, for driver
142
virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint, E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX )
144
if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_VERTEX)
145
MappingHintVertex=NewMappingHint;
146
if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_INDEX)
147
MappingHintIndex=NewMappingHint;
151
//! flags the mesh as changed, reloads hardware buffers
152
virtual void setDirty(E_BUFFER_TYPE buffer=EBT_VERTEX_AND_INDEX)
154
if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_VERTEX)
156
if (buffer==EBT_VERTEX_AND_INDEX || buffer==EBT_INDEX)
160
//! Get the currently used ID for identification of changes.
161
/** This shouldn't be used for anything outside the VideoDriver. */
162
virtual u32 getChangedID_Vertex() const {return ChangedID_Vertex;}
164
//! Get the currently used ID for identification of changes.
165
/** This shouldn't be used for anything outside the VideoDriver. */
166
virtual u32 getChangedID_Index() const {return ChangedID_Index;}
168
//! Material of this meshBuffer
169
video::SMaterial Material;
171
//! Shared Array of vertices
172
core::array<video::S3DVertex> *Vertices;
175
core::array<u16> Indices;
177
//! ID used for hardware buffer management
178
u32 ChangedID_Vertex;
180
//! ID used for hardware buffer management
184
core::aabbox3df BoundingBox;
186
//! hardware mapping hint
187
E_HARDWARE_MAPPING MappingHintVertex;
188
E_HARDWARE_MAPPING MappingHintIndex;
193
} // end namespace scene
194
} // end namespace irr