SuperTuxKart
Loading...
Searching...
No Matches
CBatchingMesh.hpp
1// A mesh used for batching many other meshes together, to reduce the number
2// of draw calls. Simply add meshes into this one, with given transformations
3// or positions, and then call update
4
5// TODO: Adapt the VBO interface and integrate setDirty with the current VBO updates.
6
7#include "IMesh.h"
8#include "SMeshBuffer.h"
9
10namespace irr
11{
12namespace scene
13{
14
15class CBatchingMesh : public IMesh
16{
17public:
19
20 virtual ~CBatchingMesh();
21
23 bool isDirty(s32 id=-1);
24
26 void update();
27
29 void clear();
30
32
33 void finalize();
34
36
37 core::array<s32> addMesh(IMesh* mesh,
38 core::vector3df pos = core::vector3df(0,0,0),
39 core::vector3df rot = core::vector3df(0,0,0),
40 core::vector3df scale = core::vector3df(1,1,1));
41
43
44 core::array<s32> addMesh(IMesh* mesh, const core::matrix4 &transform);
45
47
48 s32 addMeshBuffer(IMeshBuffer* buffer,
49 core::vector3df pos = core::vector3df(0,0,0),
50 core::vector3df rot = core::vector3df(0,0,0),
51 core::vector3df scale = core::vector3df(1,1,1));
52
54
55 s32 addMeshBuffer(IMeshBuffer* buffer, const core::matrix4 &transform);
56
59
61
63 core::array<bool> moveMesh(const core::array<s32>& bufferIDs, const core::matrix4 &newMatrix);
64
66
68 bool moveMeshBuffer(const s32 id, const core::matrix4 &newMatrix);
69
71 IMeshBuffer* getSourceBuffer(s32 id);
72
74 core::matrix4 getSourceBufferMatrix(s32 id);
75
77 u32 getSourceBufferCount() const;
78
79 /* Standard IMesh functions */
80
82
83 virtual u32 getMeshBufferCount() const;
84
86
90 virtual IMeshBuffer* getMeshBuffer(u32 nr) const;
91
93
96 virtual IMeshBuffer* getMeshBuffer( const video::SMaterial &material) const;
97
99
100 virtual const core::aabbox3d<f32>& getBoundingBox() const;
101
103 virtual void setBoundingBox( const core::aabbox3df& box);
104
106
108 virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue);
109
110 virtual void setHardwareMappingHint(E_HARDWARE_MAPPING mapping, E_BUFFER_TYPE type);
111
112 virtual void setDirty(E_BUFFER_TYPE type);
113
114private:
115
116 // add a buffer to the source buffers array if it doesn't already exist
117 void addSourceBuffer(IMeshBuffer* source);
118
119 // updates the vertices in dest buffer from the source one
120 void updateDestFromSourceBuffer(u32 id);
121
122 // recalculates the bounding box for the given dest buffer
123 void recalculateDestBufferBoundingBox(u32 i);
124
126 {
128 : SourceBuffer(0), DestReference(0), FirstVertex(0), VertexCount(0),
129 FirstIndex(0), IndexCount(0), Initialized(false) { }
130
131 IMeshBuffer* SourceBuffer;
132 u32 DestReference;
133 u32 FirstVertex, VertexCount, FirstIndex, IndexCount;
134 core::matrix4 Transform;
135 bool Initialized;
136 };
137
139 {
140 video::SMaterial Material;
141 video::E_VERTEX_TYPE VertexType;
142 u32 BufferIndex;
143 };
144
146 {
147 IMeshBuffer* Buffer;
148 video::E_VERTEX_TYPE VertexType;
149 u32 VertexCount;
150 u32 IndexCount;
151 bool IsDirty;
152 };
153
155 core::array<IMeshBuffer*> SourceBuffers;
156
157 core::array<SBufferReference> BufferReferences;
158 core::array<SMaterialReference> MaterialReferences;
159 core::array<SDestBufferReference> DestBuffers;
160
162 core::aabbox3d<f32> Box;
163
166
169};
170
171} // namespace scene
172} // namespace irr
173
174// #endif
Definition: material.hpp:48
Definition: CBatchingMesh.hpp:16
void finalize()
first updates the mesh, then drops all source buffers.
Definition: CBatchingMesh.cpp:317
void recalculateBoundingBox()
updates bouding box from internal buffers
Definition: CBatchingMesh.cpp:231
core::array< IMeshBuffer * > SourceBuffers
Source mesh buffers, these are locked.
Definition: CBatchingMesh.hpp:155
core::array< s32 > addMesh(IMesh *mesh, core::vector3df pos=core::vector3df(0, 0, 0), core::vector3df rot=core::vector3df(0, 0, 0), core::vector3df scale=core::vector3df(1, 1, 1))
adds a mesh to the buffers with the given offset
Definition: CBatchingMesh.cpp:100
virtual IMeshBuffer * getMeshBuffer(u32 nr) const
Returns pointer to a mesh buffer.
Definition: CBatchingMesh.cpp:260
bool moveMeshBuffer(const s32 id, const core::matrix4 &newMatrix)
Moves a mesh buffer.
Definition: CBatchingMesh.cpp:342
bool IsFinal
can it be changed?
Definition: CBatchingMesh.hpp:168
s32 addMeshBuffer(IMeshBuffer *buffer, core::vector3df pos=core::vector3df(0, 0, 0), core::vector3df rot=core::vector3df(0, 0, 0), core::vector3df scale=core::vector3df(1, 1, 1))
adds a mesh buffer with the given transformation
Definition: CBatchingMesh.cpp:130
bool IsDirty
does it require an update?
Definition: CBatchingMesh.hpp:165
virtual void setBoundingBox(const core::aabbox3df &box)
set user axis aligned bounding box
Definition: CBatchingMesh.cpp:282
IMeshBuffer * getSourceBuffer(s32 id)
returns the source buffer, if available
Definition: CBatchingMesh.cpp:361
virtual const core::aabbox3d< f32 > & getBoundingBox() const
Returns an axis aligned bounding box of the mesh.
Definition: CBatchingMesh.cpp:276
void update()
refreshes the internal buffers from source
Definition: CBatchingMesh.cpp:34
u32 getSourceBufferCount() const
returns the number of source buffers
Definition: CBatchingMesh.cpp:383
virtual u32 getMeshBufferCount() const
Returns the amount of mesh buffers.
Definition: CBatchingMesh.cpp:250
core::matrix4 getSourceBufferMatrix(s32 id)
returns the matrix of the source buffer
Definition: CBatchingMesh.cpp:370
core::aabbox3d< f32 > Box
bounding containing all destination buffers
Definition: CBatchingMesh.hpp:162
virtual void setMaterialFlag(video::E_MATERIAL_FLAG flag, bool newvalue)
Sets a flag of all contained materials to a new value.
Definition: CBatchingMesh.cpp:290
bool isDirty(s32 id=-1)
returns true if new buffers have been added without updating the internal buffers
Definition: CBatchingMesh.cpp:25
void clear()
drops all buffers and clears internal states
Definition: CBatchingMesh.cpp:297
core::array< bool > moveMesh(const core::array< s32 > &bufferIDs, const core::matrix4 &newMatrix)
Moves a mesh,.
Definition: CBatchingMesh.cpp:330
Definition: CBatchingMesh.hpp:126
Definition: CBatchingMesh.hpp:146
Definition: CBatchingMesh.hpp:139