本文整理汇总了C++中DynamicArray::create方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicArray::create方法的具体用法?C++ DynamicArray::create怎么用?C++ DynamicArray::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicArray
的用法示例。
在下文中一共展示了DynamicArray::create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: catch
bool
testview(Pooma::Tester &tester, DynamicArray<T,Dynamic> &da,
const CA &daview)
{
tester.out() << "In testview:" << std::endl;
tester.out() << " da = " << da << std::endl;
tester.out() << "daview = " << daview << std::endl;
// the following should crash
tester.out() << "Trying to create values within da ..." << std::endl;
bool result = false;
#if POOMA_EXCEPTIONS
try {
da.create(3);
tester.out() << "Ack! create call didn't throw!!!" << std::endl;
result = false;
}
catch(const Pooma::Assertion &a)
{
tester.out() << "Caught assertion - it worked!" << std::endl;
result = true;
}
#else
da.create(3);
tester.out() << "Ack! Program should have aborted and never gotten here!"
<< std::endl;
#endif
return result;
}
示例2: loadUncompressedTga
//==============================================================================
static ANKI_USE_RESULT Error loadUncompressedTga(ResourceFilePtr fs,
U32& width,
U32& height,
U32& bpp,
DynamicArray<U8>& data,
GenericMemoryPoolAllocator<U8>& alloc)
{
Array<U8, 6> header6;
// read the info from header
ANKI_CHECK(fs->read((char*)&header6[0], sizeof(header6)));
width = header6[1] * 256 + header6[0];
height = header6[3] * 256 + header6[2];
bpp = header6[4];
if((width == 0) || (height == 0) || ((bpp != 24) && (bpp != 32)))
{
ANKI_LOGE("Invalid image information");
return ErrorCode::USER_DATA;
}
// read the data
I bytesPerPxl = (bpp / 8);
I imageSize = bytesPerPxl * width * height;
data.create(alloc, imageSize);
ANKI_CHECK(fs->read(reinterpret_cast<char*>(&data[0]), imageSize));
// swap red with blue
for(I i = 0; i < imageSize; i += bytesPerPxl)
{
U32 temp = data[i];
data[i] = data[i + 2];
data[i + 2] = temp;
}
return ErrorCode::NONE;
}
示例3: loadCompressedTga
//==============================================================================
static ANKI_USE_RESULT Error loadCompressedTga(ResourceFilePtr fs,
U32& width,
U32& height,
U32& bpp,
DynamicArray<U8>& data,
GenericMemoryPoolAllocator<U8>& alloc)
{
Array<U8, 6> header6;
ANKI_CHECK(fs->read(reinterpret_cast<char*>(&header6[0]), sizeof(header6)));
width = header6[1] * 256 + header6[0];
height = header6[3] * 256 + header6[2];
bpp = header6[4];
if((width <= 0) || (height <= 0) || ((bpp != 24) && (bpp != 32)))
{
ANKI_LOGE("Invalid texture information");
return ErrorCode::USER_DATA;
}
I bytesPerPxl = (bpp / 8);
I imageSize = bytesPerPxl * width * height;
data.create(alloc, imageSize);
U pixelcount = height * width;
U currentpixel = 0;
U currentbyte = 0;
U8 colorbuffer[4];
do
{
U8 chunkheader = 0;
ANKI_CHECK(fs->read((char*)&chunkheader, sizeof(U8)));
if(chunkheader < 128)
{
chunkheader++;
for(int counter = 0; counter < chunkheader; counter++)
{
ANKI_CHECK(fs->read((char*)&colorbuffer[0], bytesPerPxl));
data[currentbyte] = colorbuffer[2];
data[currentbyte + 1] = colorbuffer[1];
data[currentbyte + 2] = colorbuffer[0];
if(bytesPerPxl == 4)
{
data[currentbyte + 3] = colorbuffer[3];
}
currentbyte += bytesPerPxl;
currentpixel++;
if(currentpixel > pixelcount)
{
ANKI_LOGE("Too many pixels read");
return ErrorCode::USER_DATA;
}
}
}
else
{
chunkheader -= 127;
ANKI_CHECK(fs->read((char*)&colorbuffer[0], bytesPerPxl));
for(int counter = 0; counter < chunkheader; counter++)
{
data[currentbyte] = colorbuffer[2];
data[currentbyte + 1] = colorbuffer[1];
data[currentbyte + 2] = colorbuffer[0];
if(bytesPerPxl == 4)
{
data[currentbyte + 3] = colorbuffer[3];
}
currentbyte += bytesPerPxl;
currentpixel++;
if(currentpixel > pixelcount)
{
ANKI_LOGE("Too many pixels read");
data.destroy(alloc);
return ErrorCode::USER_DATA;
}
}
}
} while(currentpixel < pixelcount);
return ErrorCode::NONE;
}
示例4: if
//.........这里部分代码省略.........
case ImageLoader::TextureType::_2D:
depthOrLayerCount = 1;
break;
case ImageLoader::TextureType::CUBE:
depthOrLayerCount = 6;
break;
case ImageLoader::TextureType::_3D:
case ImageLoader::TextureType::_2D_ARRAY:
depthOrLayerCount = header.m_depthOrLayerCount;
break;
default:
ANKI_ASSERT(0);
}
textureType = header.m_type;
//
// Move file pointer
//
if(preferredCompression == ImageLoader::DataCompression::RAW)
{
// Do nothing
}
else if(preferredCompression == ImageLoader::DataCompression::S3TC)
{
if((header.m_compressionFormats & ImageLoader::DataCompression::RAW)
!= ImageLoader::DataCompression::NONE)
{
// If raw compression is present then skip it
ANKI_CHECK(file->seek(
calcSizeOfSegment(header, ImageLoader::DataCompression::RAW),
ResourceFile::SeekOrigin::CURRENT));
}
}
else if(preferredCompression == ImageLoader::DataCompression::ETC)
{
if((header.m_compressionFormats & ImageLoader::DataCompression::RAW)
!= ImageLoader::DataCompression::NONE)
{
// If raw compression is present then skip it
ANKI_CHECK(file->seek(
calcSizeOfSegment(header, ImageLoader::DataCompression::RAW),
ResourceFile::SeekOrigin::CURRENT));
}
if((header.m_compressionFormats & ImageLoader::DataCompression::S3TC)
!= ImageLoader::DataCompression::NONE)
{
// If s3tc compression is present then skip it
ANKI_CHECK(file->seek(
calcSizeOfSegment(header, ImageLoader::DataCompression::S3TC),
ResourceFile::SeekOrigin::CURRENT));
}
}
//
// It's time to read
//
// Allocate the surfaces
surfaces.create(alloc, mipLevels * depthOrLayerCount);
// Read all surfaces
U mipWidth = header.m_width;
U mipHeight = header.m_height;
U index = 0;
for(U mip = 0; mip < header.m_mipLevels; mip++)
{
for(U d = 0; d < depthOrLayerCount; d++)
{
U dataSize = calcSurfaceSize(mipWidth,
mipHeight,
preferredCompression,
header.m_colorFormat);
// Check if this mipmap can be skipped because of size
if(max(mipWidth, mipHeight) <= maxTextureSize)
{
ImageLoader::Surface& surf = surfaces[index++];
surf.m_width = mipWidth;
surf.m_height = mipHeight;
surf.m_data.create(alloc, dataSize);
ANKI_CHECK(file->read(&surf.m_data[0], dataSize));
}
else
{
ANKI_CHECK(
file->seek(dataSize, ResourceFile::SeekOrigin::CURRENT));
}
}
mipWidth /= 2;
mipHeight /= 2;
}
return ErrorCode::NONE;
}