SetAdditionalVertexStream: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "<pageclass subcaption="C++ Function"></pageclass> This C++ Function is found inside of CAdditionalVertexStreamManager. It sets an additional vertex stream. It can be fo...")
 
No edit summary
 
Line 11: Line 11:


==Code==
==Code==
<syntaxhighlight lang="c++">
void CAdditionalVertexStreamManager::SetAdditionalVertexStream ( SCurrentStateInfo& state )
void CAdditionalVertexStreamManager::SetAdditionalVertexStream ( SCurrentStateInfo& state )
{
{

Latest revision as of 13:24, 14 May 2017

This C++ Function is found inside of CAdditionalVertexStreamManager.

It sets an additional vertex stream.

It can be found in Client/Client Core/Sources/CAdditionalVertexStreamManager.cpp in Visual Studio.

Required Arguments

  • state: To be defined.

Code

void CAdditionalVertexStreamManager::SetAdditionalVertexStream ( SCurrentStateInfo& state )
{
    HRESULT hr;

    // Get matching custom N vbuffer for std PT vbuffer
    SAdditionalStreamInfo* pAdditionalInfo = GetAdditionalStreamInfo ( state.stream1.pStreamData );
    if ( !pAdditionalInfo )
        pAdditionalInfo = CreateAdditionalStreamInfo ( state );

    uint StridePT = 20;
    uint StrideN = 12;

    // Calc area we are going to use
    uint viMinBased = state.args.MinVertexIndex + state.args.BaseVertexIndex;
    uint viMaxBased = state.args.MinVertexIndex + state.args.NumVertices + state.args.BaseVertexIndex;

    uint ReadOffsetStart = viMinBased * StridePT + state.stream1.OffsetInBytes;
    uint ReadOffsetSize = ( viMaxBased - viMinBased ) * StridePT;

    uint OffsetInBytesN = ConvertPTSize ( state.stream1.OffsetInBytes );
    uint WriteOffsetStart = viMinBased * StrideN + OffsetInBytesN;
    uint WriteOffsetSize = ( viMaxBased - viMinBased ) * StrideN;

    assert ( WriteOffsetStart == ConvertPTSize ( ReadOffsetStart ) );
    assert ( WriteOffsetSize == ConvertPTSize ( ReadOffsetSize ) );

    // See if area VB area needs updating
    if ( !pAdditionalInfo->ConvertedRanges.IsRangeSet ( WriteOffsetStart, WriteOffsetSize ) )
    {
        // Update VB area
        UpdateAdditionalStreamContent ( state, pAdditionalInfo, ReadOffsetStart, ReadOffsetSize, WriteOffsetStart, WriteOffsetSize );
        pAdditionalInfo->ConvertedRanges.SetRange ( WriteOffsetStart, WriteOffsetSize );
    }

    // Save old declaration
    hr = m_pDevice->GetVertexDeclaration ( &m_pOldVertexDeclaration );

    // Set declaration
    hr = g_pProxyDevice->SetVertexDeclaration ( pAdditionalInfo->pVertexDeclaration );

    // Set additional stream
    uint OffsetInBytes = ConvertPTSize ( state.stream1.OffsetInBytes );
    hr = m_pDevice->SetStreamSource ( 2, pAdditionalInfo->pStreamData, OffsetInBytes, pAdditionalInfo->Stride );
}

See Also