⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dxuteffectmap.cpp

📁 在GPU上实现数值模拟技术(线性方程组)的通用架构
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        CGrowableArray<ParamList>* pBindings = &m_Bindings[ eSemantic ][ eObject ][ index ];
        
        bool bBound = false;
        for( int i=0; i < pBindings->GetSize(); i++ )
        {
            if( pBindings->GetAt(i).pEffect == pEffect )
            {
                // Found the containing effect for this parameter in the list, add the new handle
                pBindings->GetAt(i).ahParameters.Add( hParameter );
                bBound = true;
                break;
            }
        }

        if( !bBound )
        {
            // This parameter belongs to a new effect
            ParamList newParamList;
            newParamList.pEffect = pEffect;
			pEffect->AddRef();
            newParamList.ahParameters.Add( hParameter );
            pBindings->Add( newParamList );
        }
       
    }
    
    return S_OK;
}


//-------------------------------------------------------------------------------------
// Removes all instances of this effect from the binding list
//-------------------------------------------------------------------------------------
HRESULT CDXUTEffectMap::RemoveEffect( ID3DXEffect* pEffect )
{
	if( pEffect == NULL )
		return E_INVALIDARG;

	// Search through the list of registered semantics and remove all items
	// assigned to the given effect
	for( UINT iSemantic = 0; iSemantic < NUM_DXUT_SEMANTICS; iSemantic++ )
	{
		for( UINT iObject = 0; iObject < NUM_DXUT_OBJECTS; iObject++ )
		{
			for( UINT iIndex = 0; iIndex < MAX_INDEX; iIndex++ )
			{
				CGrowableArray<ParamList>* pBinding = &m_Bindings[ iSemantic ][ iObject ][ iIndex ];

				// Clear nested arrays first
				for( int iParamList = 0; iParamList < pBinding->GetSize(); iParamList++ )
				{
					ParamList& rParamList = pBinding->GetAt( iParamList );

					if( rParamList.pEffect == pEffect )
						rParamList.Reset();
				}
			}
		}
	}

	return S_OK;
}


//-------------------------------------------------------------------------------------
HRESULT CDXUTEffectMap::SetWorldMatrix( D3DXMATRIXA16* pWorldMatrix, const WCHAR* strUnits )
{
    m_matWorld = *pWorldMatrix;
    return UpdateTransforms( DXUT_World );
}


//-------------------------------------------------------------------------------------
HRESULT CDXUTEffectMap::SetViewMatrix( D3DXMATRIXA16* pViewMatrix, const WCHAR* strUnits )
{
    m_matView = *pViewMatrix;
    return UpdateTransforms( DXUT_View );
}


//-------------------------------------------------------------------------------------
HRESULT CDXUTEffectMap::SetProjectionMatrix( D3DXMATRIXA16* pProjectionMatrix )
{
    m_matProjection = *pProjectionMatrix;
    return UpdateTransforms( DXUT_Projection );
}


//-------------------------------------------------------------------------------------
HRESULT CDXUTEffectMap::UpdateTransforms( DXUT_SEMANTIC eSemantic, const WCHAR* strUnits )
{
    HRESULT hr;

    // Determine which transforms are required by the effect
    bool bEffectContains[ NUM_DXUT_SEMANTICS ] = {0};
    for( int iTransform = DXUT_World; iTransform <= DXUT_ProjectionInverseTranspose; iTransform++ )
    {
        bEffectContains[iTransform] = ( m_Bindings[ iTransform ][ DXUT_Geometry ][ 0 ].GetSize() > 0 );
    }

    if( eSemantic == DXUT_World )
    {
        // World matrix permutations
        if( bEffectContains[ DXUT_World ] ||
            bEffectContains[ DXUT_WorldInverse ] ||
            bEffectContains[ DXUT_WorldInverseTranspose ] )
        {
            V_RETURN( SetStandardParameter( DXUT_World, DXUT_Geometry, 0, (float*)&m_matWorld, 16, L"", strUnits, L"World" ) );

            if( bEffectContains[ DXUT_WorldInverse ] ||
                bEffectContains[ DXUT_WorldInverseTranspose ] )
            {
                D3DXMATRIXA16 matWorldInverse;
                D3DXMatrixInverse( &matWorldInverse, NULL, &m_matWorld );
                V_RETURN( SetStandardParameter( DXUT_WorldInverse, DXUT_Geometry, 0, (float*)&matWorldInverse, 16, L"", strUnits, L"World" ) );
            
                if( bEffectContains[ DXUT_WorldInverseTranspose ] )
                {
                    D3DXMATRIXA16 matWorldInverseTranspose;
                    D3DXMatrixTranspose( &matWorldInverseTranspose, &matWorldInverse );
                    V_RETURN( SetStandardParameter( DXUT_WorldInverseTranspose, DXUT_Geometry, 0, (float*)&matWorldInverseTranspose, 16, L"", strUnits, L"World" ) );
                }
            }
        }
    }

    if( eSemantic == DXUT_World ||
        eSemantic == DXUT_View )
    {
        // WorldView matrix permutations
        if( bEffectContains[ DXUT_WorldView ] ||
            bEffectContains[ DXUT_WorldViewInverse ] ||
            bEffectContains[ DXUT_WorldViewInverseTranspose ] )
        {
            D3DXMATRIXA16 matWorldView;
            D3DXMatrixMultiply( &matWorldView, &m_matWorld, &m_matView );
            V_RETURN( SetStandardParameter( DXUT_WorldView, DXUT_Geometry, 0, (float*)&matWorldView, 16, L"", strUnits, L"World" ) );
        
            if( bEffectContains[ DXUT_WorldViewInverse ] ||
                bEffectContains[ DXUT_WorldViewInverseTranspose ] )
            {
                D3DXMATRIXA16 matWorldViewInverse;
                D3DXMatrixInverse( &matWorldViewInverse, NULL, &matWorldView );    
                V_RETURN( SetStandardParameter( DXUT_WorldViewInverse, DXUT_Geometry, 0, (float*)&matWorldViewInverse, 16, L"", strUnits, L"World" ) );
            
                if( bEffectContains[ DXUT_WorldViewInverseTranspose ] )
                {
                    D3DXMATRIXA16 matWorldViewInverseTranspose;
                    D3DXMatrixTranspose( &matWorldViewInverseTranspose, &matWorldViewInverse );
                    V_RETURN( SetStandardParameter( DXUT_WorldViewInverseTranspose, DXUT_Geometry, 0, (float*)&matWorldViewInverseTranspose, 16, L"", strUnits, L"World" ) );
                }
            }
        }
    }

    if( eSemantic == DXUT_World ||
        eSemantic == DXUT_View ||
        eSemantic == DXUT_Projection )
    {
        // WorldViewProjection matrix permutations
        if( bEffectContains[ DXUT_WorldViewProjection ] ||
            bEffectContains[ DXUT_WorldViewProjectionInverse ] ||
            bEffectContains[ DXUT_WorldViewProjectionInverseTranspose ] )
        {
            D3DXMATRIXA16 matWorldViewProjection;
            D3DXMatrixMultiply( &matWorldViewProjection, &m_matWorld, &m_matView );
            D3DXMatrixMultiply( &matWorldViewProjection, &matWorldViewProjection, &m_matProjection );

            V_RETURN( SetStandardParameter( DXUT_WorldViewProjection, DXUT_Geometry, 0, (float*)&matWorldViewProjection, 16, L"", strUnits, L"World" ) );
        
            if( bEffectContains[ DXUT_WorldViewProjectionInverse ] ||
                bEffectContains[ DXUT_WorldViewProjectionInverseTranspose ] )
            {
                D3DXMATRIXA16 matWorldViewProjectionInverse;
                D3DXMatrixInverse( &matWorldViewProjectionInverse, NULL, &matWorldViewProjection );    
                V_RETURN( SetStandardParameter( DXUT_WorldViewProjectionInverse, DXUT_Geometry, 0, (float*)&matWorldViewProjectionInverse, 16, L"", strUnits, L"World" ) );
            
                if( bEffectContains[ DXUT_WorldViewProjectionInverseTranspose ] )
                {
                    D3DXMATRIXA16 matWorldViewProjectionInverseTranspose;
                    D3DXMatrixTranspose( &matWorldViewProjectionInverseTranspose, &matWorldViewProjectionInverse );
                    V_RETURN( SetStandardParameter( DXUT_WorldViewProjectionInverseTranspose, DXUT_Geometry, 0, (float*)&matWorldViewProjectionInverseTranspose, 16, L"", strUnits, L"World" ) );
                }
            }
        }
    }

    if( eSemantic == DXUT_View )
    {
        // View matrix permutations
        if( bEffectContains[ DXUT_View ] ||
            bEffectContains[ DXUT_ViewInverse ] ||
            bEffectContains[ DXUT_ViewInverseTranspose ] )
        {
            V_RETURN( SetStandardParameter( DXUT_View, DXUT_Geometry, 0, (float*)&m_matView, 16, L"", strUnits, L"World" ) );

            if( bEffectContains[ DXUT_ViewInverse ] ||
                bEffectContains[ DXUT_ViewInverseTranspose ] )
            {
                D3DXMATRIXA16 matViewInverse;
                D3DXMatrixInverse( &matViewInverse, NULL, &m_matView );
                V_RETURN( SetStandardParameter( DXUT_ViewInverse, DXUT_Geometry, 0, (float*)&matViewInverse, 16, L"", strUnits, L"World" ) );
            
                if( bEffectContains[ DXUT_ViewInverseTranspose ] )
                {
                    D3DXMATRIXA16 matViewInverseTranspose;
                    D3DXMatrixTranspose( &matViewInverseTranspose, &matViewInverse );
                    V_RETURN( SetStandardParameter( DXUT_ViewInverseTranspose, DXUT_Geometry, 0, (float*)&matViewInverseTranspose, 16, L"", strUnits, L"World" ) );
                }
            }
        }
    }

    if( eSemantic == DXUT_View ||
        eSemantic == DXUT_Projection )
    {
        // ViewProjection matrix permutations
        if( bEffectContains[ DXUT_ViewProjection ] ||
            bEffectContains[ DXUT_ViewProjectionInverse ] ||
            bEffectContains[ DXUT_ViewProjectionInverseTranspose ] )
        {
            D3DXMATRIXA16 matViewProjection;
            D3DXMatrixMultiply( &matViewProjection, &m_matView, &m_matProjection );
            V_RETURN( SetStandardParameter( DXUT_ViewProjection, DXUT_Geometry, 0, (float*)&matViewProjection, 16, L"", strUnits, L"World" ) );
        
            if( bEffectContains[ DXUT_ViewProjectionInverse ] ||
                bEffectContains[ DXUT_ViewProjectionInverseTranspose ] )
            {
                D3DXMATRIXA16 matViewProjectionInverse;
                D3DXMatrixInverse( &matViewProjectionInverse, NULL, &matViewProjection );    
                V_RETURN( SetStandardParameter( DXUT_ViewProjectionInverse, DXUT_Geometry, 0, (float*)&matViewProjectionInverse, 16, L"", strUnits, L"World" ) );
            
                if( bEffectContains[ DXUT_ViewProjectionInverseTranspose ] )
                {
                    D3DXMATRIXA16 matViewProjectionInverseTranspose;
                    D3DXMatrixTranspose( &matViewProjectionInverseTranspose, &matViewProjectionInverse );
                    V_RETURN( SetStandardParameter( DXUT_ViewProjectionInverseTranspose, DXUT_Geometry, 0, (float*)&matViewProjectionInverseTranspose, 16, L"", strUnits, L"World" ) );
                }
            }
        }
    }

    if( eSemantic == DXUT_Projection )
    {
        // Projection matrix permutations
        if( bEffectContains[ DXUT_Projection ] ||
            bEffectContains[ DXUT_ProjectionInverse ] ||
            bEffectContains[ DXUT_ProjectionInverseTranspose ] )
        {
            V_RETURN( SetStandardParameter( DXUT_Projection, DXUT_Geometry, 0, (float*)&m_matProjection, 16, L"", strUnits, L"World" ) );

            if( bEffectContains[ DXUT_ProjectionInverse ] ||
                bEffectContains[ DXUT_ProjectionInverseTranspose ] )
            {
                D3DXMATRIXA16 matProjectionInverse;
                D3DXMatrixInverse( &matProjectionInverse, NULL, &m_matProjection );
                V_RETURN( SetStandardParameter( DXUT_ProjectionInverse, DXUT_Geometry, 0, (float*)&matProjectionInverse, 16, L"", strUnits, L"World" ) );
            
                if( bEffectContains[ DXUT_ProjectionInverseTranspose ] )
                {
                    D3DXMATRIXA16 matProjectionInverseTranspose;
                    D3DXMatrixTranspose( &matProjectionInverseTranspose, &matProjectionInverse );
                    V_RETURN( SetStandardParameter( DXUT_ProjectionInverseTranspose, DXUT_Geometry, 0, (float*)&matProjectionInverseTranspose, 16, L"", strUnits, L"World" ) );
                }
            }
        }
    }

    return S_OK;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -