Updated meshoptimizer.
This commit is contained in:
parent
f07a164880
commit
9640d461ac
12
3rdparty/meshoptimizer/src/quantization.cpp
vendored
12
3rdparty/meshoptimizer/src/quantization.cpp
vendored
@ -3,9 +3,15 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
union FloatBits
|
||||||
|
{
|
||||||
|
float f;
|
||||||
|
unsigned int ui;
|
||||||
|
};
|
||||||
|
|
||||||
unsigned short meshopt_quantizeHalf(float v)
|
unsigned short meshopt_quantizeHalf(float v)
|
||||||
{
|
{
|
||||||
union { float f; unsigned int ui; } u = {v};
|
FloatBits u = {v};
|
||||||
unsigned int ui = u.ui;
|
unsigned int ui = u.ui;
|
||||||
|
|
||||||
int s = (ui >> 16) & 0x8000;
|
int s = (ui >> 16) & 0x8000;
|
||||||
@ -30,7 +36,7 @@ float meshopt_quantizeFloat(float v, int N)
|
|||||||
{
|
{
|
||||||
assert(N >= 0 && N <= 23);
|
assert(N >= 0 && N <= 23);
|
||||||
|
|
||||||
union { float f; unsigned int ui; } u = {v};
|
FloatBits u = {v};
|
||||||
unsigned int ui = u.ui;
|
unsigned int ui = u.ui;
|
||||||
|
|
||||||
const int mask = (1 << (23 - N)) - 1;
|
const int mask = (1 << (23 - N)) - 1;
|
||||||
@ -64,7 +70,7 @@ float meshopt_dequantizeHalf(unsigned short h)
|
|||||||
// 112 is an exponent bias fixup; since we already applied it once, applying it twice converts 31 to 255
|
// 112 is an exponent bias fixup; since we already applied it once, applying it twice converts 31 to 255
|
||||||
r += (em >= (31 << 10)) ? (112 << 23) : 0;
|
r += (em >= (31 << 10)) ? (112 << 23) : 0;
|
||||||
|
|
||||||
union { float f; unsigned int ui; } u;
|
FloatBits u;
|
||||||
u.ui = s | r;
|
u.ui = s | r;
|
||||||
return u.f;
|
return u.f;
|
||||||
}
|
}
|
||||||
|
13
3rdparty/meshoptimizer/src/vcacheoptimizer.cpp
vendored
13
3rdparty/meshoptimizer/src/vcacheoptimizer.cpp
vendored
@ -195,9 +195,8 @@ void meshopt_optimizeVertexCacheTable(unsigned int* destination, const unsigned
|
|||||||
TriangleAdjacency adjacency = {};
|
TriangleAdjacency adjacency = {};
|
||||||
buildTriangleAdjacency(adjacency, indices, index_count, vertex_count, allocator);
|
buildTriangleAdjacency(adjacency, indices, index_count, vertex_count, allocator);
|
||||||
|
|
||||||
// live triangle counts
|
// live triangle counts; note, we alias adjacency.counts as we remove triangles after emitting them so the counts always match
|
||||||
unsigned int* live_triangles = allocator.allocate<unsigned int>(vertex_count);
|
unsigned int* live_triangles = adjacency.counts;
|
||||||
memcpy(live_triangles, adjacency.counts, vertex_count * sizeof(unsigned int));
|
|
||||||
|
|
||||||
// emitted flags
|
// emitted flags
|
||||||
unsigned char* emitted_flags = allocator.allocate<unsigned char>(face_count);
|
unsigned char* emitted_flags = allocator.allocate<unsigned char>(face_count);
|
||||||
@ -261,20 +260,16 @@ void meshopt_optimizeVertexCacheTable(unsigned int* destination, const unsigned
|
|||||||
unsigned int index = cache[i];
|
unsigned int index = cache[i];
|
||||||
|
|
||||||
cache_new[cache_write] = index;
|
cache_new[cache_write] = index;
|
||||||
cache_write += (index != a && index != b && index != c);
|
cache_write += (index != a) & (index != b) & (index != c);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int* cache_temp = cache;
|
unsigned int* cache_temp = cache;
|
||||||
cache = cache_new, cache_new = cache_temp;
|
cache = cache_new, cache_new = cache_temp;
|
||||||
cache_count = cache_write > cache_size ? cache_size : cache_write;
|
cache_count = cache_write > cache_size ? cache_size : cache_write;
|
||||||
|
|
||||||
// update live triangle counts
|
|
||||||
live_triangles[a]--;
|
|
||||||
live_triangles[b]--;
|
|
||||||
live_triangles[c]--;
|
|
||||||
|
|
||||||
// remove emitted triangle from adjacency data
|
// remove emitted triangle from adjacency data
|
||||||
// this makes sure that we spend less time traversing these lists on subsequent iterations
|
// this makes sure that we spend less time traversing these lists on subsequent iterations
|
||||||
|
// live triangle counts are updated as a byproduct of these adjustments
|
||||||
for (size_t k = 0; k < 3; ++k)
|
for (size_t k = 0; k < 3; ++k)
|
||||||
{
|
{
|
||||||
unsigned int index = indices[current_triangle * 3 + k];
|
unsigned int index = indices[current_triangle * 3 + k];
|
||||||
|
Loading…
Reference in New Issue
Block a user