More work on block compression with miniz.

This commit is contained in:
Daviw Williams 2013-01-11 13:29:33 +01:00
parent 7bb7be0dec
commit 68ee094cec
3 changed files with 19 additions and 11 deletions

View File

@ -210,13 +210,21 @@ namespace PolyVox
pUncompressedData += m_vecCompressedData[ct].length;
}*/
m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength];
Data src;
src.ptr = m_pCompressedData;
src.length = m_uCompressedDataLength;
Data uncompressedResult = polyvox_decompress(src);
Data dst;
dst.ptr = reinterpret_cast<uint8_t*>(m_tUncompressedData);
dst.length = m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType);
m_tUncompressedData = reinterpret_cast<VoxelType*>(uncompressedResult.ptr);
polyvox_decompress(src, dst);
POLYVOX_ASSERT(dst.length == m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType), "Destination length has changed.");
//m_tUncompressedData = reinterpret_cast<VoxelType*>(uncompressedResult.ptr);
m_bIsCompressed = false;
m_bIsUncompressedDataModified = false;

View File

@ -33,6 +33,6 @@ struct Data
};
Data polyvox_compress(Data src);
Data polyvox_decompress(Data src);
void polyvox_decompress(Data src, Data dst);
#endif //__PolyVox_Compression_H__

View File

@ -37,27 +37,27 @@ Data polyvox_compress(Data src)
return dst;
}
Data polyvox_decompress(Data src)
void polyvox_decompress(Data src, Data dst)
{
unsigned char* buffer;
/*unsigned char* buffer;
mz_ulong uncompressedDataLength = 1000000;
buffer = new unsigned char[uncompressedDataLength];
buffer = new unsigned char[uncompressedDataLength];*/
int iUncompressionResult = uncompress(buffer, &uncompressedDataLength, src.ptr, src.length);
int iUncompressionResult = uncompress(dst.ptr, &dst.length, src.ptr, src.length);
if (iUncompressionResult != Z_OK)
{
delete[] buffer;
//delete[] buffer;
POLYVOX_THROW(std::runtime_error, "Data decompression failed.");
}
Data dst;
/*Data dst;
dst.length = uncompressedDataLength;
dst.ptr = new uint8_t[dst.length];
memcpy(dst.ptr, buffer, uncompressedDataLength);
delete[] buffer;
delete[] buffer;*/
return dst;
//return dst;
}