//
// Asura_PlatformFSFX.cpp (PC)
//
// Created by JGP 07/02/06
// 
// Copyright (C) 2006 Rebellion (Derby), All Rights Reserved.
//

#include "Core/Asura.h"

#ifdef ASURA_USE_FSFX

#include "Camera/Asura_Camera.h"
#include "FSFX/Asura_FSFX_Component.h"
#include "FSFX/Asura_FSFX_System.h"
#include "FSFX/Asura_FSFX_Template.h"
#include "Rendering/Asura_Render.h"
#include "Rendering/Asura_ViewPort.h"

#include "FSFX/Asura_Platform_FSFX_SM30.h"
#include "Rendering/Asura_Direct3D.h"

///////////////////////////////////////////////////////////////////////////////////////
// Asura_FSFX_System platform specific
///////////////////////////////////////////////////////////////////////////////////////

extern void Asura_FSFX_Component_DepthOfField_Platform_Reset();
extern void Asura_FSFX_Component_GaussianBlur_Platform_Reset();

extern void Asura_FSFX_Component_RadialBlur_PlatformInitialise();
extern void Asura_FSFX_Component_RadialBlur_PlatformShutdown();

void Asura_FSFX_System::Platform_Initialise()
{
	if( NULL == Asura_Direct3D::D3DDevice)
	{
		return;
	}
#ifdef ASURA_TARGET_SM3
	Asura_Platform_FSFX_SM30::Platform_Initialise();

	Asura_FSFX_Component_SM30_Bloom::Platform_Initialise();

	Asura_FSFX_Component_SM30_FishEye::Platform_Initialise();

	Asura_FSFX_Component_SM30_DoubleVision::Platform_Initialise();
#endif

	Asura_FSFX_Component_RadialBlur_PlatformInitialise();	
}

void Asura_FSFX_System::Platform_Reset()
{
#ifdef ASURA_TARGET_SM3
	Asura_Platform_FSFX_SM30::Platform_Reset();

	Asura_FSFX_Component_SM30_Bloom::Platform_Reset();

	Asura_FSFX_Component_SM30_FishEye::Platform_Reset();

	Asura_FSFX_Component_SM30_DoubleVision::Platform_Reset();
#endif

	Asura_FSFX_Component_DepthOfField_Platform_Reset();
	Asura_FSFX_Component_GaussianBlur_Platform_Reset();
}

void Asura_FSFX_System::Platform_Shutdown()
{
#ifdef ASURA_TARGET_SM3
	Asura_Platform_FSFX_SM30::Platform_Shutdown();

	Asura_FSFX_Component_SM30_Bloom::Platform_Shutdown();

	Asura_FSFX_Component_SM30_FishEye::Platform_Shutdown();

	Asura_FSFX_Component_SM30_DoubleVision::Platform_Shutdown();
#endif

	Asura_FSFX_Component_RadialBlur_PlatformShutdown();
}

void Asura_FSFX_System::Platform_BeginRender(void)
{
	D3DPERFCALL(BeginEvent(D3DCOLOR_XRGB(0xFF, 0xFF, 0xFF), L"FSFX"));
}

void Asura_FSFX_System::Platform_EndRender(void)
{
	D3DPERFCALL(EndEvent()); // FSFX
}

///////////////////////////////////////////////////////////////////////////////////////
// Asura_FSFX_Template platform specific
///////////////////////////////////////////////////////////////////////////////////////


int Asura_FSFX_Template::Platform_GetPlatformFlag()
{
	return Asura_FSFX_Component::FSFX_PLATFORM_PC;
}


///////////////////////////////////////////////////////////////////////////////////////
// Asura_FSFX_Component_Test platform specific
///////////////////////////////////////////////////////////////////////////////////////


/*
	As it happens this particular
	render function is going to be the same between
	platforms...
*/
void Asura_FSFX_Component_Test::Platform_Render( const float fIntensity )
{
	const Asura_ViewingArea*	pxViewingArea	= Asura_Camera::GetViewingArea();
	const float 				fScreenWidth	= static_cast<float>(Asura_Viewport::GetWidth());
	const float 				fScreenHeight	= static_cast<float>(Asura_Viewport::GetHeight());
	const float 				fXOffset		= static_cast<float>(pxViewingArea->m_fXOffset * fScreenWidth);
	const float 				fYOffset		= static_cast<float>(pxViewingArea->m_fYOffset * fScreenHeight);
	const float 				fWidth			= static_cast<float>(pxViewingArea->m_fWidth * fScreenWidth);
	const float 				fHeight			= static_cast<float>(pxViewingArea->m_fHeight * fScreenHeight);

	SCOPEDPIXEVENT(( 0xFFFFFFFF, L"FSFX: Test" ));

	Asura_Render::Overlay.Colour           = 0xff000000 | ( static_cast<unsigned char>( fIntensity * m_fRed ) << 16 ) | ( static_cast<unsigned char>( fIntensity * m_fGreen ) << 8 ) | ( static_cast<unsigned char>( fIntensity * m_fBlue ) );
	Asura_Render::Overlay.TranslucencyMode = ( m_bSubtractive ) ? ASURA_TRANSLUCENCY_INVCOLOUR : ASURA_TRANSLUCENCY_GLOWING;
	Asura_Render::Overlay.TextureIndex     = ASURA_TEXTURE_NONE;

	Asura_Render::Overlay.SetRectXY( fXOffset, fYOffset, fWidth, fHeight );
	Asura_Render::Overlay.Render();   
}




#endif // ASURA_USE_FSFX
