当前位置: 首页>>代码示例>>C++>>正文


C++ DynamicArray::create方法代码示例

本文整理汇总了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;
}
开发者ID:pathscale,项目名称:freepooma-testsuite,代码行数:30,代码来源:dynamic_array_badcreate.C

示例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;
}
开发者ID:Al1a123,项目名称:anki-3d-engine,代码行数:40,代码来源:ImageLoader.cpp

示例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;
}
开发者ID:Al1a123,项目名称:anki-3d-engine,代码行数:93,代码来源:ImageLoader.cpp

示例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;
}
开发者ID:Al1a123,项目名称:anki-3d-engine,代码行数:101,代码来源:ImageLoader.cpp


注:本文中的DynamicArray::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。