Work on Volume class.
This commit is contained in:
		| @@ -42,7 +42,7 @@ int g_frameCounter = 0; | |||||||
| bool g_bUseOpenGLVertexBufferObjects; | bool g_bUseOpenGLVertexBufferObjects; | ||||||
|  |  | ||||||
| //Creates a volume 128x128x128 | //Creates a volume 128x128x128 | ||||||
| Volume<uint8> g_volData(logBase2(g_uVolumeSideLength)); | Volume<uint8> g_volData(g_uVolumeSideLength); | ||||||
|  |  | ||||||
| //Rather than storing one big mesh, the volume is broken into regions and a mesh is stored for each region | //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]; | OpenGLSurfacePatch g_openGLSurfacePatches[g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions]; | ||||||
|   | |||||||
| @@ -34,10 +34,10 @@ namespace PolyVox | |||||||
| 	Block<VoxelType>::Block(uint8 uSideLength) | 	Block<VoxelType>::Block(uint8 uSideLength) | ||||||
| 		:m_tData(0) | 		:m_tData(0) | ||||||
| 	{ | 	{ | ||||||
| 		//Debug mode error handling | 		//Debug mode validation | ||||||
| 		assert(isPowerOf2(uSideLength)); | 		assert(isPowerOf2(uSideLength)); | ||||||
|  |  | ||||||
| 		//Release mode error handling | 		//Release mode validation | ||||||
| 		if(!isPowerOf2(uSideLength)) | 		if(!isPowerOf2(uSideLength)) | ||||||
| 		{ | 		{ | ||||||
| 			throw std::invalid_argument("Block side length must be a power of two."); | 			throw std::invalid_argument("Block side length must be a power of two."); | ||||||
|   | |||||||
| @@ -39,7 +39,7 @@ namespace PolyVox | |||||||
| 		friend class VolumeIterator<VoxelType>; | 		friend class VolumeIterator<VoxelType>; | ||||||
|  |  | ||||||
| 	public:		 | 	public:		 | ||||||
| 		Volume(uint8 uSideLengthPower, uint8 uBlockSideLengthPower = 5); | 		Volume(uint16 uSideLength, uint16 uBlockSideLength = 64); | ||||||
| 		Volume(const Volume& rhs); | 		Volume(const Volume& rhs); | ||||||
| 		~Volume();	 | 		~Volume();	 | ||||||
|  |  | ||||||
|   | |||||||
| @@ -33,22 +33,35 @@ namespace PolyVox | |||||||
| { | { | ||||||
| 	#pragma region Constructors/Destructors | 	#pragma region Constructors/Destructors | ||||||
| 	template <typename VoxelType> | 	template <typename VoxelType> | ||||||
| 	Volume<VoxelType>::Volume(uint8 uSideLengthPower, uint8 uBlockSideLengthPower) | 	Volume<VoxelType>::Volume(uint16 uSideLength, uint16 uBlockSideLength) | ||||||
| 		:m_pBlocks(0) | 		:m_pBlocks(0) | ||||||
| 	{ | 	{ | ||||||
| 		//Check the volume size is sensible. This corresponds to a side length of 65536 voxels | 		//Debug mode validation | ||||||
| 		if(uSideLengthPower > 16) | 		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 | 		//Compute the volume side length | ||||||
| 		m_uSideLengthPower = uSideLengthPower; | 		m_uSideLength = uSideLength; | ||||||
| 		m_uSideLength = 0x01 << uSideLengthPower; | 		m_uSideLengthPower = logBase2(m_uSideLength); | ||||||
|  |  | ||||||
| 		//Compute the block side length | 		//Compute the block side length | ||||||
| 		m_uBlockSideLengthPower = uBlockSideLengthPower; | 		m_uBlockSideLength = uBlockSideLength; | ||||||
| 		m_uBlockSideLength = 0x01 << uBlockSideLengthPower; | 		m_uBlockSideLengthPower = logBase2(m_uBlockSideLength); | ||||||
|  |  | ||||||
| 		//Compute the side length in blocks | 		//Compute the side length in blocks | ||||||
| 		m_uSideLengthInBlocks = m_uSideLength / m_uBlockSideLength; | 		m_uSideLengthInBlocks = m_uSideLength / m_uBlockSideLength; | ||||||
| @@ -63,7 +76,7 @@ namespace PolyVox | |||||||
| 		m_pHomogenousValue = new VoxelType[m_uNoOfBlocksInVolume]; | 		m_pHomogenousValue = new VoxelType[m_uNoOfBlocksInVolume]; | ||||||
| 		for(uint32 i = 0; i < m_uNoOfBlocksInVolume; ++i) | 		for(uint32 i = 0; i < m_uNoOfBlocksInVolume; ++i) | ||||||
| 		{ | 		{ | ||||||
| 			m_pBlocks[i] = getHomogenousBlock(0); //new Block<VoxelType>(uBlockSideLengthPower); | 			m_pBlocks[i] = getHomogenousBlock(0); | ||||||
| 			m_pIsShared[i] = true; | 			m_pIsShared[i] = true; | ||||||
| 			m_pIsPotentiallySharable[i] = false; | 			m_pIsPotentiallySharable[i] = false; | ||||||
| 			m_pHomogenousValue[i] = 0; | 			m_pHomogenousValue[i] = 0; | ||||||
|   | |||||||
| @@ -30,11 +30,11 @@ namespace PolyVox | |||||||
| 	//If this is not the case then the output is undefined. | 	//If this is not the case then the output is undefined. | ||||||
| 	uint8 logBase2(uint32 uInput) | 	uint8 logBase2(uint32 uInput) | ||||||
| 	{ | 	{ | ||||||
| 		//Debug mode error handling | 		//Debug mode validation | ||||||
| 		assert(uInput != 0); | 		assert(uInput != 0); | ||||||
| 		assert(isPowerOf2(uInput)); | 		assert(isPowerOf2(uInput)); | ||||||
|  |  | ||||||
| 		//Release mode error handling | 		//Release mode validation | ||||||
| 		if(uInput == 0) | 		if(uInput == 0) | ||||||
| 		{ | 		{ | ||||||
| 			throw std::invalid_argument("Cannot compute the log of zero."); | 			throw std::invalid_argument("Cannot compute the log of zero."); | ||||||
|   | |||||||
| @@ -20,13 +20,13 @@ namespace PolyVox | |||||||
| 		stream.read(reinterpret_cast<char*>(&volumeHeightPower), sizeof(volumeHeightPower)); | 		stream.read(reinterpret_cast<char*>(&volumeHeightPower), sizeof(volumeHeightPower)); | ||||||
| 		stream.read(reinterpret_cast<char*>(&volumeDepthPower), sizeof(volumeDepthPower)); | 		stream.read(reinterpret_cast<char*>(&volumeDepthPower), sizeof(volumeDepthPower)); | ||||||
|  |  | ||||||
| 		//FIXME - need to support non cubic volumes |  | ||||||
| 		Volume<uint8>* volume = new Volume<uint8>(volumeWidthPower); |  | ||||||
|  |  | ||||||
| 		uint16 volumeWidth = 0x0001 << volumeWidthPower; | 		uint16 volumeWidth = 0x0001 << volumeWidthPower; | ||||||
| 		uint16 volumeHeight = 0x0001 << volumeHeightPower; | 		uint16 volumeHeight = 0x0001 << volumeHeightPower; | ||||||
| 		uint16 volumeDepth = 0x0001 << volumeDepthPower; | 		uint16 volumeDepth = 0x0001 << volumeDepthPower; | ||||||
|  |  | ||||||
|  | 		//FIXME - need to support non cubic volumes | ||||||
|  | 		Volume<uint8>* volume = new Volume<uint8>(volumeWidth); | ||||||
|  |  | ||||||
| 		//Read data | 		//Read data | ||||||
| 		for(uint16 z = 0; z < volumeDepth; ++z) | 		for(uint16 z = 0; z < volumeDepth; ++z) | ||||||
| 		{ | 		{ | ||||||
| @@ -88,13 +88,13 @@ namespace PolyVox | |||||||
| 		stream.read(reinterpret_cast<char*>(&volumeHeightPower), sizeof(volumeHeightPower)); | 		stream.read(reinterpret_cast<char*>(&volumeHeightPower), sizeof(volumeHeightPower)); | ||||||
| 		stream.read(reinterpret_cast<char*>(&volumeDepthPower), sizeof(volumeDepthPower)); | 		stream.read(reinterpret_cast<char*>(&volumeDepthPower), sizeof(volumeDepthPower)); | ||||||
|  |  | ||||||
| 		//FIXME - need to support non cubic volumes |  | ||||||
| 		Volume<uint8>* volume = new Volume<uint8>(volumeWidthPower); |  | ||||||
|  |  | ||||||
| 		uint16 volumeWidth = 0x0001 << volumeWidthPower; | 		uint16 volumeWidth = 0x0001 << volumeWidthPower; | ||||||
| 		uint16 volumeHeight = 0x0001 << volumeHeightPower; | 		uint16 volumeHeight = 0x0001 << volumeHeightPower; | ||||||
| 		uint16 volumeDepth = 0x0001 << volumeDepthPower; | 		uint16 volumeDepth = 0x0001 << volumeDepthPower; | ||||||
|  |  | ||||||
|  | 		//FIXME - need to support non cubic volumes | ||||||
|  | 		Volume<uint8>* volume = new Volume<uint8>(volumeWidth); | ||||||
|  |  | ||||||
| 		//Read data | 		//Read data | ||||||
| 		bool firstTime = true; | 		bool firstTime = true; | ||||||
| 		uint32 runLength = 0; | 		uint32 runLength = 0; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user