//////////////////////////////////////////////////////////////////////////////
//
// AVP_Platform_FSFX.cpp
//
// Copyright (c) 2007 Rebellion. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////

/******************************************************************************/
/* Included Files                                                             */
/******************************************************************************/

#include "Core/Asura.h"

#if defined ASURA_USE_FSFX

// Asura Platform-independent
#include "FSFX/Asura_FSFX_System.h"
#include "Rendering/Asura_Render.h"

// Asura Xbox 360
#include "Rendering/Asura_Xbox360_Graphics.h"

// AVP Platform-independent
#include "FSFX/AVP_FSFX.h"

// Misc
#include <xtl.h>

/******************************************************************************/
/* Asura_FSFX_System Static Class Functions                                   */
/******************************************************************************/

void Asura_FSFX_System::PlatformProject_Initialise()
{
}

void Asura_FSFX_System::PlatformProject_Reset()
{
}

void Asura_FSFX_System::PlatformProject_Shutdown()
{
}

/******************************************************************************/
/* AVP_FSFX_Component_UseStencil Class Functions                              */
/******************************************************************************/

void AVP_FSFX_Component_UseStencil::Platform_Render( const float fIntensity )
{
	SCOPEDPIXEVENT(( D3DCOLOR_XRGB( 0xFF, 0xFF, 0xFF ), "FSFX: AVP - %x/%x Stencil", m_uBitsToCheck, m_uBitValues ));


	if (m_uBitsToCheck != 0)
	{
		// shift them up incase there are some used bits
		u_int uBitsToCheck = m_uBitsToCheck << ASURA_STENCIL_BIT_FIRST_PROJECT_SPECIFIC;
		u_int uBitValues = m_uBitValues << ASURA_STENCIL_BIT_FIRST_PROJECT_SPECIFIC;


		Asura_Render::CurrentStates.RequestStencilEnabled(true);

		Asura_Xbox360_Graphics::GetDevice()->SetRenderState_Inline( D3DRS_STENCILFUNC, D3DCMP_EQUAL );
		Asura_Xbox360_Graphics::GetDevice()->SetRenderState_Inline( D3DRS_STENCILREF, uBitValues );
		Asura_Xbox360_Graphics::GetDevice()->SetRenderState_Inline( D3DRS_STENCILMASK, uBitsToCheck );
		Asura_Xbox360_Graphics::GetDevice()->SetRenderState_Inline( D3DRS_STENCILWRITEMASK, ASURA_STENCIL_MASK_PROJECT_SPECIFIC );
		Asura_Xbox360_Graphics::GetDevice()->SetRenderState_Inline( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );
		Asura_Xbox360_Graphics::GetDevice()->SetRenderState_Inline( D3DRS_STENCILFAIL, D3DSTENCILOP_KEEP );
		Asura_Xbox360_Graphics::GetDevice()->SetRenderState_Inline( D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP );
	} else {
		Asura_Render::CurrentStates.RequestStencilEnabled(false);
	}
}

#endif // defined ASURA_USE_FSFX
