//////////////////////////////////////////////////////////////////////////////
//
// AVP_FSFX.h
//
// Copyright (c) 2007 Rebellion. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////

#if defined ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#if !defined __AVP_FSFX_H__
#define __AVP_FSFX_H__

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

#if defined(ASURA_USE_FSFX)

// Asura Platform-independent
#include "FSFX/Asura_FSFX_Component.h"
#include "Rendering/Asura_Colour.h"

/******************************************************************************/
/* Types                                                                      */
/******************************************************************************/

// Don't re-order this list, its values are saved out
enum AVP_FSFX_Type
{
	AVP_FSFX_USE_STENCIL = Asura_FSFX_Component::FSFX_FIRST_PROJECT_SPECIFIC,
	AVP_FSFX_DISPLACEMENT_MAP,
	AVP_FSFX_EDGES,
};

enum {
	AVP_MATERIAL_RESPONSE_PROJECT_INDEX_ALIEN = 0,
	AVP_MATERIAL_RESPONSE_PROJECT_INDEX_HOT,
	AVP_MATERIAL_RESPONSE_PROJECT_INDEX_TECH,
	AVP_MATERIAL_RESPONSE_PROJECT_INDEX_HOLOGRAM,

	NUM_AVP_MATERIAL_RESPONSE_PROJECT_INDEXES
};

//Keep this in sync with PS3/Rendering/AVP_Platform_Stencil_Setup.h
enum {
	AVP_MATERIAL_RESPONSE_PROJECT_FLAG_ALIEN = (1<<AVP_MATERIAL_RESPONSE_PROJECT_INDEX_ALIEN),
	AVP_MATERIAL_RESPONSE_PROJECT_FLAG_HOT = (1<<AVP_MATERIAL_RESPONSE_PROJECT_INDEX_HOT),
	AVP_MATERIAL_RESPONSE_PROJECT_FLAG_TECH = (1<<AVP_MATERIAL_RESPONSE_PROJECT_INDEX_TECH),
	AVP_MATERIAL_RESPONSE_PROJECT_FLAG_HOLOGRAM = (1<<AVP_MATERIAL_RESPONSE_PROJECT_INDEX_HOLOGRAM),

	AVP_MATERIAL_RESPONSE_PROJECT_FLAG_ALLUSED = ((1<<NUM_AVP_MATERIAL_RESPONSE_PROJECT_INDEXES) - 1),
};



/******************************************************************************/
/* Classes                                                                    */
/******************************************************************************/

class AVP_FSFX_Component_UseStencil : public Asura_FSFX_Component
{
public:

	AVP_FSFX_Component_UseStencil();

	virtual Asura_FSFX_Component* CreateCopy();

	virtual void Platform_Render( const float fIntensity );

	static Type GetTypeID() { return static_cast< Type >( AVP_FSFX_USE_STENCIL ); }
	virtual Type GetType() { return GetTypeID(); }

#if defined ASURA_TOOLS
	friend class Tools_Mode_FSFX_Template;
	static const char* GetTypeDescID() { return "AVP - Use Stencil Buffer"; }
	virtual const char* GetTypeDesc() const { return GetTypeDescID(); }
	static int GetPlatformsSupportedID() { return (1 << FSFX_PLATFORM_PC) | (1 << FSFX_PLATFORM_XB360) | (1 << FSFX_PLATFORM_PS3); }
	virtual int GetPlatformsSupported() const { return GetPlatformsSupportedID(); }
#endif // defined ASURA_TOOLS

	virtual void Deserialize( Asura_Chunk_Stream& xStream );
#if defined ASURA_TOOLS
	virtual void Serialize( Asura_Chunk_Stream& xStream ) const;
#endif
	u_int GetBitsToCheck() const {return m_uBitsToCheck;}
	u_int GetBitValues() const {return m_uBitValues;}
	void SetBitsToCheck(u_int uBitsToCheck)  {m_uBitsToCheck = uBitsToCheck;}
	void SetBitValues(u_int uBitValues)  {m_uBitValues = uBitValues;}

private:

	virtual int GetVersion() const { return 2; }

	u_int m_uBitsToCheck;
	u_int m_uBitValues;
};


class AVP_FSFX_Component_DisplacementMap : public Asura_FSFX_Component
{
public:

	AVP_FSFX_Component_DisplacementMap();
	~AVP_FSFX_Component_DisplacementMap();

	virtual Asura_FSFX_Component* CreateCopy();

	virtual void Platform_Render( const float fIntensity );

	static Type GetTypeID() { return static_cast< Type >( AVP_FSFX_DISPLACEMENT_MAP ); }
	virtual Type GetType() { return GetTypeID(); }

#if defined ASURA_TOOLS
	friend class Tools_Mode_FSFX_Template;
	static const char* GetTypeDescID() { return "AVP - DisplacementMap"; }
	virtual const char* GetTypeDesc() const { return GetTypeDescID(); }
	static int GetPlatformsSupportedID() { return (1 << FSFX_PLATFORM_PC) | (1 << FSFX_PLATFORM_XB360) | (1 << FSFX_PLATFORM_PS3); }
	virtual int GetPlatformsSupported() const { return GetPlatformsSupportedID(); }
#endif // defined ASURA_TOOLS

	virtual void Deserialize( Asura_Chunk_Stream& xStream );
#if defined ASURA_TOOLS
	virtual void Serialize( Asura_Chunk_Stream& xStream ) const;
#endif

	void UpdateTexture();
	void SetTexture(const Asura_String &pxTextureName, int iNewTexture);
	u_int GetTextureCount() const { return 1; }
	int GetTextureIndex( const u_int uTemplateTextureIndex ) const { return m_iTextureID; }
	const char* GetTextureName( const u_int uTemplateTextureIndex ) const { return m_xTextureFilename.GetString(); }


private:
	static int s_iReferences;
	static void Platform_Initialise();
	static void Platform_Shutdown();



	Asura_String m_xTextureFilename;
	uint32 m_uTextureHash;
	int32 m_iTextureID;
	float m_fAmount;

	virtual int GetVersion() const { return 1; }
};

class AVP_FSFX_Component_Edges: public Asura_FSFX_Component
{
public:

	AVP_FSFX_Component_Edges();
	~AVP_FSFX_Component_Edges();

	virtual Asura_FSFX_Component* CreateCopy();

	virtual void Platform_Render( const float fIntensity );

	static Type GetTypeID() { return static_cast< Type >( AVP_FSFX_EDGES); }
	virtual Type GetType() { return GetTypeID(); }

#if defined ASURA_TOOLS
	friend class Tools_Mode_FSFX_Template;
	static const char* GetTypeDescID() { return "AVP - Edges"; }
	virtual const char* GetTypeDesc() const { return GetTypeDescID(); }
	static int GetPlatformsSupportedID() { return (1 << FSFX_PLATFORM_PC) | (1 << FSFX_PLATFORM_XB360) | (1 << FSFX_PLATFORM_PS3); }
	virtual int GetPlatformsSupported() const { return GetPlatformsSupportedID(); }
#endif // defined ASURA_TOOLS

	virtual void Deserialize( Asura_Chunk_Stream& xStream );
#if defined ASURA_TOOLS
	virtual void Serialize( Asura_Chunk_Stream& xStream ) const;
#endif


private:
	static int s_iReferences;
	static void Platform_Initialise();
	static void Platform_Shutdown();

	Asura_RGBA m_xTintColour;
	float m_fBlurWidth;
	float m_fEDWidth;
	float m_fAmount;
	float m_fLowThreshold;
	float m_fHighThreshold;
	u_int m_uMethod;

	virtual int GetVersion() const { return 1; }
};


#endif	// defined(ASURA_USE_FSFX)

#endif // !defined __AVP_FSFX_H__
