//////////////////////////////////////////////////////////////////////////////
//
// Asura_PS3_EnvironmentRenderer.h
//
// Copyright (c) 2006 Rebellion. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef ___ASURA_PS3_ENVIRONMENTRENDERER_H___
#define ___ASURA_PS3_ENVIRONMENTRENDERER_H___ 1

// I N C L U D E S ///////////////////////////////////////////////////////////

// Engine independent.
#include "Core/Asura_Maths.h"
#include "Core/Asura_Hash.h"
#include "Rendering/Asura_PS3_GCM_VertexBuffer.h"
#include "Rendering/Asura_PS3_GCM_IndexBuffer.h"
#include "Rendering/Asura_PS3_MaterialResponse_System.h"
#include "Rendering/Shaders/Asura_PS3_GCM_Shader.h"

#define ASURA_MAX_VISIBLE_WATER_STRIPS 128

// F O R W A R D   D E C L A R A T I O N S ///////////////////////////////////
class Asura_PS3_GCM_IndexBuffer;
class Asura_PS3_GCM_VertexBuffer;
class Asura_PS3_GCM_VertexShader;
class Asura_PS3_Shadow;

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

////////////////////////////////////////////////////////////////////////////////
//
// Asura_PS3_EnvironmentRenderer_Strip
//
// Minimal description of a strip - chunk data matches order and size
// so all strips can be loaded in one go
//
////////////////////////////////////////////////////////////////////////////////
class Asura_PS3_EnvironmentRenderer_Strip
{
public:

	Asura_Hash_ID						m_uFPHashID;
	u_int								m_uVertexBufferId;
	u_int								m_uNumberOfVertices;
	u_int								m_uNumberOfIndices;
	Asura_Hash_ID						m_auMaterialResponseHashIDs[2];
	u_int								m_iModuleIndex;
	u_int								m_uNumberOfTriangles;
	u_int								m_uAntiAliasEdgeIdxStart;
	u_int								m_uAntiAliasEdgeIdxNum;
	Asura_Bounding_Box					m_xBoundingBox;
};

////////////////////////////////////////////////////////////////////////////////
//
// Asura_PS3_EnvironmentRenderer_Buffer
//
// container class for vertex and index buffers;
// just call BindAll after selecting vertex/fragment shaders and 
// you're ready to render
//
////////////////////////////////////////////////////////////////////////////////

class Asura_PS3_EnvironmentRenderer_Buffer
{
public:
	Asura_PS3_GCM_IndexBuffer	m_xIndexBuffer;
	u_int						m_uVertexBufferIndex;
};

////////////////////////////////////////////////////////////////////////////////
//
// Asura_PS3_EnvironmentRenderer
//
// The environment renderer itself
//
////////////////////////////////////////////////////////////////////////////////

class Asura_PS3_EnvironmentRenderer
{ 
	friend class Asura_Chunk_ResourceFile_PS3_Environment;
public:
	static void Initialise( void );
	static void Reset( void );
	static void Shutdown (void );

	static void Render( const bool bTransparentStrips );
	static void RenderWater(void);
	static void RenderToShadow(float fNear, float fFar, bool bCubeMap);
	static void RenderGeometry(Asura_AMatrix4x4& xViewProjectionMatrix, Asura_Vector_3& xClipSphereCentre, float fClipSphereRadius, const Asura_OBB* pxClipOBB);

	static int GetVertexSize( void );

	static Asura_PS3_EnvironmentRenderer_Strip*	GetStrip( u_int uStrip );
	static u_int GetNumberOfStrips() { return s_uNumberOfStrips; }

private: friend class Asura_Environment_Renderer;

	static u_int									s_uNumberOfStrips;
	static int										s_iNumSolidStrips;
	static Asura_PS3_EnvironmentRenderer_Strip*		s_pxStrips;
	static Asura_PS3_EnvironmentRenderer_Buffer*	s_pxBuffers;
	static int*										s_aiQueuedWaterStrips;
	static int*										s_aiSolidAlphaTestStrips;
	static int*										s_aiSolidStrips;
	static int*										s_aiTransparentStrips;
	static bool*									s_abStripInRenderList;
	static u_int									s_uNumVertexBuffers;
	static Asura_PS3_GCM_VertexBuffer*				s_pxVertexBuffer;
	static Asura_PS3_GCM_IndexBuffer				s_xAntiAliasEdges;

	//cached strip data
	static Asura_Hash_ID							s_uStripMaterialHash1;
	static Asura_Hash_ID							s_uStripMaterialHash2;
	static const Asura_MaterialResponse*			s_pxStripMaterial1;
	static const Asura_MaterialResponse*			s_pxStripMaterial2;
	static Asura_PS3_FragmentShaderCopy*			s_pxStripShader;
	static float									s_fStripAmbientContribution;
	static float									s_afStripPrelightColour[4];
	static u_int									s_uStripVertexBufferId;

	static void RenderStrip( const int iStripIdx, const bool bTransparentStrips );
	static void RenderZPassOnly( void );
	static void RenderUsingZPrePass( const bool bTransparentStrips );
	static void FlushCachedStrip( void );
};

// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

#endif // #ifndef ___ASURA_PS3_ENVIRONMENTRENDERER_H___
