From 2458f94feb9c216f0f63f81e7cca98d8c214e14d Mon Sep 17 00:00:00 2001 From: Daviw Williams Date: Tue, 25 Feb 2014 16:51:26 +0100 Subject: [PATCH] Eliminating some differences from the cubiquity-version branch. --- .../PolyVoxCore/include/PolyVoxCore/Impl/Utility.h | 1 + .../PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl | 2 +- library/PolyVoxCore/include/PolyVoxCore/Vector.inl | 5 ++++- library/PolyVoxCore/source/Impl/Utility.cpp | 13 +++++++++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Utility.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Utility.h index 71dc7b83..0ae8353e 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Utility.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Utility.h @@ -37,6 +37,7 @@ namespace PolyVox int32_t roundToInteger(float r); template Type clamp(const Type& value, const Type& low, const Type& high); + uint32_t upperPowerOfTwo(uint32_t v); inline int32_t roundTowardsNegInf(float r) { diff --git a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl b/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl index d9355466..9b1bf020 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/SurfaceMesh.inl @@ -365,7 +365,7 @@ namespace PolyVox void SurfaceMesh::removeUnusedVertices(void) { std::vector isVertexUsed(m_vecVertices.size()); - fill(isVertexUsed.begin(), isVertexUsed.end(), false); + std::fill(isVertexUsed.begin(), isVertexUsed.end(), false); for(uint32_t triCt = 0; triCt < m_vecTriangleIndices.size(); triCt++) { diff --git a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl index 6dc04e90..e741b066 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Vector.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Vector.inl @@ -653,7 +653,10 @@ namespace PolyVox inline void Vector::normalise(void) { float fLength = this->length(); - if(fLength <= 0.0) + + // We could wait until the NAN occurs before throwing, but then we'd have to add some roll-back code. + // This seems like a lot of overhead for a common operation which should rarely go wrong. + if(fLength <= 0.0001) { POLYVOX_THROW(invalid_operation, "Cannot normalise a vector with a length of zero"); } diff --git a/library/PolyVoxCore/source/Impl/Utility.cpp b/library/PolyVoxCore/source/Impl/Utility.cpp index a035b115..83be3b0a 100644 --- a/library/PolyVoxCore/source/Impl/Utility.cpp +++ b/library/PolyVoxCore/source/Impl/Utility.cpp @@ -56,4 +56,17 @@ namespace PolyVox else return ((uInput & (uInput-1)) == 0); } + + // http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2 + uint32_t upperPowerOfTwo(uint32_t v) + { + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v++; + return v; + } }