-------------------------------------------------------------------------------------- Description: Rebuilds D3D vertex declaration. --------------------------------------------------------------------------------------
| 882 | // Rebuilds D3D vertex declaration. |
| 883 | // -------------------------------------------------------------------------------------- |
| 884 | void Tr2ParticleSystem::RebuildDeclaration() |
| 885 | { |
| 886 | Tr2VertexDefinition vd; |
| 887 | |
| 888 | for( auto it = m_elementMap.begin(); it != m_elementMap.end(); ++it ) |
| 889 | { |
| 890 | //Skip things we don't want to upload to the GPU |
| 891 | if( it->second.m_bufferType != Tr2ParticleElementData::GPU ) |
| 892 | { |
| 893 | continue; |
| 894 | } |
| 895 | |
| 896 | Tr2VertexDefinition::Item item; |
| 897 | item.m_stream = 0; |
| 898 | item.m_offset = it->second.m_offset * sizeof( float ); |
| 899 | item.m_dataType = static_cast<Tr2VertexDefinition::DataType>( vd.DT_FLOAT32 + ( ( it->second.m_dimension - 1 ) << vd.DT_SIZE_OFFSET ) ); |
| 900 | item.m_usage = it->first.GetD3DUsage(); |
| 901 | |
| 902 | item.m_usageIndex = it->first.m_type == Tr2ParticleElementDeclarationName::CUSTOM ? it->second.m_usageIndex : 0; |
| 903 | |
| 904 | vd.m_items.push_back( item ); |
| 905 | vd.m_nextOffset[0] = std::max( vd.m_nextOffset[0], item.m_offset + vd.GetDataTypeSizeInBytes( item.m_dataType ) ); |
| 906 | |
| 907 | /* |
| 908 | Since we need to upload both the current and previous frame's data, |
| 909 | we duplicate the vertex attributes with an offset. This allows the shader to access |
| 910 | both the current data and the previous data simultaneously. |
| 911 | |
| 912 | Since CUSTOM vertex attributes can't be updated, we only need to duplicate the non-CUSTOM |
| 913 | attributes. However, for simplicity, all the previous frame particle GPU data is tracked, |
| 914 | so this could be added in the future if necessary. |
| 915 | */ |
| 916 | |
| 917 | if( it->first.m_type != Tr2ParticleElementDeclarationName::CUSTOM ) |
| 918 | { |
| 919 | item.m_usageIndex = 1; |
| 920 | item.m_offset += m_vertexSizes[Tr2ParticleElementData::GPU] * sizeof( float ) / 2; |
| 921 | |
| 922 | vd.m_items.push_back( item ); |
| 923 | vd.m_nextOffset[0] = std::max( vd.m_nextOffset[0], item.m_offset + vd.GetDataTypeSizeInBytes( item.m_dataType ) ); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | m_declaration = Tr2EffectStateManager::GetVertexDeclarationHandle( vd ); |
| 928 | } |
| 929 | |
| 930 | // -------------------------------------------------------------------------------------- |
| 931 | // Description: |
nothing calls this directly
no test coverage detected