Пример #1
0
//-------------------------------------------------------------------------------------
// 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;
}
Пример #2
0
//-------------------------------------------------------------------------------------
HRESULT CDXUTEffectMap::SetStandardParameter( DXUT_SEMANTIC eSemantic, 
                                         DXUT_OBJECT eObject, 
                                         DWORD dwObjectIndex, 
                                         float* pData, 
                                         DWORD dwDataLen, 
                                         const WCHAR* strType, 
                                         const WCHAR* strUnits, 
                                         const WCHAR* strSpace )
{
    HRESULT hr;

    // TODO: remove index limits
    if( dwObjectIndex >= MAX_INDEX )
        return E_INVALIDARG;

    // TODO: handle unit and space conversions

    // Retrieve the interested handles
    CGrowableArray<ParamList>* pBindings = &m_Bindings[ eSemantic ][ eObject ][ dwObjectIndex ];
        
    for( int iList=0; iList < pBindings->GetSize(); iList++ )
    {
        ParamList& paramList = pBindings->GetAt(iList);

        for( int iParam=0; iParam < paramList.ahParameters.GetSize(); iParam++ )
        {
            V_RETURN( paramList.pEffect->SetFloatArray( paramList.ahParameters[iParam], pData, dwDataLen ) );
        }
    }

    return S_OK;
}
Пример #3
0
//-------------------------------------------------------------------------------------
VOID CDXUTEffectMap::Reset()
{
	D3DXMatrixIdentity( &m_matWorld );
    D3DXMatrixIdentity( &m_matView );
    D3DXMatrixIdentity( &m_matProjection );

	// Reset all the stored parameter lists
	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++ )
				{
					pBinding->GetAt( iParamList ).Reset();
				}
				
				// Remove all the bound parameter lists
				pBinding->RemoveAll();
			}
		}
	}
}
Пример #4
0
//--------------------------------------------------------------------------------------
// RenderTerrain
//--------------------------------------------------------------------------------------
void RenderTerrain( ID3D10Device* pd3dDevice )
{
    D3DXMATRIX mWorld;
    D3DXMatrixIdentity( &mWorld );

    D3DXVECTOR3 vEye;
    D3DXVECTOR3 vDir;
    D3DXMATRIX mCamWorld;
    D3DXMATRIX mView;
    D3DXMATRIX mProj;
    GetCameraData( &mCamWorld, &mView, &mProj, &vEye, &vDir );
    D3DXMATRIX mWVP = mCamWorld * mView * mProj;

    pd3dDevice->IASetInputLayout( g_pBasicDecl10 );

    g_pmWorldViewProj->SetMatrix( ( float* )&mWVP );
    g_pmWorld->SetMatrix( ( float* )&mWorld );

    g_ptxNormal->SetResource( g_pNormalTexRV );
    g_ptxDirt->SetResource( g_pDirtTexRV );
    g_ptxGrass->SetResource( g_pGroundGrassTexRV );
    g_ptxMask->SetResource( g_pMaskTexRV );

    if( !g_bShowTiles )
    {
        D3DXVECTOR4 color( 1,1,1,1 );
        g_pvColor->SetFloatVector( ( float* )&color );
    }

    pd3dDevice->IASetIndexBuffer( g_Terrain.GetTerrainIB10(), DXGI_FORMAT_R16_UINT, 0 );

    D3D10_TECHNIQUE_DESC techDesc;
    g_pRenderTerrain->GetDesc( &techDesc );

    for( UINT p = 0; p < techDesc.Passes; ++p )
    {
        // Render front to back
        UINT NumTiles = g_VisibleTileArray.GetSize();
        SetNumVisibleTiles( NumTiles );
        for( UINT i = 0; i < NumTiles; i++ )
        {
            TERRAIN_TILE* pTile = g_Terrain.GetTile( g_VisibleTileArray.GetAt( i ) );

            if( g_bShowTiles )
            {
                g_pvColor->SetFloatVector( ( float* )&pTile->Color );
            }
            g_pRenderTerrain->GetPassByIndex( p )->Apply( 0 );

            g_Terrain.RenderTile( pTile );
        }
    }
}
Пример #5
0
//-------------------------------------------------------------------------------------
// Investigates all the parameters, looking at semantics and annotations and placing 
// handles to these parameters within the internal database.
//-------------------------------------------------------------------------------------
HRESULT CDXUTEffectMap::AddEffect( ID3DXEffect* pEffect )
{
    HRESULT hr;

	if( pEffect == NULL )
		return E_INVALIDARG;

    // Get the number of parameters
    D3DXEFFECT_DESC descEffect;
    V_RETURN( pEffect->GetDesc( &descEffect ) );
    
    // Enumerate the parameters
    for( UINT iParam=0; iParam < descEffect.Parameters; iParam++ )
    {
        // Retrieve param
        D3DXHANDLE hParameter = pEffect->GetParameter( NULL, iParam );
        if( NULL == hParameter )
            return E_FAIL;

        // Grab description
        D3DXPARAMETER_DESC desc;
        V_RETURN( pEffect->GetParameterDesc( hParameter, &desc ) );

        // If this parameter doesn't have a semantic, skip to the next parameter
        if( desc.Semantic == NULL )
            continue;

        // Map the semantic to the standard set
        DXUT_SEMANTIC eSemantic = StringToSemantic( desc.Semantic );
        if( eSemantic == DXUT_UNKNOWN_SEMANTIC )
            continue;

        // Get the object annotation
        const char* cstrObject = "Geometry";
        D3DXHANDLE hAnnotation = pEffect->GetAnnotationByName( hParameter, "Object" );
        if( hAnnotation )
        {
            V_RETURN( pEffect->GetString( hAnnotation, &cstrObject ) );
        }

        // Map the object to the standard set
        DXUT_OBJECT eObject = StringToObject( cstrObject );
        if( eObject == DXUT_UNKNOWN_OBJECT )
            continue;

        // Extract the index from the semantic
        int index = 0;
        const char* strIndex = desc.Semantic + strlen(desc.Semantic)-1;

        // If there is a digit at the end of the semantic, locate the beginning of the index
        // and convert to an integer
        if( isdigit( (BYTE) (*strIndex) ) )
        {
            while( isdigit( (BYTE) (*(strIndex-1)) ) )
            {
                --strIndex;
            }

            index = atoi( strIndex );
        }

        // Check whether index is out of bounds
        if( index < 0 || index >= MAX_INDEX )
            continue;

        // Store the handle
        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;
}