本文整理汇总了C++中Shader::BeginLoadVariant方法的典型用法代码示例。如果您正苦于以下问题:C++ Shader::BeginLoadVariant方法的具体用法?C++ Shader::BeginLoadVariant怎么用?C++ Shader::BeginLoadVariant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Shader
的用法示例。
在下文中一共展示了Shader::BeginLoadVariant方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: BeginPrecacheResourceData
/// @copydoc GameObject::BeginPrecacheResourceData()
bool Material::BeginPrecacheResourceData()
{
#if HELIUM_TOOLS
// Convert shader options to variant indices if we just loaded a set of options.
if( m_bLoadedOptions )
{
MemoryZero( m_persistentResourceData.m_shaderVariantIndices, sizeof( m_persistentResourceData.m_shaderVariantIndices ) );
Shader* pShader = m_spShader;
if( pShader )
{
const Shader::Options& rUserOptions = pShader->GetUserOptions();
for( size_t shaderTypeIndex = 0;
shaderTypeIndex < HELIUM_ARRAY_COUNT( m_persistentResourceData.m_shaderVariantIndices );
++shaderTypeIndex )
{
m_persistentResourceData.m_shaderVariantIndices[ shaderTypeIndex ] = static_cast< uint32_t >( rUserOptions.GetOptionSetIndex(
static_cast< RShader::EType >( shaderTypeIndex ),
m_userOptions.GetData(),
m_userOptions.GetSize() ) );
}
}
m_userOptions.Clear();
m_bLoadedOptions = false;
}
#endif
// Preload shader variant resources.
Shader* pShader = m_spShader;
if( !pShader )
{
for( size_t shaderTypeIndex = 0; shaderTypeIndex < HELIUM_ARRAY_COUNT( m_shaderVariants ); ++shaderTypeIndex )
{
HELIUM_ASSERT( IsInvalid( m_shaderVariantLoadIds[ shaderTypeIndex ] ) );
m_shaderVariants[ shaderTypeIndex ].Release();
}
}
else
{
for( size_t shaderTypeIndex = 0; shaderTypeIndex < HELIUM_ARRAY_COUNT( m_shaderVariants ); ++shaderTypeIndex )
{
HELIUM_ASSERT( IsInvalid( m_shaderVariantLoadIds[ shaderTypeIndex ] ) );
m_shaderVariantLoadIds[ shaderTypeIndex ] = pShader->BeginLoadVariant(
static_cast< RShader::EType >( shaderTypeIndex ),
m_persistentResourceData.m_shaderVariantIndices[ shaderTypeIndex ] );
}
}
// Preload the constant buffers for shader parameters.
Renderer* pRenderer = Renderer::GetStaticInstance();
if( pRenderer )
{
for( size_t shaderTypeIndex = 0; shaderTypeIndex < HELIUM_ARRAY_COUNT( m_constantBuffers ); ++shaderTypeIndex )
{
HELIUM_ASSERT( !m_constantBuffers[ shaderTypeIndex ] );
HELIUM_ASSERT( IsInvalid( m_constantBufferLoadIds[ shaderTypeIndex ] ) );
size_t bufferSize = GetSubDataSize( static_cast< uint32_t >( shaderTypeIndex ) );
if( bufferSize == 0 )
{
continue;
}
RConstantBufferPtr spBuffer = pRenderer->CreateConstantBuffer(
bufferSize,
RENDERER_BUFFER_USAGE_STATIC );
if( !spBuffer )
{
HELIUM_TRACE(
TraceLevels::Error,
( TXT( "Material::BeginPrecacheResourceData(): Failed to allocate constant buffer of %" )
TPRIuSZ TXT( " bytes for parameter usage for material \"%s\".\n" ) ),
bufferSize,
*GetPath().ToString() );
continue;
}
void* pBufferData = spBuffer->Map();
if( !pBufferData )
{
HELIUM_TRACE(
TraceLevels::Error,
( TXT( "Material::BeginPrecacheResourceData(): Failed to map constant buffer data for " )
TXT( "material \"%s\".\n" ) ),
*GetPath().ToString() );
continue;
}
size_t loadId = BeginLoadSubData( pBufferData, static_cast< uint32_t >( shaderTypeIndex ) );
if( IsInvalid( loadId ) )
{
HELIUM_TRACE(
TraceLevels::Error,
( TXT( "Material::BeginPrecacheResourceData(): Failed to begin loading resource sub-data %" )
//.........这里部分代码省略.........
示例2: CacheResource
/// @copydoc ResourceHandler::CacheResource()
bool MaterialResourceHandler::CacheResource(
AssetPreprocessor* pAssetPreprocessor,
Resource* pResource,
const String& /*rSourceFilePath*/ )
{
HELIUM_ASSERT( pAssetPreprocessor );
HELIUM_ASSERT( pResource );
Material* pMaterial = Reflect::AssertCast< Material >( pResource );
Shader* pShader = pMaterial->GetShader();
bool failedToWriteASubdata = false;
StrongPtr< Material::PersistentResourceData > resource_data( new Material::PersistentResourceData() );
// Compute the shader variant indices from the user options selected in the material, as the array of indices in
// the material is not yet initialized.
//uint32_t shaderVariantIndices[ RShader::TYPE_MAX ];
if( pShader )
{
const Shader::Options& rShaderUserOptions = pShader->GetUserOptions();
const DynamicArray< Shader::SelectPair >& rMaterialUserOptions = pMaterial->GetUserOptions();
for( size_t shaderTypeIndex = 0; shaderTypeIndex < RShader::TYPE_MAX; ++shaderTypeIndex )
{
size_t optionSetIndex = rShaderUserOptions.GetOptionSetIndex(
static_cast< RShader::EType >( shaderTypeIndex ),
rMaterialUserOptions.GetData(),
rMaterialUserOptions.GetSize() );
resource_data->m_shaderVariantIndices[ shaderTypeIndex ] = static_cast< uint32_t >( optionSetIndex );
}
}
else
{
MemoryZero( resource_data->m_shaderVariantIndices, sizeof( resource_data->m_shaderVariantIndices ) );
}
size_t float1ParameterCount = pMaterial->GetFloat1ParameterCount();
size_t float2ParameterCount = pMaterial->GetFloat2ParameterCount();
size_t float3ParameterCount = pMaterial->GetFloat3ParameterCount();
size_t float4ParameterCount = pMaterial->GetFloat4ParameterCount();
Name parameterConstantBufferName = Material::GetParameterConstantBufferName();
for( size_t platformIndex = 0; platformIndex < static_cast< size_t >( Cache::PLATFORM_MAX ); ++platformIndex )
{
PlatformPreprocessor* pPreprocessor = pAssetPreprocessor->GetPlatformPreprocessor(
static_cast< Cache::EPlatform >( platformIndex ) );
if( !pPreprocessor )
{
continue;
}
Resource::PreprocessedData& rPreprocessedData = pResource->GetPreprocessedData(
static_cast< Cache::EPlatform >( platformIndex ) );
SaveObjectToPersistentDataBuffer(resource_data.Get(), rPreprocessedData.persistentDataBuffer);
rPreprocessedData.bLoaded = true;
// Write out the parameter constant buffer data as the resource sub-data.
size_t shaderProfileCount = pPreprocessor->GetShaderProfileCount();
DynamicArray< DynamicArray< uint8_t > >& rSubDataBuffers = rPreprocessedData.subDataBuffers;
rSubDataBuffers.Clear();
rSubDataBuffers.Reserve( shaderProfileCount * RShader::TYPE_MAX );
rSubDataBuffers.Resize( shaderProfileCount * RShader::TYPE_MAX );
if( pShader )
{
// deserializer.SetByteSwapping( bSwapBytes );
for( size_t shaderTypeIndex = 0; shaderTypeIndex < RShader::TYPE_MAX; ++shaderTypeIndex )
{
RShader::EType shaderType = static_cast< RShader::EType >( shaderTypeIndex );
size_t variantLoadId = pShader->BeginLoadVariant(
shaderType,
resource_data->m_shaderVariantIndices[ shaderTypeIndex ] );
if( IsInvalid( variantLoadId ) )
{
continue;
}
ShaderVariantPtr spVariant;
while( !pShader->TryFinishLoadVariant( variantLoadId, spVariant ) )
{
}
ShaderVariant* pVariant = spVariant;
if( !pVariant )
{
continue;
}
const Resource::PreprocessedData& rVariantData = pVariant->GetPreprocessedData(
static_cast< Cache::EPlatform >( platformIndex ) );
HELIUM_ASSERT( rVariantData.bLoaded );
const DynamicArray< DynamicArray< uint8_t > >& rVariantSubDataBuffers = rVariantData.subDataBuffers;
size_t variantSubDataCount = rVariantSubDataBuffers.GetSize();
HELIUM_ASSERT( variantSubDataCount != 0 );
//.........这里部分代码省略.........
示例3: Initialize
//.........这里部分代码省略.........
vertexElements[1].type = RENDERER_VERTEX_DATA_TYPE_UINT8_4_NORM;
vertexElements[1].semantic = RENDERER_VERTEX_SEMANTIC_COLOR;
vertexElements[1].semanticIndex = 0;
vertexElements[1].bufferIndex = 0;
vertexElements[2].type = RENDERER_VERTEX_DATA_TYPE_FLOAT16_2;
vertexElements[2].semantic = RENDERER_VERTEX_SEMANTIC_TEXCOORD;
vertexElements[2].semanticIndex = 0;
vertexElements[2].bufferIndex = 0;
m_spScreenVertexDescription = pRenderer->CreateVertexDescription( vertexElements, 3 );
HELIUM_ASSERT( m_spScreenVertexDescription );
// Create configuration-dependent render resources.
PostConfigUpdate();
// Attempt to load the depth-only pre-pass shader.
// TODO: XXX TMC: Migrate to a more data-driven solution.
AssetLoader* pAssetLoader = AssetLoader::GetInstance();
HELIUM_ASSERT( pAssetLoader );
#ifdef HELIUM_DIRECT3D
AssetPath prePassShaderPath;
HELIUM_VERIFY( prePassShaderPath.Set( HELIUM_PACKAGE_PATH_CHAR_STRING "Shaders" HELIUM_OBJECT_PATH_CHAR_STRING "PrePass.hlsl" ) );
AssetPtr spPrePassShader;
HELIUM_VERIFY( pAssetLoader->LoadObject( prePassShaderPath, spPrePassShader ) );
Shader* pPrePassShader = Reflect::SafeCast< Shader >( spPrePassShader.Get() );
if ( HELIUM_VERIFY( pPrePassShader ) )
{
size_t loadId = pPrePassShader->BeginLoadVariant( RShader::TYPE_VERTEX, 0 );
HELIUM_ASSERT( IsValid( loadId ) );
if ( IsValid( loadId ) )
{
while ( !pPrePassShader->TryFinishLoadVariant( loadId, m_spPrePassVertexShader ) )
{
pAssetLoader->Tick();
}
}
}
// Attempt to load the simple world-space, simple screen-space, and screen-space text shaders.
// TODO: XXX TMC: Migrate to a more data-driven solution.
AssetPath shaderPath;
HELIUM_VERIFY( shaderPath.Set( HELIUM_PACKAGE_PATH_CHAR_STRING "Shaders" HELIUM_OBJECT_PATH_CHAR_STRING "Simple.hlsl" ) );
AssetPtr spShader;
HELIUM_VERIFY( pAssetLoader->LoadObject( shaderPath, spShader ) );
Shader* pShader = Reflect::SafeCast< Shader >( spShader.Get() );
if ( HELIUM_VERIFY( pShader ) )
{
size_t loadId = pShader->BeginLoadVariant( RShader::TYPE_VERTEX, 0 );
HELIUM_ASSERT( IsValid( loadId ) );
if ( IsValid( loadId ) )
{
while ( !pShader->TryFinishLoadVariant( loadId, m_spSimpleWorldSpaceVertexShader ) )
{
pAssetLoader->Tick();
}
}
loadId = pShader->BeginLoadVariant( RShader::TYPE_PIXEL, 0 );