Skip to content

Commit 24c6797

Browse files
committed
Skinning: Reduce unnecessary vertex buffer reuploads
1 parent 24673c8 commit 24c6797

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

irr/src/WeightBuffer.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// For conditions of distribution and use, see copyright notice in irrlicht.h
33

44
#include "WeightBuffer.h"
5+
#include "vector3d.h"
56

67
#include <algorithm>
78
#include <numeric>
@@ -61,16 +62,23 @@ void WeightBuffer::skin(IVertexBuffer *dst,
6162
const std::vector<core::matrix4> &joint_transforms) const
6263
{
6364
assert(animated_vertices.has_value());
65+
bool dirty = false;
6466
for (u32 i = 0; i < animated_vertices->size(); ++i) {
65-
6667
u32 vertex_id = (*animated_vertices)[i];
6768
auto pos = static_positions[i];
6869
auto normal = static_normals[i];
6970
skinVertex(vertex_id, pos, normal, joint_transforms);
70-
dst->getPosition(vertex_id) = pos;
71-
dst->getNormal(vertex_id) = normal;
71+
auto update = [&dirty](core::vector3df &dst, core::vector3df src) {
72+
if (dst != src) {
73+
dst = src;
74+
// Only mark as dirty if actually changed: Reupload may be expensive.
75+
dirty = true;
76+
}
77+
};
78+
update(dst->getPosition(vertex_id), pos);
79+
update(dst->getNormal(vertex_id), normal);
7280
}
73-
if (!animated_vertices->empty())
81+
if (dirty)
7482
dst->setDirty();
7583
}
7684

0 commit comments

Comments
 (0)