本文整理汇总了C++中DynArray::New方法的典型用法代码示例。如果您正苦于以下问题:C++ DynArray::New方法的具体用法?C++ DynArray::New怎么用?C++ DynArray::New使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynArray
的用法示例。
在下文中一共展示了DynArray::New方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void SimpleObjectSortedMapData< KeyT, CompareKeyT, AllocatorT >::Serialize( ArchiveT& archive )
{
DynArray< ObjectPtr > components;
components.Reserve( m_Data->GetSize() * 2 );
{
DataType::ConstIterator itr = m_Data->Begin();
DataType::ConstIterator end = m_Data->End();
for ( ; itr != end; ++itr )
{
ObjectPtr elem = Registry::GetInstance()->CreateInstance( Reflect::GetDataClass< KeyT >() );
Data* ser = AssertCast< Data >( elem.Ptr() );
ser->ConnectData( const_cast< KeyT* >( &itr->First() ) );
HELIUM_VERIFY( components.New( ser ) );
HELIUM_VERIFY( components.New( itr->Second() ) );
}
}
archive.SerializeArray( components );
{
DynArray< ObjectPtr >::Iterator itr = components.Begin();
DynArray< ObjectPtr >::Iterator end = components.End();
for ( ; itr != end; ++itr )
{
Data* ser = AssertCast< Data >( *itr );
ser->Disconnect();
++itr; // Skip over the object reference.
// might be useful to cache the data object here
}
}
}
示例2:
/// Resolve a set of shader preprocessor options from the associated index.
///
/// @param[in] shaderType Type of shader.
/// @param[in] index Option set index.
/// @param[out] rToggleNames List of enabled shader toggles.
/// @param[out] rSelectPairs List shader selection pair values.
void Shader::Options::GetOptionSetFromIndex(
RShader::EType shaderType,
size_t index,
DynArray< Name >& rToggleNames,
DynArray< SelectPair >& rSelectPairs ) const
{
HELIUM_ASSERT( static_cast< size_t >( shaderType ) < static_cast< size_t >( RShader::TYPE_MAX ) );
rToggleNames.Resize( 0 );
rSelectPairs.Resize( 0 );
uint32_t shaderTypeMask = ( 1 << shaderType );
size_t shaderToggleCount = m_toggles.GetSize();
for( size_t shaderToggleIndex = 0; shaderToggleIndex < shaderToggleCount; ++shaderToggleIndex )
{
const Toggle& rShaderToggle = m_toggles[ shaderToggleIndex ];
if( !( rShaderToggle.shaderTypeFlags & shaderTypeMask ) )
{
continue;
}
if( index & 0x1 )
{
HELIUM_VERIFY( rToggleNames.New( rShaderToggle.name ) );
}
index >>= 1;
}
size_t shaderSelectCount = m_selects.GetSize();
for( size_t shaderSelectIndex = 0; shaderSelectIndex < shaderSelectCount; ++shaderSelectIndex )
{
const Select& rShaderSelect = m_selects[ shaderSelectIndex ];
if( !( rShaderSelect.shaderTypeFlags & shaderTypeMask ) )
{
continue;
}
const DynArray< Name >& rShaderSelectChoices = rShaderSelect.choices;
size_t shaderSelectChoiceCount = rShaderSelectChoices.GetSize();
size_t selectIndexMultiplier = shaderSelectChoiceCount + rShaderSelect.bOptional;
size_t selectIndex = index % selectIndexMultiplier;
index /= selectIndexMultiplier;
if( !rShaderSelect.bOptional || selectIndex != shaderSelectChoiceCount )
{
SelectPair* pSelectPair = rSelectPairs.New();
HELIUM_ASSERT( pSelectPair );
pSelectPair->name = rShaderSelect.name;
pSelectPair->choice = rShaderSelectChoices[ selectIndex ];
}
}
}
示例3:
void SimpleSortedSetData< KeyT, CompareKeyT, AllocatorT >::Serialize( ArchiveT& archive )
{
DynArray< ObjectPtr > components;
components.Reserve( m_Data->GetSize() );
{
DataType::ConstIterator itr = m_Data->Begin();
DataType::ConstIterator end = m_Data->End();
for ( ; itr != end; ++itr )
{
ObjectPtr dataElem = Registry::GetInstance()->CreateInstance( Reflect::GetDataClass< KeyT >() );
// downcast to data type
Data* dataSer = AssertCast< Data >( dataElem );
// connect to our map data memory address
dataSer->ConnectData( const_cast< KeyT* >( &( *itr ) ) );
// serialize to the archive stream
HELIUM_VERIFY( components.New( dataSer ) );
}
}
archive.SerializeArray( components );
DynArray< ObjectPtr >::Iterator itr = components.Begin();
DynArray< ObjectPtr >::Iterator end = components.End();
for ( ; itr != end; ++itr )
{
Data* ser = AssertCast< Data >( *itr );
ser->Disconnect();
// might be useful to cache the data object here
}
}
示例4: CompressTexture
/// Compress a font texture sheet and add the texture data to the given texture sheet array.
///
/// @param[in] pGrayscaleData Texture sheet data, stored as a contiguous array of 8-bit grayscale values.
/// @param[in] textureWidth Width of the texture sheet.
/// @param[in] textureHeight Height of the texture sheet.
/// @param[in] compression Font texture sheet compression method to use.
/// @param[in] rTextureSheets Array of texture sheets to which the texture data should be appended.
void FontResourceHandler::CompressTexture(
const uint8_t* pGrayscaleData,
uint16_t textureWidth,
uint16_t textureHeight,
Font::ECompression compression,
DynArray< DynArray< uint8_t > >& rTextureSheets )
{
HELIUM_ASSERT( pGrayscaleData );
DynArray< uint8_t >* pOutputSheet = rTextureSheets.New();
HELIUM_ASSERT( pOutputSheet );
// If the output is to be uncompressed grayscale data, simply copy the data to the output texture, as it's already
// uncompressed grayscale data.
if( compression == Font::ECompression::GRAYSCALE_UNCOMPRESSED )
{
size_t pixelCount = static_cast< size_t >( textureWidth ) * static_cast< size_t >( textureHeight );
pOutputSheet->AddArray( pGrayscaleData, pixelCount );
return;
}
// Convert the source image to a 32-bit BGRA image for the NVIDIA texture tools library to process.
Image::InitParameters imageParameters;
imageParameters.format.SetBytesPerPixel( 4 );
imageParameters.format.SetChannelBitCount( Image::CHANNEL_RED, 8 );
imageParameters.format.SetChannelBitCount( Image::CHANNEL_GREEN, 8 );
imageParameters.format.SetChannelBitCount( Image::CHANNEL_BLUE, 8 );
imageParameters.format.SetChannelBitCount( Image::CHANNEL_ALPHA, 8 );
#if HELIUM_ENDIAN_LITTLE
imageParameters.format.SetChannelBitOffset( Image::CHANNEL_RED, 16 );
imageParameters.format.SetChannelBitOffset( Image::CHANNEL_GREEN, 8 );
imageParameters.format.SetChannelBitOffset( Image::CHANNEL_BLUE, 0 );
imageParameters.format.SetChannelBitOffset( Image::CHANNEL_ALPHA, 24 );
#else
imageParameters.format.SetChannelBitOffset( Image::CHANNEL_RED, 8 );
imageParameters.format.SetChannelBitOffset( Image::CHANNEL_GREEN, 16 );
imageParameters.format.SetChannelBitOffset( Image::CHANNEL_BLUE, 24 );
imageParameters.format.SetChannelBitOffset( Image::CHANNEL_ALPHA, 0 );
#endif
imageParameters.width = textureWidth;
imageParameters.height = textureHeight;
Image bgraImage;
HELIUM_VERIFY( bgraImage.Initialize( imageParameters ) );
uint_fast32_t imageWidth = textureWidth;
uint_fast32_t imageHeight = textureHeight;
uint_fast32_t imagePitch = bgraImage.GetPitch();
uint8_t* pImagePixelData = static_cast< uint8_t* >( bgraImage.GetPixelData() );
HELIUM_ASSERT( pImagePixelData );
uint8_t* pImageRow = pImagePixelData;
for( uint_fast32_t imageY = 0; imageY < imageHeight; ++imageY )
{
uint8_t* pOutputPixel = pImageRow;
for( uint_fast32_t imageX = 0; imageX < imageWidth; ++imageX )
{
uint8_t pixel = *( pGrayscaleData++ );
*( pOutputPixel++ ) = pixel;
*( pOutputPixel++ ) = pixel;
*( pOutputPixel++ ) = pixel;
*( pOutputPixel++ ) = 0xff;
}
pImageRow += imagePitch;
}
// Set up the input options for the texture compressor.
nvtt::InputOptions inputOptions;
inputOptions.setTextureLayout( nvtt::TextureType_2D, textureWidth, textureHeight );
inputOptions.setMipmapData( pImagePixelData, textureWidth, textureHeight );
inputOptions.setMipmapGeneration( false );
inputOptions.setWrapMode( nvtt::WrapMode_Repeat );
inputOptions.setGamma( 1.0f, 1.0f );
inputOptions.setNormalMap( false );
// Set up the output options for the texture compressor.
MemoryTextureOutputHandler outputHandler( textureWidth, textureHeight, false, false );
nvtt::OutputOptions outputOptions;
outputOptions.setOutputHandler( &outputHandler );
outputOptions.setOutputHeader( false );
// Set up the compression options for the texture compressor (note that the only compression option we currently
// support other than uncompressed grayscale is BC1/DXT1).
nvtt::CompressionOptions compressionOptions;
compressionOptions.setFormat( nvtt::Format_BC1 );
compressionOptions.setQuality( nvtt::Quality_Normal );
//.........这里部分代码省略.........
示例5: CacheResource
/// @copydoc ResourceHandler::CacheResource()
bool FontResourceHandler::CacheResource(
ObjectPreprocessor* pObjectPreprocessor,
Resource* pResource,
const String& rSourceFilePath )
{
HELIUM_ASSERT( pObjectPreprocessor );
HELIUM_ASSERT( pResource );
Font* pFont = Reflect::AssertCast< Font >( pResource );
// Load the font into memory ourselves in order to make sure we properly support Unicode file names.
FileStream* pFileStream = File::Open( rSourceFilePath, FileStream::MODE_READ );
if( !pFileStream )
{
HELIUM_TRACE(
TRACE_ERROR,
TXT( "FontResourceHandler: Source file for font resource \"%s\" failed to open properly.\n" ),
*rSourceFilePath );
return false;
}
uint64_t fileSize64 = static_cast< uint64_t >( pFileStream->GetSize() );
if( fileSize64 > SIZE_MAX )
{
HELIUM_TRACE(
TRACE_ERROR,
( TXT( "FontResourceHandler: Font file \"%s\" exceeds the maximum addressable size of data in memory for " )
TXT( "this platform and will not be cached.\n" ) ),
*rSourceFilePath );
delete pFileStream;
return false;
}
size_t fileSize = static_cast< size_t >( fileSize64 );
uint8_t* pFileData = new uint8_t [ fileSize ];
if( !pFileData )
{
HELIUM_TRACE(
TRACE_ERROR,
( TXT( "FontResourceHandler: Failed to allocate %" ) TPRIuSZ TXT( " bytes for resource data for font " )
TXT( "\"%s\".\n" ) ),
fileSize,
*rSourceFilePath );
delete pFileStream;
return false;
}
size_t bytesRead = pFileStream->Read( pFileData, 1, fileSize );
delete pFileStream;
if( bytesRead != fileSize )
{
HELIUM_TRACE(
TRACE_WARNING,
( TXT( "FontResourceHandler: Attempted to read %" ) TPRIuSZ TXT( " bytes from font resource file \"%s\", " )
TXT( "but only %" ) TPRIuSZ TXT( " bytes were read successfully.\n" ) ),
fileSize,
*rSourceFilePath,
bytesRead );
}
// Create the font face.
FT_Library pLibrary = GetStaticLibrary();
HELIUM_ASSERT( pLibrary );
FT_Face pFace = NULL;
FT_Error error = FT_New_Memory_Face( pLibrary, pFileData, static_cast< FT_Long >( bytesRead ), 0, &pFace );
if( error != 0 )
{
HELIUM_TRACE(
TRACE_ERROR,
TXT( "FontResourceHandler: Failed to create font face from resource file \"%s\".\n" ),
*rSourceFilePath );
delete [] pFileData;
return false;
}
// Set the appropriate font size.
int32_t pointSize = Font::Float32ToFixed26x6( pFont->GetPointSize() );
uint32_t dpi = pFont->GetDpi();
error = FT_Set_Char_Size( pFace, pointSize, pointSize, dpi, dpi );
if( error != 0 )
{
HELIUM_TRACE(
TRACE_ERROR,
TXT( "FontResourceHandler: Failed to set size of font resource \"%s\".\n" ),
*rSourceFilePath );
FT_Done_Face( pFace );
delete [] pFileData;
//.........这里部分代码省略.........
示例6: SynchronizeShaderParameters
//.........这里部分代码省略.........
{
for( parameterIndex = 0; parameterIndex < existingFloat3Count; ++parameterIndex )
{
const Float3Parameter& rExistingParameter = m_float3Parameters[ parameterIndex ];
if( rExistingParameter.name == constantName )
{
newValue.SetElement( 0, rExistingParameter.value.GetElement( 0 ) );
newValue.SetElement( 1, rExistingParameter.value.GetElement( 1 ) );
newValue.SetElement( 2, rExistingParameter.value.GetElement( 2 ) );
break;
}
}
if( parameterIndex >= existingFloat3Count )
{
for( parameterIndex = 0; parameterIndex < existingFloat4Count; ++parameterIndex )
{
const Float4Parameter& rExistingParameter =
m_float4Parameters[ parameterIndex ];
if( rExistingParameter.name == constantName )
{
newValue = rExistingParameter.value;
break;
}
}
}
}
}
if( constantSize < sizeof( float32_t ) * 2 )
{
Float1Parameter* pParameter = newFloat1Parameters.New();
HELIUM_ASSERT( pParameter );
pParameter->name = constantName;
pParameter->value = newValue.GetElement( 0 );
}
else if( constantSize < sizeof( float32_t ) * 3 )
{
Float2Parameter* pParameter = newFloat2Parameters.New();
HELIUM_ASSERT( pParameter );
pParameter->name = constantName;
pParameter->value = Simd::Vector2( newValue.GetElement( 0 ), newValue.GetElement( 1 ) );
}
else if( constantSize < sizeof( float32_t ) * 4 )
{
Float3Parameter* pParameter = newFloat3Parameters.New();
HELIUM_ASSERT( pParameter );
pParameter->name = constantName;
pParameter->value =
Simd::Vector3( newValue.GetElement( 0 ), newValue.GetElement( 1 ), newValue.GetElement( 2 ) );
}
else
{
Float4Parameter* pParameter = newFloat4Parameters.New();
HELIUM_ASSERT( pParameter );
pParameter->name = constantName;
pParameter->value = newValue;
}
}
}
}
newFloat1Parameters.Trim();
newFloat2Parameters.Trim();