Work on compression interface.

This commit is contained in:
Daviw Williams 2013-01-31 15:54:04 +01:00
parent 924744c5e6
commit 36676433be
10 changed files with 196 additions and 132 deletions

View File

@ -49,6 +49,7 @@ SET(CORE_INC_FILES
include/PolyVoxCore/BaseVolume.h
include/PolyVoxCore/BaseVolume.inl
include/PolyVoxCore/BaseVolumeSampler.inl
include/PolyVoxCore/Compressor.h
include/PolyVoxCore/ConstVolumeProxy.h
include/PolyVoxCore/CubicSurfaceExtractor.h
include/PolyVoxCore/CubicSurfaceExtractor.inl

View File

@ -0,0 +1,42 @@
/*******************************************************************************
Copyright (c) 2005-2009 David 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_Compressor_H__
#define __PolyVox_Compressor_H__
#include "PolyVoxCore/Impl/TypeDef.h"
namespace PolyVox
{
class Compressor
{
public:
Compressor() {};
virtual ~Compressor() {};
virtual uint32_t compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) = 0;
virtual uint32_t decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength) = 0;
};
}
#endif //__PolyVox_Compressor_H__

View File

@ -25,6 +25,8 @@ freely, subject to the following restrictions:
#define __PolyVox_Block_H__
#include "PolyVoxCore/Impl/TypeDef.h"
#include "PolyVoxCore/Compressor.h"
#include "PolyVoxCore/Vector.h"
#include <limits>
@ -60,10 +62,9 @@ namespace PolyVox
uint32_t calculateSizeInBytes(void);
public:
void compress(void);
void uncompress(void);
void compress(Compressor* pCompressor);
void uncompress(Compressor* pCompressor);
std::vector< RunlengthEntry<uint16_t> > m_vecCompressedData;
void* m_pCompressedData;
uint32_t m_uCompressedDataLength;
VoxelType* m_tUncompressedData;

View File

@ -131,20 +131,21 @@ namespace PolyVox
m_bIsUncompressedDataModified = true;
//For some reason blocks start out compressed. We should probably change this.
compress();
compress(0);
}
template <typename VoxelType>
uint32_t Block<VoxelType>::calculateSizeInBytes(void)
{
//FIXME - This function is incomplete.
uint32_t uSizeInBytes = sizeof(Block<VoxelType>);
uSizeInBytes += m_vecCompressedData.capacity() * sizeof(RunlengthEntry<uint16_t>);
return uSizeInBytes;
}
template <typename VoxelType>
void Block<VoxelType>::compress(void)
void Block<VoxelType>::compress(Compressor* pCompressor)
{
//POLYVOX_ASSERT(pCompressor, "Compressor is not valid");
POLYVOX_ASSERT(m_bIsCompressed == false, "Attempted to compress block which is already flagged as compressed.");
POLYVOX_ASSERT(m_tUncompressedData != 0, "No uncompressed data is present.");
@ -175,8 +176,9 @@ namespace PolyVox
}
template <typename VoxelType>
void Block<VoxelType>::uncompress(void)
void Block<VoxelType>::uncompress(Compressor* pCompressor)
{
//POLYVOX_ASSERT(pCompressor, "Compressor is not valid");
POLYVOX_ASSERT(m_bIsCompressed == true, "Attempted to uncompress block which is not flagged as compressed.");
POLYVOX_ASSERT(m_tUncompressedData == 0, "Uncompressed data already exists.");

View File

@ -26,6 +26,7 @@ freely, subject to the following restrictions:
#include "PolyVoxCore/BaseVolume.h"
#include "Impl/Block.h"
#include "PolyVoxCore/Compressor.h"
#include "PolyVoxCore/Log.h"
#include "PolyVoxCore/Region.h"
#include "PolyVoxCore/Vector.h"
@ -256,6 +257,7 @@ namespace PolyVox
LargeVolume
(
const Region& regValid,
Compressor* pCompressor = 0,
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataRequiredHandler = 0,
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataOverflowHandler = 0,
bool bPagingEnabled = false,
@ -363,6 +365,9 @@ namespace PolyVox
uint16_t m_uBlockSideLength;
uint8_t m_uBlockSideLengthPower;
//The compressor used by the Blocks to compress their data if required.
Compressor* m_pCompressor;
bool m_bCompressionEnabled;
bool m_bPagingEnabled;
};

View File

@ -62,12 +62,14 @@ namespace PolyVox
LargeVolume<VoxelType>::LargeVolume
(
const Region& regValid,
Compressor* pCompressor,
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataRequiredHandler,
polyvox_function<void(const ConstVolumeProxy<VoxelType>&, const Region&)> dataOverflowHandler,
bool bPagingEnabled,
uint16_t uBlockSideLength
)
:BaseVolume<VoxelType>(regValid)
,m_pCompressor(pCompressor)
{
m_funcDataRequiredHandler = dataRequiredHandler;
m_funcDataOverflowHandler = dataOverflowHandler;
@ -456,7 +458,7 @@ namespace PolyVox
{
for(uint32_t ct = 0; ct < m_vecUncompressedBlockCache.size(); ct++)
{
m_vecUncompressedBlockCache[ct]->block.compress();
m_vecUncompressedBlockCache[ct]->block.compress(m_pCompressor);
}
m_vecUncompressedBlockCache.clear();
}
@ -537,7 +539,7 @@ namespace PolyVox
if(m_vecUncompressedBlockCache[ct] == &(itBlock->second))
{
// TODO: compression is unneccessary? or will not compressing this cause a memleak?
itBlock->second.block.compress();
itBlock->second.block.compress(m_pCompressor);
// put last object in cache here
m_vecUncompressedBlockCache[ct] = m_vecUncompressedBlockCache.back();
// decrease cache size by one since last element is now in here twice
@ -667,7 +669,7 @@ namespace PolyVox
}
//Compress the least recently used block.
m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex]->block.compress();
m_vecUncompressedBlockCache[leastRecentlyUsedBlockIndex]->block.compress(m_pCompressor);
//We don't actually remove any elements from this vector, we
//simply change the pointer to point at the new uncompressed bloack.
@ -678,7 +680,7 @@ namespace PolyVox
m_vecUncompressedBlockCache.push_back(&loadedBlock);
}
loadedBlock.block.uncompress();
loadedBlock.block.uncompress(m_pCompressor);
m_pLastAccessedBlock = &(loadedBlock.block);
POLYVOX_ASSERT(m_pLastAccessedBlock->m_tUncompressedData, "Block has no uncompressed data");

View File

@ -1,9 +1,11 @@
#ifndef __PolyVox_MinizCompressor_H__
#define __PolyVox_MinizCompressor_H__
#include "PolyVoxCore/Impl/TypeDef.h"
#include "PolyVoxCore/Compressor.h"
class MinizCompressor
namespace PolyVox
{
class MinizCompressor : public Compressor
{
public:
MinizCompressor();
@ -12,5 +14,6 @@ public:
uint32_t compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength);
uint32_t decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength);
};
}
#endif //__PolyVox_MinizCompressor_H__

View File

@ -1,10 +1,12 @@
#ifndef __PolyVox_RLECompressor_H__
#define __PolyVox_RLECompressor_H__
#include "PolyVoxCore/Impl/TypeDef.h"
#include "PolyVoxCore/Compressor.h"
namespace PolyVox
{
template<typename ValueType, typename LengthType>
class RLECompressor
class RLECompressor : public Compressor
{
struct Run
{
@ -18,6 +20,7 @@ public:
uint32_t compress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength);
uint32_t decompress(void* pSrcData, uint32_t uSrcLength, void* pDstData, uint32_t uDstLength);
};
}
#include "RLECompressor.inl"

View File

@ -2,6 +2,8 @@
#include <cassert>
#include <limits>
namespace PolyVox
{
template<typename ValueType, typename LengthType>
RLECompressor<ValueType, LengthType>::RLECompressor()
{
@ -83,4 +85,4 @@ uint32_t RLECompressor<ValueType, LengthType>::decompress(void* pSrcData, uint32
return uDstLengthInBytes;
}
}

View File

@ -14,6 +14,8 @@
// it is then to #include it directly which is what the examples do.
#include "PolyVoxCore/Impl/miniz.c"
namespace PolyVox
{
MinizCompressor::MinizCompressor()
{
}
@ -43,3 +45,4 @@ uint32_t MinizCompressor::decompress(void* pSrcData, uint32_t uSrcLength, void*
return ulDstLength;
}
}