diff --git a/examples/OpenGL/main.cpp b/examples/OpenGL/main.cpp index 2969efd8..fe66eae8 100644 --- a/examples/OpenGL/main.cpp +++ b/examples/OpenGL/main.cpp @@ -42,7 +42,7 @@ int g_frameCounter = 0; bool g_bUseOpenGLVertexBufferObjects; //Creates a volume 128x128x128 -Volume g_volData(logBase2(g_uVolumeSideLength)); +Volume g_volData(g_uVolumeSideLength); //Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region OpenGLSurfacePatch g_openGLSurfacePatches[g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions]; diff --git a/library/include/PolyVoxCore/Block.inl b/library/include/PolyVoxCore/Block.inl index a829490e..5582a544 100644 --- a/library/include/PolyVoxCore/Block.inl +++ b/library/include/PolyVoxCore/Block.inl @@ -34,10 +34,10 @@ namespace PolyVox Block::Block(uint8 uSideLength) :m_tData(0) { - //Debug mode error handling + //Debug mode validation assert(isPowerOf2(uSideLength)); - //Release mode error handling + //Release mode validation if(!isPowerOf2(uSideLength)) { throw std::invalid_argument("Block side length must be a power of two."); diff --git a/library/include/PolyVoxCore/Volume.h b/library/include/PolyVoxCore/Volume.h index 02fee274..02ff6298 100644 --- a/library/include/PolyVoxCore/Volume.h +++ b/library/include/PolyVoxCore/Volume.h @@ -39,7 +39,7 @@ namespace PolyVox friend class VolumeIterator; public: - Volume(uint8 uSideLengthPower, uint8 uBlockSideLengthPower = 5); + Volume(uint16 uSideLength, uint16 uBlockSideLength = 64); Volume(const Volume& rhs); ~Volume(); diff --git a/library/include/PolyVoxCore/Volume.inl b/library/include/PolyVoxCore/Volume.inl index b4fadd0e..885c0588 100644 --- a/library/include/PolyVoxCore/Volume.inl +++ b/library/include/PolyVoxCore/Volume.inl @@ -33,22 +33,35 @@ namespace PolyVox { #pragma region Constructors/Destructors template - Volume::Volume(uint8 uSideLengthPower, uint8 uBlockSideLengthPower) + Volume::Volume(uint16 uSideLength, uint16 uBlockSideLength) :m_pBlocks(0) { - //Check the volume size is sensible. This corresponds to a side length of 65536 voxels - if(uSideLengthPower > 16) + //Debug mode validation + assert(isPowerOf2(uSideLength)); + assert(isPowerOf2(uBlockSideLength)); + assert(uBlockSideLength <= uSideLength); + + //Release mode validation + if(!isPowerOf2(uSideLength)) { - throw std::invalid_argument("Volume side length power must be less than or equal to 16"); + throw std::invalid_argument("Volume side length must be a power of two."); + } + if(!isPowerOf2(uBlockSideLength)) + { + throw std::invalid_argument("Block side length must be a power of two."); + } + if(uBlockSideLength > uSideLength) + { + throw std::invalid_argument("Block side length cannot be less than volume side length."); } //Compute the volume side length - m_uSideLengthPower = uSideLengthPower; - m_uSideLength = 0x01 << uSideLengthPower; + m_uSideLength = uSideLength; + m_uSideLengthPower = logBase2(m_uSideLength); //Compute the block side length - m_uBlockSideLengthPower = uBlockSideLengthPower; - m_uBlockSideLength = 0x01 << uBlockSideLengthPower; + m_uBlockSideLength = uBlockSideLength; + m_uBlockSideLengthPower = logBase2(m_uBlockSideLength); //Compute the side length in blocks m_uSideLengthInBlocks = m_uSideLength / m_uBlockSideLength; @@ -63,7 +76,7 @@ namespace PolyVox m_pHomogenousValue = new VoxelType[m_uNoOfBlocksInVolume]; for(uint32 i = 0; i < m_uNoOfBlocksInVolume; ++i) { - m_pBlocks[i] = getHomogenousBlock(0); //new Block(uBlockSideLengthPower); + m_pBlocks[i] = getHomogenousBlock(0); m_pIsShared[i] = true; m_pIsPotentiallySharable[i] = false; m_pHomogenousValue[i] = 0; diff --git a/library/source/PolyVoxCore/Utility.cpp b/library/source/PolyVoxCore/Utility.cpp index 70901937..3e158dda 100644 --- a/library/source/PolyVoxCore/Utility.cpp +++ b/library/source/PolyVoxCore/Utility.cpp @@ -30,11 +30,11 @@ namespace PolyVox //If this is not the case then the output is undefined. uint8 logBase2(uint32 uInput) { - //Debug mode error handling + //Debug mode validation assert(uInput != 0); assert(isPowerOf2(uInput)); - //Release mode error handling + //Release mode validation if(uInput == 0) { throw std::invalid_argument("Cannot compute the log of zero."); diff --git a/library/source/PolyVoxUtil/Serialization.cpp b/library/source/PolyVoxUtil/Serialization.cpp index a1ff3e2a..28f7c74e 100644 --- a/library/source/PolyVoxUtil/Serialization.cpp +++ b/library/source/PolyVoxUtil/Serialization.cpp @@ -19,14 +19,14 @@ namespace PolyVox stream.read(reinterpret_cast(&volumeWidthPower), sizeof(volumeWidthPower)); stream.read(reinterpret_cast(&volumeHeightPower), sizeof(volumeHeightPower)); stream.read(reinterpret_cast(&volumeDepthPower), sizeof(volumeDepthPower)); - - //FIXME - need to support non cubic volumes - Volume* volume = new Volume(volumeWidthPower); uint16 volumeWidth = 0x0001 << volumeWidthPower; uint16 volumeHeight = 0x0001 << volumeHeightPower; uint16 volumeDepth = 0x0001 << volumeDepthPower; + //FIXME - need to support non cubic volumes + Volume* volume = new Volume(volumeWidth); + //Read data for(uint16 z = 0; z < volumeDepth; ++z) { @@ -87,14 +87,14 @@ namespace PolyVox stream.read(reinterpret_cast(&volumeWidthPower), sizeof(volumeWidthPower)); stream.read(reinterpret_cast(&volumeHeightPower), sizeof(volumeHeightPower)); stream.read(reinterpret_cast(&volumeDepthPower), sizeof(volumeDepthPower)); - - //FIXME - need to support non cubic volumes - Volume* volume = new Volume(volumeWidthPower); uint16 volumeWidth = 0x0001 << volumeWidthPower; uint16 volumeHeight = 0x0001 << volumeHeightPower; uint16 volumeDepth = 0x0001 << volumeDepthPower; + //FIXME - need to support non cubic volumes + Volume* volume = new Volume(volumeWidth); + //Read data bool firstTime = true; uint32 runLength = 0;