#include "IntroEffect.h"

HRESULT IntroEffect::init()
{
	HRESULT hr = S_OK;

    DWORD dwShaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
	#if defined( DEBUG ) || defined( _DEBUG )
		dwShaderFlags |= D3D10_SHADER_DEBUG;
	#endif

	ID3D10Blob *pErrorMsg;
	hr = D3DX10CreateEffectFromFile( L"../../shaders/Intro.fx", NULL, NULL, "fx_4_0", dwShaderFlags, 0, DXUTGetD3D10Device(), NULL,
                                         NULL, &effect, &pErrorMsg, NULL );

	if(pErrorMsg)
	{
		#if defined( DEBUG ) || defined( _DEBUG )
		 //_RPT1(_CRT_WARN, "compilation error : %s\n", (char*) pErrorMsg->GetBufferPointer()); 
		  SAFE_RELEASE(pErrorMsg);
		#endif
	}
    if( FAILED( hr ) )
    {
        MessageBox( NULL,
                    L"The FX file cannot be located.  Please run this executable from the directory that contains the FX file.", L"Error", MB_OK );
		V_RETURN(hr);
    }
	technique = effect->GetTechniqueByName("Render");
	fullscreenTexture = effect->GetVariableByName("fullScreenTex")->AsShaderResource();
	fadeValue = effect->GetVariableByName("fadeValue")->AsScalar();
	ID3D10Device* pd3dDevice = DXUTGetD3D10Device();
	
	D3D10_PASS_DESC PassDesc;
	technique->GetPassByIndex( 0 )->GetDesc( &PassDesc );
	pd3dDevice->IASetInputLayout( NULL );

	return S_OK;
}

void IntroEffect::setFadeValue(float value)
{
	fadeValue->SetFloat(value);
}

void IntroEffect::setInputLayout()
{
	DXUTGetD3D10Device()->IASetInputLayout( NULL );
}

void IntroEffect::setFullScreenTexture(ID3D10ShaderResourceView* textureResrc)
{
	fullscreenTexture->SetResource(textureResrc);
}

ID3D10Effect* IntroEffect::getEffectVariable()
{
	return effect;
}

ID3D10EffectTechnique* IntroEffect::getTechniqueVariable()
{
	return technique;
}

void IntroEffect::setModelMatrix(D3DXMATRIX* modelMatrix)
{}
void IntroEffect::setViewMatrix(D3DXMATRIX* viewMatrix)
{}
void IntroEffect::setProjectionMatrix(D3DXMATRIX* projMatrix)
{}
IntroEffect::~IntroEffect()
{
	SAFE_RELEASE(effect);
}
