//
// EdgeAntiAlias_FP.h
//
// Ben Weston 02/10/08
//
// NOTE: I've done this differently to other shader headers, to see if I can make things simpler than the system we presently have.
// Differences:
//  - VP & FP are both declared in the same header
//  - FP is defined as a class inheriting from Asura_PS3_FragmentShader, just like VP's usually are, so user just creates a new object and needn't
//     know the parameters for the constructor.
//  - The FP class contains m_xHandles, rather than creating a global value. This should really be static, but then the cpp file that uses it would
//     need to declare it, or we could declare it in here but then this wouldn't behave nicely if included by multiple files (already an issue with
//     the _VD.h files, which tend to declare identically-named values!).
// TODO: Simplify it further (perhaps using templates), and similarly create a better behaved and simpler version of the _VD.h files. Then roll that out to all shaders.
// TODO: These changes only work for shaders that have 1 global instance, not those handled by Asura_PS3_GCM_ShadersLibrary (which is actually most of them)
//

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef __ASURA_PS3_EDGEANTIALIAS_FP_H__
#define __ASURA_PS3_EDGEANTIALIAS_FP_H__

class Asura_PS3_EdgeAntiAlias_FP_Handles : public Asura_PS3_FP_Handles
{
public:
	Asura_PS3_EdgeAntiAlias_FP_Handles() : Asura_PS3_FP_Handles( 0, 1 )
	{}

	void InitialiseFromShader( Asura_PS3_FragmentShaderBase* pxShader )
	{
		pxShader->InitTextureUnit( 0, "g_xInputSampler", CELL_GCM_TEXTURE_CLAMP, CELL_GCM_TEXTURE_CLAMP, CELL_GCM_TEXTURE_LINEAR_LINEAR, CELL_GCM_TEXTURE_LINEAR );
	}
};


extern u_int _binary_PS3_EdgeAntiAlias_FP_bin_start;
extern u_int _binary_PS3_EdgeAntiAlias_FP_bin_end;

class Asura_PS3_EdgeAntiAlias_FP : public Asura_PS3_FragmentShader
{
public:
	Asura_PS3_EdgeAntiAlias_FP() : Asura_PS3_FragmentShader( (unsigned char *)&_binary_PS3_EdgeAntiAlias_FP_bin_start, (unsigned char *)&_binary_PS3_EdgeAntiAlias_FP_bin_end, new Asura_PS3_EdgeAntiAlias_FP_Handles )
	{
	}

	~Asura_PS3_EdgeAntiAlias_FP()
	{
		delete m_pxHandles;	//we created this in the constructor (though it's not obvious thanks to C++'s obfuscated syntax)
	}
};


static Asura_PS3_GCM_VertexShaderUniformParameter g_axVertexShaderEdgeAA[] =
{
	//m_szName, m_usArraySize, m_sizeInFloat4ForOneElement, m_usRegister
	{ "g_xProjectionMatrix",		1, 4, NULL },
	{ "g_fDepthOffset",				1, 1, NULL },
	{ "g_xConstants",				1, 1, NULL },
};

enum
{
	VS_ViewProjectionMatrix,
	VS_DepthOffset,
	VS_Constants
};

extern uint32_t _binary_PS3_EdgeAntiAlias_VP_bin_start;
extern uint32_t _binary_PS3_EdgeAntiAlias_VP_bin_end;

class Asura_PS3_EdgeAntiAlias_VP : public Asura_PS3_GCM_VertexShader
{
public:
	Asura_PS3_EdgeAntiAlias_VP() : Asura_PS3_GCM_VertexShader( (unsigned char *)&_binary_PS3_EdgeAntiAlias_VP_bin_start, (unsigned char *)&_binary_PS3_EdgeAntiAlias_VP_bin_end,
																g_axVertexShaderEdgeAA, sizeof(g_axVertexShaderEdgeAA)/sizeof(Asura_PS3_GCM_VertexShaderUniformParameter) )
	{
	}

	~Asura_PS3_EdgeAntiAlias_VP()
	{
		u_int i;
		for( i = 0; i < sizeof( g_axVertexShaderEdgeAA ) / sizeof( Asura_PS3_GCM_VertexShaderUniformParameter ); ++i )
		{
			g_axVertexShaderEdgeAA[ i ].CleanUp();
		}
	}
};


#endif //#ifndef __ASURA_PS3_EDGEANTIALIAS_FP_H__
