Work on Volume class.

This commit is contained in:
David Williams 2009-03-24 22:29:39 +00:00
parent d191902db3
commit 5955a29a46
6 changed files with 34 additions and 21 deletions

View File

@ -42,7 +42,7 @@ int g_frameCounter = 0;
bool g_bUseOpenGLVertexBufferObjects;
//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
OpenGLSurfacePatch g_openGLSurfacePatches[g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions][g_uVolumeSideLengthInRegions];

View File

@ -34,10 +34,10 @@ namespace PolyVox
Block<VoxelType>::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.");

View File

@ -39,7 +39,7 @@ namespace PolyVox
friend class VolumeIterator<VoxelType>;
public:
Volume(uint8 uSideLengthPower, uint8 uBlockSideLengthPower = 5);
Volume(uint16 uSideLength, uint16 uBlockSideLength = 64);
Volume(const Volume& rhs);
~Volume();

View File

@ -33,22 +33,35 @@ namespace PolyVox
{
#pragma region Constructors/Destructors
template <typename VoxelType>
Volume<VoxelType>::Volume(uint8 uSideLengthPower, uint8 uBlockSideLengthPower)
Volume<VoxelType>::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<VoxelType>(uBlockSideLengthPower);
m_pBlocks[i] = getHomogenousBlock(0);
m_pIsShared[i] = true;
m_pIsPotentiallySharable[i] = false;
m_pHomogenousValue[i] = 0;

View File

@ -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.");

View File

@ -20,13 +20,13 @@ namespace PolyVox
stream.read(reinterpret_cast<char*>(&volumeHeightPower), sizeof(volumeHeightPower));
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 volumeHeight = 0x0001 << volumeHeightPower;
uint16 volumeDepth = 0x0001 << volumeDepthPower;
//FIXME - need to support non cubic volumes
Volume<uint8>* volume = new Volume<uint8>(volumeWidth);
//Read data
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*>(&volumeDepthPower), sizeof(volumeDepthPower));
//FIXME - need to support non cubic volumes
Volume<uint8>* volume = new Volume<uint8>(volumeWidthPower);
uint16 volumeWidth = 0x0001 << volumeWidthPower;
uint16 volumeHeight = 0x0001 << volumeHeightPower;
uint16 volumeDepth = 0x0001 << volumeDepthPower;
//FIXME - need to support non cubic volumes
Volume<uint8>* volume = new Volume<uint8>(volumeWidth);
//Read data
bool firstTime = true;
uint32 runLength = 0;