diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8.1/include/CIndexBuffer.h | 226 |
1 files changed, 226 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8.1/include/CIndexBuffer.h b/libraries/irrlicht-1.8.1/include/CIndexBuffer.h new file mode 100644 index 0000000..b0bb436 --- /dev/null +++ b/libraries/irrlicht-1.8.1/include/CIndexBuffer.h | |||
@@ -0,0 +1,226 @@ | |||
1 | // Copyright (C) 2008-2012 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: | ||
40 | core::array<T> Indices; | ||
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 | // push const ref due to compiler problem with gcc 4.6, big endian | ||
49 | Indices.push_back((const T&)element); | ||
50 | } | ||
51 | |||
52 | virtual u32 operator [](u32 index) const | ||
53 | { | ||
54 | return (u32)(Indices[index]); | ||
55 | } | ||
56 | |||
57 | virtual u32 getLast() {return (u32)Indices.getLast();} | ||
58 | |||
59 | virtual void setValue(u32 index, u32 value) | ||
60 | { | ||
61 | Indices[index]=(T)value; | ||
62 | } | ||
63 | |||
64 | virtual void set_used(u32 usedNow) | ||
65 | { | ||
66 | Indices.set_used(usedNow); | ||
67 | } | ||
68 | |||
69 | virtual void reallocate(u32 new_size) | ||
70 | { | ||
71 | Indices.reallocate(new_size); | ||
72 | } | ||
73 | |||
74 | virtual u32 allocated_size() const | ||
75 | { | ||
76 | return Indices.allocated_size(); | ||
77 | } | ||
78 | |||
79 | virtual void* pointer() {return Indices.pointer();} | ||
80 | |||
81 | virtual video::E_INDEX_TYPE getType() const | ||
82 | { | ||
83 | if (sizeof(T)==sizeof(u16)) | ||
84 | return video::EIT_16BIT; | ||
85 | else | ||
86 | return video::EIT_32BIT; | ||
87 | } | ||
88 | }; | ||
89 | |||
90 | public: | ||
91 | IIndexList *Indices; | ||
92 | |||
93 | CIndexBuffer(video::E_INDEX_TYPE IndexType) :Indices(0), MappingHint(EHM_NEVER), ChangedID(1) | ||
94 | { | ||
95 | setType(IndexType); | ||
96 | } | ||
97 | |||
98 | CIndexBuffer(const IIndexBuffer &IndexBufferCopy) :Indices(0), MappingHint(EHM_NEVER), ChangedID(1) | ||
99 | { | ||
100 | setType(IndexBufferCopy.getType()); | ||
101 | reallocate(IndexBufferCopy.size()); | ||
102 | |||
103 | for (u32 n=0;n<IndexBufferCopy.size();++n) | ||
104 | push_back(IndexBufferCopy[n]); | ||
105 | } | ||
106 | |||
107 | virtual ~CIndexBuffer() | ||
108 | { | ||
109 | delete Indices; | ||
110 | } | ||
111 | |||
112 | //virtual void setType(video::E_INDEX_TYPE IndexType); | ||
113 | virtual void setType(video::E_INDEX_TYPE IndexType) | ||
114 | { | ||
115 | IIndexList *NewIndices=0; | ||
116 | |||
117 | switch (IndexType) | ||
118 | { | ||
119 | case video::EIT_16BIT: | ||
120 | { | ||
121 | NewIndices=new CSpecificIndexList<u16>; | ||
122 | break; | ||
123 | } | ||
124 | case video::EIT_32BIT: | ||
125 | { | ||
126 | NewIndices=new CSpecificIndexList<u32>; | ||
127 | break; | ||
128 | } | ||
129 | } | ||
130 | |||
131 | if (Indices) | ||
132 | { | ||
133 | NewIndices->reallocate( Indices->size() ); | ||
134 | |||
135 | for(u32 n=0;n<Indices->size();++n) | ||
136 | NewIndices->push_back((*Indices)[n]); | ||
137 | |||
138 | delete Indices; | ||
139 | } | ||
140 | |||
141 | Indices=NewIndices; | ||
142 | } | ||
143 | |||
144 | virtual void* getData() {return Indices->pointer();} | ||
145 | |||
146 | virtual video::E_INDEX_TYPE getType() const {return Indices->getType();} | ||
147 | |||
148 | virtual u32 stride() const {return Indices->stride();} | ||
149 | |||
150 | virtual u32 size() const | ||
151 | { | ||
152 | return Indices->size(); | ||
153 | } | ||
154 | |||
155 | virtual void push_back(const u32 &element) | ||
156 | { | ||
157 | Indices->push_back(element); | ||
158 | } | ||
159 | |||
160 | virtual u32 operator [](u32 index) const | ||
161 | { | ||
162 | return (*Indices)[index]; | ||
163 | } | ||
164 | |||
165 | virtual u32 getLast() | ||
166 | { | ||
167 | return Indices->getLast(); | ||
168 | } | ||
169 | |||
170 | virtual void setValue(u32 index, u32 value) | ||
171 | { | ||
172 | Indices->setValue(index, value); | ||
173 | } | ||
174 | |||
175 | virtual void set_used(u32 usedNow) | ||
176 | { | ||
177 | Indices->set_used(usedNow); | ||
178 | } | ||
179 | |||
180 | virtual void reallocate(u32 new_size) | ||
181 | { | ||
182 | Indices->reallocate(new_size); | ||
183 | } | ||
184 | |||
185 | virtual u32 allocated_size() const | ||
186 | { | ||
187 | return Indices->allocated_size(); | ||
188 | } | ||
189 | |||
190 | virtual void* pointer() | ||
191 | { | ||
192 | return Indices->pointer(); | ||
193 | } | ||
194 | |||
195 | //! get the current hardware mapping hint | ||
196 | virtual E_HARDWARE_MAPPING getHardwareMappingHint() const | ||
197 | { | ||
198 | return MappingHint; | ||
199 | } | ||
200 | |||
201 | //! set the hardware mapping hint, for driver | ||
202 | virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint ) | ||
203 | { | ||
204 | MappingHint=NewMappingHint; | ||
205 | } | ||
206 | |||
207 | //! flags the mesh as changed, reloads hardware buffers | ||
208 | virtual void setDirty() | ||
209 | { | ||
210 | ++ChangedID; | ||
211 | } | ||
212 | |||
213 | //! Get the currently used ID for identification of changes. | ||
214 | /** This shouldn't be used for anything outside the VideoDriver. */ | ||
215 | virtual u32 getChangedID() const {return ChangedID;} | ||
216 | |||
217 | E_HARDWARE_MAPPING MappingHint; | ||
218 | u32 ChangedID; | ||
219 | }; | ||
220 | |||
221 | |||
222 | } // end namespace scene | ||
223 | } // end namespace irr | ||
224 | |||
225 | #endif | ||
226 | |||