/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


#ifndef	__NGEOTRILIST__
#define	__NGEOTRILIST__


		#include "core/tangent_frame.h"
		#include "color/color.h"
		#include "container/nlist.h"
		#include "container/narray.h"


namespace GS {
	namespace Core {

/*!
	@short	Geometry triangle list.
	@author Emmanuel Julien (ejulien@gsworks.fr)
*/
struct	Trilist
{
struct	Skin
{
		float	w[__PV_BONE_LIMIT__];
		uchar	bone_index[__PV_BONE_LIMIT__];	///< Internal maximum of 256 bones per triangle list (indexed via the Trilist::bone_map array).
};

		Array <Vector4>	vtx;
		Array <uint>	idx;					///< Triangle index array.
		Array <Skin>	skin;					///< Vertex skinning information.
		Array <ushort>	bone;					///< Map referencing items in Item::bone (usually resolved from the Geometry::bone_id array at skin binding time).

		Array <Vector4> nrm;
		Array <TangentFrame> tangent;
		Array <Vector2> uv[__UV_PER_GEOMETRY__];
		Array <Color>	rgb;

		uint			mat;					///< Material index.

		/// Return the number of triangle in the list.
inline	uint			GetTriangleCount() const { return idx.GetCount() / 3; }

		/*!
			@short	Optimize a given triangle list array.

			The optimizer reorder the triangle list index in order to maximize cache hits.
			You can specify the target architecture vertex cache size.

			@note	This function can be called several times if needed. The
					modifications will however not be applied to the renderer
					internals. For this you will need to explicitly recreate
					the renderer's representation.
		*/
static	void			Optimize(const List <Trilist *> &list, int vtx_cache_size = 16);

		Trilist() : mat(0) {}
};

typedef Trilist * pTrilist;

	} // Core
} // GS


#endif	// __NGEOTRILIST__
