diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index 5ed191f5..ccae9941 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -25,6 +25,7 @@ freely, subject to the following restrictions: #include "PolyVoxCore/LargeVolume.h" #include "PolyVoxCore/LowPassFilter.h" #include "PolyVoxCore/RawVolume.h" +#include "PolyVoxCore/RLECompressor.h" #include "PolyVoxCore/SurfaceMesh.h" #include "PolyVoxCore/Impl/Utility.h" @@ -48,7 +49,8 @@ using namespace std; int main(int argc, char *argv[]) { - LargeVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1))); + RLECompressor* compressor = new RLECompressor(); + LargeVolume volData(PolyVox::Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1)), compressor, 0); //Make our volume contain a sphere in the center. int32_t minPos = 0; diff --git a/examples/Paging/main.cpp b/examples/Paging/main.cpp index ab40f514..8e6cba7f 100644 --- a/examples/Paging/main.cpp +++ b/examples/Paging/main.cpp @@ -314,12 +314,13 @@ int main(int argc, char *argv[]) OpenGLWidget openGLWidget(0); openGLWidget.show(); - RLECompressor* compressor = new RLECompressor(); + RLECompressor* compressor = new RLECompressor(); + PerlinNoisePager* pager = new PerlinNoisePager(); //If these lines don't compile, please try commenting them out and using the two lines after //(you will need Boost for this). If you have to do this then please let us know in the forums as //we rely on community feedback to keep the Boost version running. - LargeVolume volData(compressor, &load, &unload, 64); + LargeVolume volData(compressor, pager, 64); //LargeVolume volData(polyvox_bind(&load, polyvox_placeholder_1, polyvox_placeholder_2), // polyvox_bind(&unload, polyvox_placeholder_1, polyvox_placeholder_2), 256); volData.setMaxNumberOfBlocksInMemory(4096); diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.h index ae504a20..6de905b3 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/Pager.h" #include "PolyVoxCore/Region.h" #include "PolyVoxCore/Vector.h" @@ -249,18 +250,15 @@ namespace PolyVox LargeVolume ( Compressor* pCompressor, - polyvox_function&, const Region&)> dataRequiredHandler, - polyvox_function&, const Region&)> dataOverflowHandler, + Pager* pPager, uint16_t uBlockSideLength = 32 ); /// Constructor for creating a fixed size volume. LargeVolume ( const Region& regValid, - Compressor* pCompressor = 0, - polyvox_function&, const Region&)> dataRequiredHandler = 0, - polyvox_function&, const Region&)> dataOverflowHandler = 0, - bool bPagingEnabled = false, + Compressor* pCompressor, + Pager* pPager, uint16_t uBlockSideLength = 32 ); /// Destructor @@ -346,12 +344,12 @@ namespace PolyVox /// gets called when a new region is allocated and needs to be filled /// NOTE: accessing ANY voxels outside this region during the process of this function /// is absolutely unsafe - polyvox_function&, const Region&)> m_funcDataRequiredHandler; + //polyvox_function&, const Region&)> m_funcDataRequiredHandler; /// gets called when a Region needs to be stored by the user, because LargeVolume will erase it right after /// this function returns /// NOTE: accessing ANY voxels outside this region during the process of this function /// is absolutely unsafe - polyvox_function&, const Region&)> m_funcDataOverflowHandler; + //polyvox_function&, const Region&)> m_funcDataOverflowHandler; Block* getUncompressedBlock(int32_t uBlockX, int32_t uBlockY, int32_t uBlockZ) const; void eraseBlock(typename std::map::iterator itBlock) const; @@ -381,8 +379,7 @@ namespace PolyVox //The compressor used by the Blocks to compress their data if required. Compressor* m_pCompressor; - - bool m_bPagingEnabled; + Pager* m_pPager; }; } diff --git a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl index 4ea2b2af..7201836a 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl +++ b/library/PolyVoxCore/include/PolyVoxCore/LargeVolume.inl @@ -38,16 +38,13 @@ namespace PolyVox LargeVolume::LargeVolume ( Compressor* pCompressor, - polyvox_function&, const Region&)> dataRequiredHandler, - polyvox_function&, const Region&)> dataOverflowHandler, + Pager* pPager, uint16_t uBlockSideLength ) :BaseVolume(Region::MaxRegion) ,m_pCompressor(pCompressor) { - m_funcDataRequiredHandler = dataRequiredHandler; - m_funcDataOverflowHandler = dataOverflowHandler; - m_bPagingEnabled = true; + m_pPager = pPager; //Create a volume of the right size. initialise(Region::MaxRegion,uBlockSideLength); } @@ -66,17 +63,13 @@ namespace PolyVox ( const Region& regValid, Compressor* pCompressor, - polyvox_function&, const Region&)> dataRequiredHandler, - polyvox_function&, const Region&)> dataOverflowHandler, - bool bPagingEnabled, + Pager* pPager, uint16_t uBlockSideLength ) :BaseVolume(regValid) ,m_pCompressor(pCompressor) { - m_funcDataRequiredHandler = dataRequiredHandler; - m_funcDataOverflowHandler = dataOverflowHandler; - m_bPagingEnabled = bPagingEnabled; + m_pPager = pPager; //Create a volume of the right size. initialise(regValid,uBlockSideLength); @@ -540,7 +533,7 @@ namespace PolyVox template void LargeVolume::eraseBlock(typename std::map::iterator itBlock) const { - if(m_funcDataOverflowHandler) + //if(m_funcDataOverflowHandler) { Vector3DInt32 v3dPos = itBlock->first; Vector3DInt32 v3dLower(v3dPos.getX() << m_uBlockSideLengthPower, v3dPos.getY() << m_uBlockSideLengthPower, v3dPos.getZ() << m_uBlockSideLengthPower); @@ -549,7 +542,7 @@ namespace PolyVox Region reg(v3dLower, v3dUpper); ConstVolumeProxy ConstVolumeProxy(*this, reg); - m_funcDataOverflowHandler(ConstVolumeProxy, reg); + m_pPager->dataOverflowHandler(ConstVolumeProxy, reg); } if(m_pCompressor) { @@ -617,7 +610,7 @@ namespace PolyVox //The block is not in the map, so we will have to create a new block and add it. //Before we do so, we might want to dump some existing data to make space. We //Only do this if paging is enabled. - if(m_bPagingEnabled) + if(m_pPager) { // check wether another block needs to be unloaded before this one can be loaded if(m_pBlocks.size() == m_uMaxNumberOfBlocksInMemory) @@ -648,9 +641,9 @@ namespace PolyVox //We have created the new block. If paging is enabled it should be used to //fill in the required data. Otherwise it is just left in the default state. - if(m_bPagingEnabled) + if(m_pPager) { - if(m_funcDataRequiredHandler) + //if(m_funcDataRequiredHandler) { // "load" will actually call setVoxel, which will in turn call this function again but the block will be found // so this if(itBlock == m_pBlocks.end()) never is entered @@ -659,7 +652,7 @@ namespace PolyVox Vector3DInt32 v3dUpper = v3dLower + Vector3DInt32(m_uBlockSideLength-1, m_uBlockSideLength-1, m_uBlockSideLength-1); Region reg(v3dLower, v3dUpper); ConstVolumeProxy ConstVolumeProxy(*this, reg); - m_funcDataRequiredHandler(ConstVolumeProxy, reg); + m_pPager->dataRequiredHandler(ConstVolumeProxy, reg); } } } diff --git a/library/PolyVoxCore/include/PolyVoxCore/Pager.h b/library/PolyVoxCore/include/PolyVoxCore/Pager.h index 706640aa..893898bb 100644 --- a/library/PolyVoxCore/include/PolyVoxCore/Pager.h +++ b/library/PolyVoxCore/include/PolyVoxCore/Pager.h @@ -42,8 +42,15 @@ namespace PolyVox /// Destructor virtual ~Pager() {}; - virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region); - virtual void dataOverflowHandler(const ConstVolumeProxy& volumeProxy, const Region& region); + virtual void dataRequiredHandler(const ConstVolumeProxy& volumeProxy, const Region& region) + { + POLYVOX_ASSERT(false, "NOT IMPLEMENTED"); + } + + virtual void dataOverflowHandler(const ConstVolumeProxy& volumeProxy, const Region& region) + { + POLYVOX_ASSERT(false, "NOT IMPLEMENTED"); + } }; } diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index dd000a88..4a4d638d 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -277,7 +277,7 @@ TestVolume::TestVolume() //Create the volumes m_pRawVolume = new RawVolume(region); m_pSimpleVolume = new SimpleVolume(region); - m_pLargeVolume = new LargeVolume(region, m_pCompressor); + m_pLargeVolume = new LargeVolume(region, m_pCompressor, 0, 32); // LargeVolume currently fails a test if compression is enabled. It // may be related to accessing the data through more than one sampler?