From e80fa3de7dd5636ad5774d6893d4e47fd7f53c6c Mon Sep 17 00:00:00 2001 From: David Williams Date: Sat, 22 Jun 2013 12:16:52 +0200 Subject: [PATCH] Added functions for accessing compressed data in block. --- .../include/PolyVoxCore/Impl/Block.h | 3 ++ .../include/PolyVoxCore/Impl/Block.inl | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h index 1f7b71d5..93a9c0f0 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.h @@ -51,10 +51,13 @@ namespace PolyVox public: Block(uint16_t uSideLength = 0); + const uint8_t* getCompressedData(void) const; + const uint32_t getCompressedDataLength(void) const; uint16_t getSideLength(void) const; VoxelType getVoxel(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos) const; VoxelType getVoxel(const Vector3DUint16& v3dPos) const; + void setCompressedData(const uint8_t* const data, uint32_t dataLength); void setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue); void setVoxelAt(const Vector3DUint16& v3dPos, VoxelType tValue); diff --git a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl index 61c9baac..64fbe33b 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/Impl/Block.inl @@ -51,6 +51,24 @@ namespace PolyVox } } + template + const uint8_t* Block::getCompressedData(void) const + { + POLYVOX_ASSERT(m_bIsCompressed, "You cannot call getCompressedData() when the block is not compressed"); + POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL"); + + return m_pCompressedData; + } + + template + const uint32_t Block::getCompressedDataLength(void) const + { + POLYVOX_ASSERT(m_bIsCompressed, "You cannot call getCompressedData() when the block is not compressed"); + POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL"); + + return m_uCompressedDataLength; + } + template uint16_t Block::getSideLength(void) const { @@ -64,6 +82,7 @@ namespace PolyVox POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the block"); POLYVOX_ASSERT(uYPos < m_uSideLength, "Supplied position is outside of the block"); POLYVOX_ASSERT(uZPos < m_uSideLength, "Supplied position is outside of the block"); + POLYVOX_ASSERT(!m_bIsCompressed, "You cannot call getVoxel() when a block is compressed"); POLYVOX_ASSERT(m_tUncompressedData, "No uncompressed data - block must be decompressed before accessing voxels."); return m_tUncompressedData @@ -80,6 +99,20 @@ namespace PolyVox return getVoxel(v3dPos.getX(), v3dPos.getY(), v3dPos.getZ()); } + template + void Block::setCompressedData(const uint8_t* const data, uint32_t dataLength) + { + POLYVOX_ASSERT(m_bIsCompressed, "You cannot call setCompressedData() when the block is not compressed"); + POLYVOX_ASSERT(m_pCompressedData, "Compressed data is NULL"); + POLYVOX_ASSERT(m_pCompressedData != data, "Attempting to copy data onto itself"); + + delete[] m_pCompressedData; + + m_uCompressedDataLength = dataLength; + m_pCompressedData = new uint8_t[dataLength]; + memcpy(m_pCompressedData, data, dataLength); + } + template void Block::setVoxelAt(uint16_t uXPos, uint16_t uYPos, uint16_t uZPos, VoxelType tValue) { @@ -87,6 +120,7 @@ namespace PolyVox POLYVOX_ASSERT(uXPos < m_uSideLength, "Supplied position is outside of the block"); POLYVOX_ASSERT(uYPos < m_uSideLength, "Supplied position is outside of the block"); POLYVOX_ASSERT(uZPos < m_uSideLength, "Supplied position is outside of the block"); + POLYVOX_ASSERT(!m_bIsCompressed, "You cannot call setVoxelAt() when a block is compressed"); POLYVOX_ASSERT(m_tUncompressedData, "No uncompressed data - block must be decompressed before accessing voxels."); m_tUncompressedData