예제 #1
0
//--------------------------------------------------------------------------------------
HRESULT Effect9::FromSource( IDirect3DDevice9* pDevice, const SourceInfo& sf, const D3DXMACRO* pDefines, ID3DXInclude* pInclude, DWORD flags, Effect9** ppEffectOut )
{
    HRESULT hr;
    hr = S_OK;
    if( NULL == ppEffectOut )
        return E_INVALIDARG;

    // Clear the output parameter
    *ppEffectOut = NULL;

    // Attempt to create the D3DXEffect
    ID3DXEffect* pD3DXEffect = NULL;
    ID3DXBuffer* pErrors = NULL;

    if(sf.GetSourceType() == SOURCEINFO_RESOURCE)
    {
        hr = SASCreateEffectFromResource(
                pDevice,
                sf.GetResourceModule(),
                sf.GetResourceName(),
                sf.GetResourceType(),
                pDefines,
                pInclude,
                flags,
                NULL,
                &pD3DXEffect,
                &pErrors );
    }
    else if(sf.GetSourceType() == SOURCEINFO_FILE)
    {
        hr = D3DXCreateEffectFromFile( 
                pDevice, 
                sf.GetFilePath(), 
                pDefines, 
                pInclude, 
                flags, 
                NULL, 
                &pD3DXEffect, 
                &pErrors );
        if( hr == E_NOTIMPL)
            hr = D3DXCreateEffectFromFile( 
                    pDevice, 
                    sf.GetFilePath(), 
                    pDefines, 
                    pInclude, 
                    (flags | D3DXSHADER_USE_LEGACY_D3DX9_31_DLL), 
                    NULL, 
                    &pD3DXEffect, 
                    &pErrors );
    }

    if( pErrors )
        Sas::Host::OutAnsi( FAILED(hr)?LEVEL_ERROR:LEVEL_WARNING, "%s", (LPSTR)pErrors->GetBufferPointer() );

    if( FAILED(hr) )
        goto e_Exit;

    D3DXHANDLE technique = NULL;
    hr= pD3DXEffect->FindNextValidTechnique(NULL, &technique);
    if( FAILED(hr) )
    {
        Sas::Host::Out( LEVEL_ERROR, L"No technique in the effect is valid on your hardware." );
        goto e_Exit;
    }
    
    pD3DXEffect->SetTechnique(technique);

    // Now that we have a D3DXEffect we can create a Sas::Effect
    hr = FromD3DXEffect( pD3DXEffect, sf, ppEffectOut );

e_Exit:
    SAFE_RELEASE(pErrors);
    SAFE_RELEASE( pD3DXEffect );

    if(SUCCEEDED(hr))
        Sas::Host::Out( LEVEL_STATUS, L"Loading effect '%s'", sf.GetDescription() );
    else
        Sas::Host::Out( LEVEL_ERROR, L"Could not load effect '%s'", sf.GetDescription() );

    return hr;
}
예제 #2
0
//--------------------------------------------------------------------------------------
HRESULT Effect9::FromD3DXEffect( ID3DXEffect* pD3DXEffect, const SourceInfo& sf, Effect9** ppEffectOut )
{
    HRESULT hr = S_OK;
    Effect9* pNew = NULL;

    if( NULL == pD3DXEffect || 
        NULL == ppEffectOut )
        return E_INVALIDARG;

    // Clear the output parameter
    *ppEffectOut = NULL;

    // Try to allocate new memory
    pNew = new Effect9();
    if( NULL == pNew )
    {
        hr = E_OUTOFMEMORY;
        goto LFail;
    }

    // Instance members
    pNew->m_pD3DXEffect = pD3DXEffect;
    pNew->m_pD3DXEffect->AddRef();


    pNew->m_Creation = sf;

    D3DXEFFECT_DESC EffectDesc;
    // Gather the parameters
    hr = pD3DXEffect->GetDesc( &EffectDesc );
    if( FAILED(hr) )
        goto LFail;
    
    for( UINT i=0; i < EffectDesc.Parameters; i++ )
    {
        D3DXHANDLE hParameter = pD3DXEffect->GetParameter( NULL, i );
        if( NULL == hParameter )
        {
            pNew->m_Variables.push_back(NULL);
            continue;
        }

        Variable* pParam = new Variable9(pD3DXEffect, hParameter, pNew, NULL, i);
        if( NULL == pParam )
        {
            hr = E_OUTOFMEMORY;
            goto LFail;
        }

        pNew->m_Variables.push_back( pParam );

        // Check for the global parameter
        if( pParam->GetParameter()->IsGlobalParameter() )
        {
            // If this is the second global parameter found, ignore it
            if( NULL != pNew->m_pGlobal )
                Sas::Host::Out( LEVEL_ERROR, L"Multiple global parameters found. Ignoring all but the first occurance" );
            else
                pNew->m_pGlobal = pParam;
        }
    }

    // If no global parameter was found, the effect is by definition
    // not Sas-complaint
    if( NULL == pNew->m_pGlobal )
    {
        Sas::Host::Out( LEVEL_ERROR, L"'%s' - Global parameter not found. Effect is not SAS-compliant.", sf.GetDescription() );
        hr = E_FAIL;
        goto LFail;
    }


LFail:
    if(FAILED(hr))
    {
        SAFE_DELETE( pNew );
    }

    *ppEffectOut = pNew;
    return hr;
}
예제 #3
0
//--------------------------------------------------------------------------------------
HRESULT Effect10::FromSource( ID3D10Device* pDevice, const SourceInfo& sf, const D3D10_SHADER_MACRO* pDefines, ID3D10Include* pInclude, DWORD HlslFlags, DWORD FxFlags, Effect10** ppEffectOut )
{
    HRESULT hr;

    if( NULL == ppEffectOut )
        return E_INVALIDARG;

    // Clear the output parameter
    *ppEffectOut = NULL;

    // Attempt to create the D3DXEffect
    ID3D10Effect* pD3DEffect = NULL;
    ID3D10Blob* pErrors = NULL;


    if(sf.GetSourceType() == SOURCEINFO_RESOURCE)
    {
        hr = D3DX10CreateEffectFromResource( 
                sf.GetResourceModule(), 
                sf.GetResourceName(), 
                sf.GetResourceName(), 
                pDefines, 
                pInclude,
                "fx_4_0",
                HlslFlags, 
                FxFlags,
                pDevice,
                NULL,
                NULL,
                &pD3DEffect,
                &pErrors,
                NULL );
    }
    else if(sf.GetSourceType() == SOURCEINFO_FILE)
    {

        hr = D3DX10CreateEffectFromFile( 
                sf.GetFilePath(), 
                pDefines, 
                pInclude,
                "fx_4_0",
                HlslFlags, 
                FxFlags, 
                pDevice, 
                NULL, 
                NULL, 
                &pD3DEffect, 
                &pErrors,
                NULL );
    }

    if( pErrors )
        Sas::Host::OutAnsi( FAILED(hr)?LEVEL_ERROR:LEVEL_WARNING, "%s",(LPSTR)pErrors->GetBufferPointer() );

    if( FAILED(hr) )
        goto e_Exit;

    D3D10_EFFECT_DESC desc;
    pD3DEffect->GetDesc(&desc);
    if(desc.Techniques <= 0)
    {
        Sas::Host::Out( LEVEL_ERROR, L"Effect does not have a Technique10." );
        hr = E_FAIL;
        goto e_Exit;
    }


    // Now that we have a D3DXEffect we can create a Sas::Effect
    hr = FromD3DEffect( pD3DEffect, sf, ppEffectOut );

e_Exit:
    SAFE_RELEASE(pErrors);
    SAFE_RELEASE( pD3DEffect );

    if(SUCCEEDED(hr))
        Sas::Host::Out( LEVEL_STATUS, L"Loading effect '%s'", sf.GetDescription() );
    else
        Sas::Host::Out( LEVEL_ERROR, L"Could not load effect '%s'", sf.GetDescription() );

    return hr;
}