//////////////////////////////////////////////////////////////////////////////////////////
//
//  FILE        :  Tools_WaterProcessor.h
//
//  CREATED     :  Richard J. Fine  (28.4.2005)
//
//  Copyright (C) 2005 Rebellion, All Rights Reserved.
//
//////////////////////////////////////////////////////////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
	#pragma once
#endif

#ifndef __TOOLS_WATERPROCESSOR_H__
#define __TOOLS_WATERPROCESSOR_H__

#ifdef ASURA_USE_WATER

#include "Mesh/Asura_Mesh.h"
#include "Misc/list_tem.hpp"
#include "Rendering/Asura_Colour.h"

struct Tools_WaterProcessor_Vertex
{
	Asura_Vector_3 m_xPosition;
	Asura_RGBA m_xColour;
	float m_fU, m_fV;
};

struct Tools_WaterProcessor_Strip
{
	Tools_WaterProcessor_Strip() : m_iModuleIndex(-1), m_pxVertices(0), m_pusIndices(0), m_uNumVertices(0), m_uNumTriangles(0) { }
	~Tools_WaterProcessor_Strip()
	{ 
		if(m_pxVertices) 
		{ 
			delete[] m_pxVertices; 
		} 
		if(m_pusIndices) 
		{ 
			delete[] m_pusIndices; 
		} 
	}

	int								m_iModuleIndex;
	Tools_WaterProcessor_Vertex*	m_pxVertices;
	u_short*						m_pusIndices;
	u_int							m_uNumVertices;
	u_int							m_uNumTriangles;
};

class Tools_WaterProcessor
{
public:
	// Find all water meshes and load them in
	static bool Initialise();
	// Release meshes
	static void Shutdown();

	// Subdivide all meshes near waypoints
	static void Subdivide();
	// Split all quads into triangles aligned perpendicular to the sun
	static void SplitQuads();
	// Get the number of meshes
	static int GetNumMeshes();
	static Asura_Mesh* GetMesh(int iMeshIndex);
	// Generate a strip for each mesh
	static void Stripify();
	static Tools_WaterProcessor_Strip* GetStrip(int iMeshIndex);

private:
	static List<Asura_Mesh*> s_xMeshes;
	static List<Tools_WaterProcessor_Strip*> s_xStrips;

	// filtering functions
	static bool ExtractWaterPolys	(Asura_Mesh* pxMesh, int iIndex);
	static bool ExtractQuads		(Asura_Mesh* pxMesh, int iIndex);
	static bool ExtractTriangles	(Asura_Mesh* pxMesh, int iIndex);
};

#endif

#endif//__TOOLS_WATERPROCESSOR_H__
