Home | Namespaces | Hierarchy | Alphabetical List | Class list | Files | Namespace Members | Class members | File members | Tutorials
CIndexBuffer.h
Go to the documentation of this file.
1 // Copyright (C) 2008-2010 Nikolaus Gebhardt
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4 
5 #ifndef __C_INDEX_BUFFER_H_INCLUDED__
6 #define __C_INDEX_BUFFER_H_INCLUDED__
7 
8 #include "IIndexBuffer.h"
9 
10 namespace irr
11 {
12 namespace scene
13 {
14 
15  class CIndexBuffer : public IIndexBuffer
16  {
17 
18  class IIndexList
19  {
20  public:
21  virtual ~IIndexList(){};
22 
23  virtual u32 stride() const =0;
24  virtual u32 size() const =0;
25  virtual void push_back(const u32 &element) =0;
26  virtual u32 operator [](u32 index) const =0;
27  virtual u32 getLast() =0;
28  virtual void setValue(u32 index, u32 value) =0;
29  virtual void set_used(u32 usedNow) =0;
30  virtual void reallocate(u32 new_size) =0;
31  virtual u32 allocated_size() const =0;
32  virtual void* pointer() =0;
33  virtual video::E_INDEX_TYPE getType() const =0;
34  };
35 
36  template <class T>
37  class CSpecificIndexList : public IIndexList
38  {
39  public:
41 
42  virtual u32 stride() const {return sizeof(T);}
43 
44  virtual u32 size() const {return Indices.size();}
45 
46  virtual void push_back(const u32 &element)
47  {
48  Indices.push_back((T&)element);
49  }
50 
51  virtual u32 operator [](u32 index) const
52  {
53  return (u32)(Indices[index]);
54  }
55 
56  virtual u32 getLast() {return (u32)Indices.getLast();}
57 
58  virtual void setValue(u32 index, u32 value)
59  {
60  Indices[index]=(T)value;
61  }
62 
63  virtual void set_used(u32 usedNow)
64  {
65  Indices.set_used(usedNow);
66  }
67 
68  virtual void reallocate(u32 new_size)
69  {
70  Indices.reallocate(new_size);
71  }
72 
73  virtual u32 allocated_size() const
74  {
75  return Indices.allocated_size();
76  }
77 
78  virtual void* pointer() {return Indices.pointer();}
79 
80  virtual video::E_INDEX_TYPE getType() const
81  {
82  if (sizeof(T)==sizeof(u16))
83  return video::EIT_16BIT;
84  else
85  return video::EIT_32BIT;
86  }
87  };
88 
89  public:
90  IIndexList *Indices;
91 
93  {
94  setType(IndexType);
95  }
96 
97  CIndexBuffer(const IIndexBuffer &IndexBufferCopy) :Indices(0), MappingHint(EHM_NEVER), ChangedID(1)
98  {
99  setType(IndexBufferCopy.getType());
100  reallocate(IndexBufferCopy.size());
101 
102  for (u32 n=0;n<IndexBufferCopy.size();++n)
103  push_back(IndexBufferCopy[n]);
104  }
105 
106  virtual ~CIndexBuffer()
107  {
108  delete Indices;
109  }
110 
111  //virtual void setType(video::E_INDEX_TYPE IndexType);
112  virtual void setType(video::E_INDEX_TYPE IndexType)
113  {
114  IIndexList *NewIndices=0;
115 
116  switch (IndexType)
117  {
118  case video::EIT_16BIT:
119  {
120  NewIndices=new CSpecificIndexList<u16>;
121  break;
122  }
123  case video::EIT_32BIT:
124  {
125  NewIndices=new CSpecificIndexList<u32>;
126  break;
127  }
128  }
129 
130  if (Indices)
131  {
132  NewIndices->reallocate( Indices->size() );
133 
134  for(u32 n=0;n<Indices->size();++n)
135  NewIndices->push_back((*Indices)[n]);
136 
137  delete Indices;
138  }
139 
140  Indices=NewIndices;
141  }
142 
143  virtual void* getData() {return Indices->pointer();}
144 
145  virtual video::E_INDEX_TYPE getType() const {return Indices->getType();}
146 
147  virtual u32 stride() const {return Indices->stride();}
148 
149  virtual u32 size() const
150  {
151  return Indices->size();
152  }
153 
154  virtual void push_back(const u32 &element)
155  {
156  Indices->push_back(element);
157  }
158 
159  virtual u32 operator [](u32 index) const
160  {
161  return (*Indices)[index];
162  }
163 
164  virtual u32 getLast()
165  {
166  return Indices->getLast();
167  }
168 
169  virtual void setValue(u32 index, u32 value)
170  {
171  Indices->setValue(index, value);
172  }
173 
174  virtual void set_used(u32 usedNow)
175  {
176  Indices->set_used(usedNow);
177  }
178 
179  virtual void reallocate(u32 new_size)
180  {
181  Indices->reallocate(new_size);
182  }
183 
184  virtual u32 allocated_size() const
185  {
186  return Indices->allocated_size();
187  }
188 
189  virtual void* pointer()
190  {
191  return Indices->pointer();
192  }
193 
196  {
197  return MappingHint;
198  }
199 
201  virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint )
202  {
203  MappingHint=NewMappingHint;
204  }
205 
207  virtual void setDirty()
208  {
209  ++ChangedID;
210  }
211 
213 
214  virtual u32 getChangedID() const {return ChangedID;}
215 
218  };
219 
220 
221 } // end namespace scene
222 } // end namespace irr
223 
224 #endif
225 

The Irrlicht Engine
The Irrlicht Engine Documentation © 2003-2010 by Nikolaus Gebhardt. Generated on Tue Jun 5 2012 17:57:10 by Doxygen (1.8.1)