Bit more tidying of Miniz code.
This commit is contained in:
parent
ef615cc838
commit
d17c1b404b
@ -59,21 +59,28 @@ namespace PolyVox
|
|||||||
template <typename VoxelType>
|
template <typename VoxelType>
|
||||||
void MinizBlockCompressor<VoxelType>::compress(UncompressedBlock<VoxelType>* pSrcBlock, CompressedBlock<VoxelType>* pDstBlock)
|
void MinizBlockCompressor<VoxelType>::compress(UncompressedBlock<VoxelType>* pSrcBlock, CompressedBlock<VoxelType>* pDstBlock)
|
||||||
{
|
{
|
||||||
|
// The uncompressed data will be read straight out of the block
|
||||||
void* pSrcData = reinterpret_cast<void*>(pSrcBlock->getData());
|
void* pSrcData = reinterpret_cast<void*>(pSrcBlock->getData());
|
||||||
size_t uSrcLength = pSrcBlock->getDataSizeInBytes();
|
size_t uSrcLength = pSrcBlock->getDataSizeInBytes();
|
||||||
|
|
||||||
// This compressor is expected to be used many times to compress a large number of blocks, but they are all
|
// This compressor is expected to be used many times to compress a large number of blocks, but they are all
|
||||||
// expected to have the same size. Therefore the resize() function below will only perform allocation once.
|
// expected to have the same size. Therefore the resize() function below should only perform allocation once.
|
||||||
m_vecTempBuffer.resize(getExpectedCompressedSize(uSrcLength));
|
uint32_t expectedCompressedSize = getExpectedCompressedSize(uSrcLength);
|
||||||
|
if(m_vecTempBuffer.size() != expectedCompressedSize)
|
||||||
|
{
|
||||||
|
logInfo() << "Resizing temp buffer to " << expectedCompressedSize << "bytes. "
|
||||||
|
<< "This should only happen the first time the MinizBlockCompressor is used";
|
||||||
|
m_vecTempBuffer.resize(expectedCompressedSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
// The compressed data will be written into this temporary buffer.
|
||||||
uint8_t* pDstData = &(m_vecTempBuffer[0]);
|
uint8_t* pDstData = &(m_vecTempBuffer[0]);
|
||||||
size_t uDstLength = m_vecTempBuffer.size();
|
size_t uDstLength = m_vecTempBuffer.size();
|
||||||
|
|
||||||
uint32_t uCompressedLength = 0;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Perform the compression
|
// Perform the compression
|
||||||
uCompressedLength = compressWithMiniz(pSrcData, uSrcLength, pDstData, uDstLength);
|
uint32_t uCompressedLength = compressWithMiniz(pSrcData, uSrcLength, pDstData, uDstLength);
|
||||||
|
|
||||||
// Copy the resulting compressed data into the compressed block
|
// Copy the resulting compressed data into the compressed block
|
||||||
pDstBlock->setData(pDstData, uCompressedLength);
|
pDstBlock->setData(pDstData, uCompressedLength);
|
||||||
@ -95,7 +102,7 @@ namespace PolyVox
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Perform the compression
|
// Perform the compression
|
||||||
uCompressedLength = compressWithMiniz(pSrcData, uSrcLength, pDstData, uDstLength);
|
uint32_t uCompressedLength = compressWithMiniz(pSrcData, uSrcLength, pDstData, uDstLength);
|
||||||
|
|
||||||
// Copy the resulting compressed data into the compressed block
|
// Copy the resulting compressed data into the compressed block
|
||||||
pDstBlock->setData(pDstData, uCompressedLength);
|
pDstBlock->setData(pDstData, uCompressedLength);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user