Skylicht Engine
Toggle main menu visibility
Loading...
Searching...
No Matches
Irrlicht
Include
CVertexBuffer.h
1
// Copyright (C) 2012 Patryk Nadrowski
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_VERTEX_BUFFER_H_INCLUDED__
6
#define __C_VERTEX_BUFFER_H_INCLUDED__
7
8
#include "S3DVertex.h"
9
#include "IVertexBuffer.h"
10
11
namespace
irr
12
{
13
namespace
scene
14
{
15
template
<
class
T>
16
class
CVertexBuffer :
public
IVertexBuffer
17
{
18
public
:
19
CVertexBuffer() : HardwareMappingHint(
EHM_NEVER
), ChangedID(1)
20
{
21
#ifdef _DEBUG
22
setDebugName
(
"CVertexBuffer"
);
23
#endif
24
}
25
26
CVertexBuffer(
const
CVertexBuffer& vertexBuffer) : HardwareMappingHint(
EHM_NEVER
), ChangedID(1)
27
{
28
HardwareMappingHint = vertexBuffer.HardwareMappingHint;
29
30
const
u32
vbCount = vertexBuffer.Vertices.size();
31
32
Vertices.reallocate(vbCount);
33
34
for
(
u32
i = 0; i < vbCount; ++i)
35
Vertices.push_back(vertexBuffer.getVertex(i));
36
}
37
38
virtual
~CVertexBuffer()
39
{
40
Vertices.clear();
41
}
42
43
virtual
void
clear()
44
{
45
Vertices.clear();
46
}
47
48
virtual
T& getLast()
49
{
50
return
Vertices.getLast();
51
}
52
53
virtual
void
set_used(
u32
used)
54
{
55
Vertices.set_used(used);
56
}
57
58
virtual
void
reallocate(
u32
size)
59
{
60
Vertices.reallocate(size);
61
}
62
63
virtual
u32
allocated_size()
const
64
{
65
return
Vertices.allocated_size();
66
}
67
68
virtual
s32
linear_reverse_search(
const
T& element)
const
69
{
70
return
Vertices.linear_reverse_search(element);
71
}
72
73
virtual
s32
linear_reverse_search(
const
void
* element)
const
74
{
75
T* Element = (T*)element;
76
return
Vertices.linear_reverse_search(*Element);
77
}
78
79
virtual
void
fill(
u32
used)
80
{
81
Vertices.reallocate(used);
82
83
while
(Vertices.size() < used)
84
{
85
T element;
86
Vertices.push_back(element);
87
}
88
}
89
90
virtual
E_HARDWARE_MAPPING
getHardwareMappingHint()
const
91
{
92
return
HardwareMappingHint;
93
}
94
95
virtual
void
setHardwareMappingHint(
E_HARDWARE_MAPPING
hardwareMappingHint)
96
{
97
if
(HardwareMappingHint != hardwareMappingHint)
98
setDirty();
99
100
HardwareMappingHint = hardwareMappingHint;
101
}
102
103
virtual
void
addVertex(
const
T& vertex)
104
{
105
Vertices.push_back(vertex);
106
}
107
108
virtual
void
addVertex(
const
void
* vertex)
109
{
110
T* vtx = (T*)vertex;
111
Vertices.push_back(*vtx);
112
}
113
114
virtual
const
void
* getVertex(
u32
id
)
const
115
{
116
return
&Vertices[id];
117
}
118
119
virtual
T& getVertex(
u32
id
)
120
{
121
return
Vertices[id];
122
}
123
124
virtual
void
* getVertices()
125
{
126
return
Vertices.pointer();
127
}
128
129
virtual
u32
getVertexCount()
const
130
{
131
return
Vertices.size();
132
}
133
134
virtual
u32
getVertexSize()
const
135
{
136
return
sizeof
(T);
137
}
138
139
virtual
void
setVertex(
u32
id
,
const
void
* vertex)
140
{
141
if
(
id
< Vertices.size())
142
{
143
T* vtx = (T*)vertex;
144
Vertices[id] = *vtx;
145
}
146
}
147
148
virtual
void
setDirty()
149
{
150
if
(HardwareBuffer)
151
HardwareBuffer->requestUpdate();
152
153
++ChangedID;
154
}
155
156
virtual
u32
getChangedID()
const
157
{
158
return
ChangedID;
159
}
160
161
protected
:
162
E_HARDWARE_MAPPING
HardwareMappingHint;
163
164
u32
ChangedID;
165
166
core::array<T>
Vertices;
167
};
168
169
typedef
CVertexBuffer<video::S3DVertex>
SVertexBuffer;
170
typedef
CVertexBuffer<video::S3DVertex2TCoords>
SVertexBufferLightMap;
171
typedef
CVertexBuffer<video::S3DVertexTangents>
SVertexBufferTangents;
172
}
173
}
174
175
#endif
irr::IReferenceCounted::setDebugName
void setDebugName(const c8 *newName)
Sets the debug name of the object.
Definition
IReferenceCounted.h:163
irr::core::array
Self reallocating template array (like stl vector) with additional features.
Definition
irrArray.h:23
irr::scene::CVertexBuffer
Definition
CVertexBuffer.h:17
irr::scene
All scene management can be found in this namespace: Mesh loading, special scene nodes like octrees a...
Definition
CIndexBuffer.h:13
irr::scene::E_HARDWARE_MAPPING
E_HARDWARE_MAPPING
Definition
EHardwareBufferFlags.h:14
irr::scene::EHM_NEVER
@ EHM_NEVER
Don't store on the hardware.
Definition
EHardwareBufferFlags.h:16
irr
Everything in the Irrlicht Engine can be found in this namespace.
Definition
Skylicht.h:33
irr::u32
unsigned int u32
32 bit unsigned variable.
Definition
irrTypes.h:58
irr::s32
signed int s32
32 bit signed variable.
Definition
irrTypes.h:66
Generated by
1.17.0