Started moving compression code into separate class.

This commit is contained in:
David Williams 2013-07-26 16:00:29 +02:00
parent c3c4ead1f3
commit f54532a905
7 changed files with 134 additions and 2 deletions

View File

@ -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

View File

@ -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;

View File

@ -115,6 +115,18 @@ namespace PolyVox
m_tData = 0;
}
template <typename VoxelType>
VoxelType* UncompressedBlock<VoxelType>::getData(void) const
{
return m_tData;
}
template <typename VoxelType>
uint32_t UncompressedBlock<VoxelType>::getDataSizeInBytes(void) const
{
return m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType);
}
template <typename VoxelType>
VoxelType UncompressedBlock<VoxelType>::getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const
{

View File

@ -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<VoxelType>* m_pBlockCompressor;
Pager<VoxelType>* m_pPager;
// Compressed data for an empty block (sometimes needed for initialisation).

View File

@ -559,6 +559,8 @@ namespace PolyVox
delete[] pZeros;
delete[] pCompressedZeros;
m_pBlockCompressor = new MinizBlockCompressor<VoxelType>;
}
template <typename VoxelType>
@ -795,7 +797,7 @@ namespace PolyVox
// FIXME - multiple getCompressedBlock() calls (including the one above)
CompressedBlock<VoxelType>* pBlock = getCompressedBlock(uBlockX, uBlockY, uBlockZ);
const void* pSrcData = reinterpret_cast<const void*>(pBlock->getData());
/*const void* pSrcData = reinterpret_cast<const void*>(pBlock->getData());
void* pDstData = reinterpret_cast<void*>(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<VoxelType, uint16_t> 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.

View File

@ -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 <typename VoxelType>
class MinizBlockCompressor
{
public:
MinizBlockCompressor();
~MinizBlockCompressor();
void compress(UncompressedBlock<VoxelType>* pSrcBlock, CompressedBlock<VoxelType>* pDstBlock);
void decompress(CompressedBlock<VoxelType>* pSrcBlock, UncompressedBlock<VoxelType>* pDstBlock);
MinizCompressor* m_pCompressor;
};
}
#include "PolyVoxCore/MinizBlockCompressor.inl"
#endif //__PolyVox_MinizBlockCompressor_H__

View File

@ -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 <typename VoxelType>
MinizBlockCompressor<VoxelType>::MinizBlockCompressor()
{
m_pCompressor = new MinizCompressor;
}
template <typename VoxelType>
MinizBlockCompressor<VoxelType>::~MinizBlockCompressor()
{
delete m_pCompressor;
}
template <typename VoxelType>
void MinizBlockCompressor<VoxelType>::compress(UncompressedBlock<VoxelType>* pSrcBlock, CompressedBlock<VoxelType>* pDstBlock)
{
}
template <typename VoxelType>
void MinizBlockCompressor<VoxelType>::decompress(CompressedBlock<VoxelType>* pSrcBlock, UncompressedBlock<VoxelType>* pDstBlock)
{
const void* pSrcData = reinterpret_cast<const void*>(pSrcBlock->getData());
void* pDstData = reinterpret_cast<void*>(pDstBlock->getData());
uint32_t uSrcLength = pSrcBlock->getDataSizeInBytes();
uint32_t uDstLength = pDstBlock->getDataSizeInBytes();
//RLECompressor<VoxelType, uint16_t> compressor;
uint32_t uUncompressedLength = m_pCompressor->decompress(pSrcData, uSrcLength, pDstData, uDstLength);
POLYVOX_ASSERT(uUncompressedLength == pDstBlock->getDataSizeInBytes(), "Destination length has changed.");
}
}