Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
CIndexBuffer.hpp
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 nirtcpp/nirtcpp.hpp
4
5#ifndef NIRT_C_INDEX_BUFFER_HPP_INCLUDED
6#define NIRT_C_INDEX_BUFFER_HPP_INCLUDED
7
8#include <nirtcpp/core/engine/IIndexBuffer.hpp>
9
10namespace nirt
11{
12namespace scene
13{
14
16 {
17 // Virtual function wrapper around nirt::core::array
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(u32 value) =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, bool canShrink=true) =0;
31 virtual u32 allocated_size() const =0;
32 virtual void* pointer() =0;
33 virtual const void* const_pointer() const =0;
34 virtual video::E_INDEX_TYPE getType() const =0;
35 };
36
37 template <class T>
38 class CSpecificIndexList : public IIndexList
39 {
40 public:
41 core::array<T> Indices;
42
43 virtual u32 stride() const override {return sizeof(T);}
44
45 virtual u32 size() const override {return Indices.size();}
46
47 virtual void push_back(u32 value) override
48 {
49 Indices.push_back((T)value);
50 }
51
52 virtual u32 operator [](u32 index) const override
53 {
54 return (u32)(Indices[index]);
55 }
56
57 virtual u32 getLast() override {return (u32)Indices.getLast();}
58
59 virtual void setValue(u32 index, u32 value) override
60 {
61 Indices[index]=(T)value;
62 }
63
64 virtual void set_used(u32 usedNow) override
65 {
66 Indices.set_used(usedNow);
67 }
68
69 virtual void reallocate(u32 new_size, bool canShrink) override
70 {
71 Indices.reallocate(new_size, canShrink);
72 }
73
74 virtual u32 allocated_size() const override
75 {
76 return Indices.allocated_size();
77 }
78
79 virtual void* pointer() override { return Indices.pointer(); }
80 virtual const void* const_pointer() const override { return Indices.const_pointer(); }
81
82 virtual video::E_INDEX_TYPE getType() const override
83 {
84 if (sizeof(T)==sizeof(u16))
85 return video::EIT_16BIT;
86 else
87 return video::EIT_32BIT;
88 }
89 };
90
91 public:
92 IIndexList *Indices;
93
94 CIndexBuffer(video::E_INDEX_TYPE IndexType) :Indices(0), MappingHint(EHM_NEVER), ChangedID(1)
95 {
96 setType(IndexType);
97 }
98
99 CIndexBuffer(const IIndexBuffer &IndexBufferCopy) :Indices(0), MappingHint(EHM_NEVER), ChangedID(1)
100 {
101 setType(IndexBufferCopy.getType());
102 reallocate(IndexBufferCopy.size());
103
104 for (u32 n=0;n<IndexBufferCopy.size();++n)
105 push_back(IndexBufferCopy[n]);
106 }
107
108 virtual ~CIndexBuffer()
109 {
110 delete Indices;
111 }
112
113 virtual void setType(video::E_INDEX_TYPE indexType) override
114 {
115 if ( Indices && Indices->getType() == indexType )
116 return;
117
118 IIndexList *NewIndices=0;
119
120 switch (indexType)
121 {
122 case video::EIT_16BIT:
123 {
124 NewIndices=new CSpecificIndexList<u16>;
125 break;
126 }
127 case video::EIT_32BIT:
128 {
129 NewIndices=new CSpecificIndexList<u32>;
130 break;
131 }
132 }
133
134 if (Indices)
135 {
136 NewIndices->reallocate( Indices->size() );
137
138 for(u32 n=0;n<Indices->size();++n)
139 NewIndices->push_back((*Indices)[n]);
140
141 delete Indices;
142 }
143
144 Indices=NewIndices;
145 }
146
147 virtual void* getData() override {return Indices->pointer();}
148 virtual const void* getData() const override { return Indices->const_pointer(); }
149
150 virtual video::E_INDEX_TYPE getType() const override {return Indices->getType();}
151
152 virtual u32 stride() const override {return Indices->stride();}
153
154 virtual u32 size() const override
155 {
156 return Indices->size();
157 }
158
159 virtual void push_back(u32 value) override
160 {
161 Indices->push_back(value);
162 }
163
164 virtual u32 operator [](u32 index) const override
165 {
166 return (*Indices)[index];
167 }
168
169 virtual u32 getLast() override
170 {
171 return Indices->getLast();
172 }
173
174 virtual void setValue(u32 index, u32 value) override
175 {
176 Indices->setValue(index, value);
177 }
178
179 virtual void set_used(u32 usedNow) override
180 {
181 Indices->set_used(usedNow);
182 }
183
184 virtual void reallocate(u32 new_size, bool canShrink=true) override
185 {
186 Indices->reallocate(new_size, canShrink);
187 }
188
189 virtual u32 allocated_size() const override
190 {
191 return Indices->allocated_size();
192 }
193
196 {
197 return MappingHint;
198 }
199
201 virtual void setHardwareMappingHint( E_HARDWARE_MAPPING NewMappingHint ) override
202 {
203 MappingHint=NewMappingHint;
204 }
205
207 virtual void setDirty() override
208 {
209 ++ChangedID;
210 }
211
213
214 virtual u32 getChangedID() const override {return ChangedID;}
215
216 E_HARDWARE_MAPPING MappingHint;
217 u32 ChangedID;
218 };
219
220
221} // end namespace scene
222} // end namespace nirt
223
224#endif
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
Definition CIndexBuffer.hpp:16
virtual u32 size() const override
Number of elements.
Definition CIndexBuffer.hpp:154
virtual u32 stride() const override
Number of bytes per element.
Definition CIndexBuffer.hpp:152
virtual const void * getData() const override
Const pointer to first element.
Definition CIndexBuffer.hpp:148
virtual void setHardwareMappingHint(E_HARDWARE_MAPPING NewMappingHint) override
set the hardware mapping hint, for driver
Definition CIndexBuffer.hpp:201
virtual u32 operator[](u32 index) const override
Access element value at given index.
Definition CIndexBuffer.hpp:164
virtual void * getData() override
Pointer to first element.
Definition CIndexBuffer.hpp:147
virtual void push_back(u32 value) override
Add value to end. Note that for 16 bit index types values shouldn't be larger than u16.
Definition CIndexBuffer.hpp:159
virtual void setValue(u32 index, u32 value) override
Set value at index. Note that for 16 bit index types values shouldn't be larger than u16.
Definition CIndexBuffer.hpp:174
virtual E_HARDWARE_MAPPING getHardwareMappingHint() const override
get the current hardware mapping hint
Definition CIndexBuffer.hpp:195
virtual void setType(video::E_INDEX_TYPE indexType) override
Change between 16 and 32 bit indices.
Definition CIndexBuffer.hpp:113
virtual void setDirty() override
flags the mesh as changed, reloads hardware buffers
Definition CIndexBuffer.hpp:207
virtual u32 getChangedID() const override
Get the currently used ID for identification of changes.
Definition CIndexBuffer.hpp:214
Definition IIndexBuffer.hpp:20
virtual u32 size() const =0
Number of elements.
E_HARDWARE_MAPPING
Definition EHardwareBufferFlags.hpp:14
@ EHM_NEVER
Don't store on the hardware.
Definition EHardwareBufferFlags.hpp:16
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
unsigned short u16
16 bit unsigned variable.
Definition irrTypes.hpp:46
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64

Nirtcpp    @cppfx.xyz

Esvcpp    esv::print