Skip to content

Commit

Permalink
bugfix : weldVert and array_push (bkaradzic#2769)
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwu authored and Michael Pekar committed Mar 2, 2024
1 parent fa64f5c commit d56b608
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
25 changes: 18 additions & 7 deletions examples/42-bunnylod/bunnylod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,29 @@ class ExampleBunnyLOD : public entry::AppI
}
}

static void mergeIndices(uint32_t* _indices, uint32_t _num)
{
uint32_t target = 0;
for (uint32_t i = 0; i < _num; i++) {
uint32_t map = _indices[i];
while (_indices[map] != map)
map = _indices[map];
if (i != map) {
_indices[i] = map;
} else {
_indices[i] = target;
++target;
}
}
}

static const bgfx::Memory* mergeVertices(const uint8_t* _vb, uint16_t _stride, const uint32_t* _indices, uint32_t _num, uint32_t _numMerged)
{
const bgfx::Memory* mem = bgfx::alloc(_stride * _numMerged);

uint32_t target = 0;

for (uint32_t ii = 0; ii < _num; ++ii)
{
if (_indices[ii] == target)
{
bx::memCopy(mem->data + target*_stride, _vb + ii*_stride, _stride);
++target;
}
bx::memCopy(mem->data + _indices[ii]*_stride, _vb + ii*_stride, _stride);
}

return mem;
Expand Down Expand Up @@ -143,6 +153,7 @@ class ExampleBunnyLOD : public entry::AppI
m_cacheWeld = (uint32_t*)BX_ALLOC(entry::getAllocator(), numVertices * sizeof(uint32_t) );

m_totalVertices = bgfx::weldVertices(m_cacheWeld, _mesh->m_layout, vbData, numVertices, true, 0.00001f);
mergeIndices(m_cacheWeld, numVertices);
}

const bgfx::Memory* vb = mergeVertices(
Expand Down
3 changes: 2 additions & 1 deletion examples/42-bunnylod/progmesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ static void
array_push(struct array *a, int v) {
if (a->n >= a->cap) {
int *old = a->buffer;
a->buffer = (int *)malloc(a->cap * 2 * sizeof(int));
a->cap *= 2;
a->buffer = (int *)malloc(a->cap * sizeof(int));
int i;
for (i=0;i<a->n;i++) {
a->buffer[i] = old[i];
Expand Down

0 comments on commit d56b608

Please sign in to comment.