Work on block compression.

This commit is contained in:
Daviw Williams 2013-01-10 16:37:02 +01:00
parent c7937b176d
commit 7bb7be0dec
2 changed files with 6 additions and 25 deletions

View File

@ -56,7 +56,6 @@ namespace PolyVox
void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue); void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue);
void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue); void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue);
void fill(VoxelType tValue);
void initialise(uint16_t uSideLength); void initialise(uint16_t uSideLength);
uint32_t calculateSizeInBytes(void); uint32_t calculateSizeInBytes(void);

View File

@ -105,29 +105,6 @@ namespace PolyVox
setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue); setVoxelAt(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ(), tValue);
} }
template <typename VoxelType>
void Block<VoxelType>::fill(VoxelType tValue)
{
if(!m_bIsCompressed)
{
//The memset *may* be faster than the std::fill(), but it doesn't compile nicely
//in 64-bit mode as casting the pointer to an int causes a loss of precision.
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, tValue);
m_bIsUncompressedDataModified = true;
}
else
{
POLYVOX_ASSERT(false, "Not implemented");
RunlengthEntry<uint16_t> rle;
rle.length = m_uSideLength*m_uSideLength*m_uSideLength;
rle.value = tValue;
m_vecCompressedData.clear();
m_vecCompressedData.push_back(rle);
}
}
template <typename VoxelType> template <typename VoxelType>
void Block<VoxelType>::initialise(uint16_t uSideLength) void Block<VoxelType>::initialise(uint16_t uSideLength)
{ {
@ -144,10 +121,15 @@ namespace PolyVox
m_uSideLength = uSideLength; m_uSideLength = uSideLength;
m_uSideLengthPower = logBase2(uSideLength); m_uSideLengthPower = logBase2(uSideLength);
//Create the block data
m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength]; m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
Block<VoxelType>::fill(VoxelType()); //Clear it (should we bother?)
const uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength;
std::fill(m_tUncompressedData, m_tUncompressedData + uNoOfVoxels, VoxelType());
m_bIsUncompressedDataModified = true;
//For some reason blocks start out compressed. We should probably change this.
compress(); compress();
} }