Exemple #1
0
bool Material::bind(RenderContext* context)
{

    if( this == context->getBoundMaterial() )
    {
        return false;
    }

    ID3DX11Effect* effect = m_shader->getEffect();



    context->getImmediateContext()->IASetInputLayout( m_layout );


    for(std::map<string, ResourceID>::iterator iter = m_textureRefs.begin(); iter!=m_textureRefs.end(); ++iter)
    {

        ID3DX11EffectVariable* var = effect->GetVariableByName(iter->first.c_str());
        if(var->IsValid())
        {
            ID3DX11EffectShaderResourceVariable* texResource = var->AsShaderResource();
            Texture* tex = TextureManager::singleton()->getTexture(iter->second);
            if(tex)
            {
                texResource->SetResource(tex->getShaderResourceView());
            }
            else {
                texResource->SetResource(0);
            }
        }
    }

    return true;
}
bool cSkyBoxEffect::Init( ID3D11Device* pDevice, ID3D11DeviceContext* pContext )
{
	if ( !Base::LoadFXFile( mEffectFileName, pDevice ) )
	{
		return false;
	}

	cMeshGenerator gen;
	cMeshGenerator::cMesh mesh;
	gen.CreateSphere( 10000.f, 20, 20, mesh );
	
	unsigned int numVerts = mesh.VerticesA.size();
	unsigned int numInds = mesh.Indices.size();

	if ( !mBuffers.Init( pDevice, numVerts, numInds ) )
	{
		return false;
	}
	// map the vertices
	sVert_P* verts = mBuffers.BeginVertexMapping( pContext );
	for ( unsigned int idxVert = 0; idxVert < numVerts; idxVert++ )
	{
		verts[idxVert].Position = mesh.VerticesA[idxVert].Position;
		verts[idxVert].PositionPad = 1.f;
	}
	mBuffers.FinishVertexMapping( pContext );

	// map the indices
	unsigned int* inds = mBuffers.BeginIndexMapping( pContext );
	for ( unsigned int idxIndex = 0; idxIndex < numInds; idxIndex++ )
	{
		inds[idxIndex] = mesh.Indices[idxIndex];
	}
	mBuffers.FinishIndexMapping( pContext );


	mTechnique = mEffect->GetTechniqueByIndex(0);
	if ( !mTechnique->IsValid() )
	{
		return false;
	}

	D3DX11_PASS_DESC passDesc;
	mTechnique->GetPassByIndex(0)->GetDesc(&passDesc);
	pDevice->CreateInputLayout( sVert_P::GetElementDescPtr(), sVert_P::NUM_ELEMENTS,
		passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &mLayout );


	mTransform = mEffect->GetVariableByName("WorldViewProj");
	if ( mTransform->IsValid() )
	{
		NecessaryPerFrame.push_back( new cMatrixEffectVariable( mTransform ) );
	}

	ID3DX11EffectVariable* boxVar = mEffect->GetVariableByName("CubeMap");
	if ( boxVar->IsValid() )
	{
		NecessaryPerFrame.push_back( new cShaderResourceEffectVariable( boxVar ) );
	}
	mSRV = boxVar->AsShaderResource();

	return true;
}