diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 2318d55c..beb314fc 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -421,7 +421,7 @@ int main(int argc, char *argv[]) openGLWidget.show(); //Create an empty volume and then place a sphere in it - Volume volData(128, 128, 128); + Volume volData(256, 256, 256); //createSphereInVolume(volData, 30); createPerlinVolume(volData); @@ -439,12 +439,12 @@ int main(int argc, char *argv[]) }*/ //Extract the surface - SurfaceMesh mesh; + /*SurfaceMesh mesh; CubicSurfaceExtractorWithNormals surfaceExtractor(&volData, volData.getEnclosingRegion(), &mesh); surfaceExtractor.execute(); //Pass the surface to the OpenGL window - openGLWidget.setSurfaceMeshToRender(mesh); + openGLWidget.setSurfaceMeshToRender(mesh);*/ //Run the message pump. return app.exec(); diff --git a/library/PolyVoxCore/include/PolyVoxImpl/Block.h b/library/PolyVoxCore/include/PolyVoxImpl/Block.h index d9538c77..1411c7c6 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/Block.h +++ b/library/PolyVoxCore/include/PolyVoxImpl/Block.h @@ -26,6 +26,8 @@ freely, subject to the following restrictions: #include "PolyVoxForwardDeclarations.h" +#include + namespace PolyVox { template @@ -61,6 +63,9 @@ namespace PolyVox VoxelType* m_tUncompressedData; bool m_bIsCompressed; uint32_t m_uTimestamp; + + std::vector runlengths; + std::vector values; }; } diff --git a/library/PolyVoxCore/include/PolyVoxImpl/Block.inl b/library/PolyVoxCore/include/PolyVoxImpl/Block.inl index 8ac7089a..17d7f326 100644 --- a/library/PolyVoxCore/include/PolyVoxImpl/Block.inl +++ b/library/PolyVoxCore/include/PolyVoxImpl/Block.inl @@ -76,6 +76,13 @@ namespace PolyVox m_uSideLengthPower = rhs.m_uSideLengthPower; memcpy(m_tCompressedData, rhs.m_tCompressedData, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType)); + m_bIsCompressed = rhs.m_bIsCompressed; + if(m_bIsCompressed == false) + { + memcpy(m_tUncompressedData, rhs.m_tUncompressedData, m_uSideLength * m_uSideLength * m_uSideLength * sizeof(VoxelType)); + } + m_uTimestamp = rhs.m_uTimestamp; + return *this; } @@ -186,7 +193,43 @@ namespace PolyVox template void Block::compress(void) { - memcpy(m_tCompressedData, m_tUncompressedData, sizeof(VoxelType) * m_uSideLength * m_uSideLength * m_uSideLength); + //memcpy(m_tCompressedData, m_tUncompressedData, sizeof(VoxelType) * m_uSideLength * m_uSideLength * m_uSideLength); + VoxelType current; + uint32_t runLength = 0; + uint32_t uNoOfVoxels = m_uSideLength * m_uSideLength * m_uSideLength; + bool firstTime = true; + //uint32_t runlengthCounter = 0; + runlengths.clear(); + values.clear(); + + for(uint32_t ct = 0; ct < uNoOfVoxels; ++ct) + { + VoxelType value = *(m_tUncompressedData + ct); + if(firstTime) + { + current = value; + runLength = 1; + firstTime = false; + } + else + { + if(value == current) + { + runLength++; + } + else + { + //stream.write(reinterpret_cast(¤t), sizeof(current)); + //stream.write(reinterpret_cast(&runLength), sizeof(runLength)); + runlengths.push_back(runLength); + values.push_back(current); + current = value; + runLength = 1; + } + } + } + + delete[] m_tUncompressedData; m_tUncompressedData = 0; m_bIsCompressed = true; @@ -196,7 +239,20 @@ namespace PolyVox void Block::uncompress(void) { m_tUncompressedData = new VoxelType[m_uSideLength * m_uSideLength * m_uSideLength]; - memcpy(m_tUncompressedData, m_tCompressedData, sizeof(VoxelType) * m_uSideLength * m_uSideLength * m_uSideLength); + + + //memcpy(m_tUncompressedData, m_tCompressedData, sizeof(VoxelType) * m_uSideLength * m_uSideLength * m_uSideLength); + VoxelType* pUncompressedData = m_tUncompressedData; + for(uint32_t ct = 0; ct < runlengths.size(); ++ct) + { + for(uint32_t i = 0; i < runlengths[ct]; ++i) + { + *pUncompressedData = values[ct]; + ++pUncompressedData; + } + } + + m_bIsCompressed = false; } } diff --git a/library/PolyVoxCore/include/Volume.inl b/library/PolyVoxCore/include/Volume.inl index 1c25c957..dd3f3dba 100644 --- a/library/PolyVoxCore/include/Volume.inl +++ b/library/PolyVoxCore/include/Volume.inl @@ -388,10 +388,10 @@ namespace PolyVox return block; } - const uint32_t MaxUncompressedBlocks = 4; + const uint32_t MaxUncompressedBlocks = 10; if(m_pUncompressedBlocks.size() == MaxUncompressedBlocks) { - Block* pLeastRecentlyUsedBlock; + Block* pLeastRecentlyUsedBlock = 0; uint32_t uLeastRecentTimestamp = 100000000; for(std::set*>::iterator iter = m_pUncompressedBlocks.begin(); iter != m_pUncompressedBlocks.end(); iter++) {