diff --git a/library/PolyVoxCore/CMakeLists.txt b/library/PolyVoxCore/CMakeLists.txt index a8ce8a0c..f79df326 100644 --- a/library/PolyVoxCore/CMakeLists.txt +++ b/library/PolyVoxCore/CMakeLists.txt @@ -71,6 +71,8 @@ SET(CORE_INC_FILES include/PolyVoxCore/MarchingCubesSurfaceExtractor.inl include/PolyVoxCore/Material.h include/PolyVoxCore/MaterialDensityPair.h + include/PolyVoxCore/MinizBlockCompressor.h + include/PolyVoxCore/MinizBlockCompressor.inl include/PolyVoxCore/MinizCompressor.h include/PolyVoxCore/Pager.h include/PolyVoxCore/PolyVoxForwardDeclarations.h diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index aeb309cc..554bc3c2 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -100,6 +100,9 @@ namespace PolyVox UncompressedBlock(uint16_t uSideLength); ~UncompressedBlock(); + VoxelType* getData(void) const; + uint32_t getDataSizeInBytes(void) const; + VoxelType getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const; VoxelType getVoxel(const Vector3DUint16& v3dPos) const; diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index 16927b4e..ba156ef4 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -115,6 +115,18 @@ namespace PolyVox m_tData = 0; } + template + VoxelType* UncompressedBlock::getData(void) const + { + return m_tData; + } + + template + uint32_t UncompressedBlock::getDataSizeInBytes(void) const + { + return m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType); + } + template VoxelType UncompressedBlock::getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const { diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index 9f409571..e5095c3f 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h @@ -27,6 +27,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/BaseVolume.h" #include "Impl/Block.h" #include "PolyVoxCore/Compressor.h" +#include "PolyVoxCore/MinizBlockCompressor.h" //Shouldn't include the implementation here. #include "PolyVoxCore/Pager.h" #include "PolyVoxCore/Region.h" #include "PolyVoxCore/Vector.h" @@ -357,6 +358,7 @@ namespace PolyVox // The compressor used by the Blocks to compress their data if required. Compressor* m_pCompressor; + MinizBlockCompressor* m_pBlockCompressor; Pager* m_pPager; // Compressed data for an empty block (sometimes needed for initialisation). diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index e40d3c8a..c6cb68c3 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -559,6 +559,8 @@ namespace PolyVox delete[] pZeros; delete[] pCompressedZeros; + + m_pBlockCompressor = new MinizBlockCompressor; } template @@ -795,7 +797,7 @@ namespace PolyVox // FIXME - multiple getCompressedBlock() calls (including the one above) CompressedBlock* pBlock = getCompressedBlock(uBlockX, uBlockY, uBlockZ); - const void* pSrcData = reinterpret_cast(pBlock->getData()); + /*const void* pSrcData = reinterpret_cast(pBlock->getData()); void* pDstData = reinterpret_cast(pUncompressedBlock->m_tData); uint32_t uSrcLength = pBlock->getDataSizeInBytes(); uint32_t uDstLength = m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType); @@ -804,7 +806,9 @@ namespace PolyVox //RLECompressor compressor; uint32_t uUncompressedLength = m_pCompressor->decompress(pSrcData, uSrcLength, pDstData, uDstLength); - POLYVOX_ASSERT(uUncompressedLength == m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType), "Destination length has changed."); + POLYVOX_ASSERT(uUncompressedLength == m_uBlockSideLength * m_uBlockSideLength * m_uBlockSideLength * sizeof(VoxelType), "Destination length has changed.");*/ + + m_pBlockCompressor->decompress(pBlock, pUncompressedBlock); } // Add our new block to the map. diff --git a/library/PolyVoxCore/include/PolyVoxCore/MinizBlockCompressor.h b/library/PolyVoxCore/include/PolyVoxCore/MinizBlockCompressor.h new file mode 100644 index 00000000..b6053fbc --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/MinizBlockCompressor.h @@ -0,0 +1,52 @@ +/******************************************************************************* +Copyright (c) 2005-2013 David Williams and Matthew Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#ifndef __PolyVox_MinizBlockCompressor_H__ +#define __PolyVox_MinizBlockCompressor_H__ + +#include "PolyVoxCore/Impl/Block.h" + +#include "PolyVoxCore/MinizCompressor.h" + +namespace PolyVox +{ + /** + * Provides an interface for performing paging of data. + */ + template + class MinizBlockCompressor + { + public: + MinizBlockCompressor(); + ~MinizBlockCompressor(); + + void compress(UncompressedBlock* pSrcBlock, CompressedBlock* pDstBlock); + void decompress(CompressedBlock* pSrcBlock, UncompressedBlock* pDstBlock); + + MinizCompressor* m_pCompressor; + }; +} + +#include "PolyVoxCore/MinizBlockCompressor.inl" + +#endif //__PolyVox_MinizBlockCompressor_H__ diff --git a/library/PolyVoxCore/include/PolyVoxCore/MinizBlockCompressor.inl b/library/PolyVoxCore/include/PolyVoxCore/MinizBlockCompressor.inl new file mode 100644 index 00000000..69f6b2e9 --- /dev/null +++ b/library/PolyVoxCore/include/PolyVoxCore/MinizBlockCompressor.inl @@ -0,0 +1,57 @@ +/******************************************************************************* +Copyright (c) 2005-2013 David Williams and Matthew Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +namespace PolyVox +{ + template + MinizBlockCompressor::MinizBlockCompressor() + { + m_pCompressor = new MinizCompressor; + } + + template + MinizBlockCompressor::~MinizBlockCompressor() + { + delete m_pCompressor; + } + + template + void MinizBlockCompressor::compress(UncompressedBlock* pSrcBlock, CompressedBlock* pDstBlock) + { + } + + template + void MinizBlockCompressor::decompress(CompressedBlock* pSrcBlock, UncompressedBlock* pDstBlock) + { + const void* pSrcData = reinterpret_cast(pSrcBlock->getData()); + void* pDstData = reinterpret_cast(pDstBlock->getData()); + uint32_t uSrcLength = pSrcBlock->getDataSizeInBytes(); + uint32_t uDstLength = pDstBlock->getDataSizeInBytes(); + + + //RLECompressor compressor; + uint32_t uUncompressedLength = m_pCompressor->decompress(pSrcData, uSrcLength, pDstData, uDstLength); + + POLYVOX_ASSERT(uUncompressedLength == pDstBlock->getDataSizeInBytes(), "Destination length has changed."); + } +} \ No newline at end of file