//
// Tools_AAEdges.h
//
// Copyright (C) 2009 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
	#pragma once
#endif

#ifndef __TOOLS_AAEDGES_H__
#define __TOOLS_AAEDGES_H__


struct Tools_LinkedAntiAliasEdge
{
	Tools_LinkedAntiAliasEdge*	m_pxNext;
	uint16						m_auIdx[2];
	int							m_iParentIndex; // module index initially, then strip index. According to what this edge "belongs to" at this point.
};

class Tools_EnvironmentProcessor_Strip;
class Asura_Mesh;

class Tools_AAEdges
{
public:
	Tools_AAEdges();
	~Tools_AAEdges();

	u_int						GetNumberOfEdgesForStrip( const int iStripId ) const		{ return m_puNumAAEdgesPerStrip[iStripId]; }
	int							GetTotalNumberOfEdgeIndices( ) const						{ return m_iTotalNumEdgeIndices; }
	Tools_LinkedAntiAliasEdge*	GetSortedEdges( ) const										{ return m_pxSortedEdges; }
	void						Create( const Asura_Bounding_Box& xBB, const u_int uNumberOfStrips );
	void						BeginStripsMapping();
	void						MapStrip( const Tools_EnvironmentProcessor_Strip& xStrip, int iStripId );
	void						EndStripsMapping();

private:
	int							FindAntiAliasEdges( const Asura_Mesh* pxMesh, uint16** ppuOutput );

private:
	int							m_iTotalNumEdgeIndices;
	int*						m_iNumEdgeIndices;
	uint16**					m_puEdgeIndices;
	Tools_LinkedAntiAliasEdge*	m_axAllocatedEdges;
	Tools_LinkedAntiAliasEdge** m_apxSpatialHash;
	u_int*						m_puNumAAEdgesPerStrip;
	Tools_LinkedAntiAliasEdge*	m_pxSortedEdges;
	int							m_iMappedEdgeCount;
	Asura_Vector_3				m_xSpatialOffset;
	Asura_Vector_3				m_xSpatialInvRange;
	int							m_iGridDim;
};


#endif //__TOOLS_AAEDGES_H__
