#pragma once
#define MLR_MLR_I_C_TMESH_HPP

#include <MLR\MLR.hpp>
#include <MLR\MLR_I_TMesh.hpp>
#include <MLR\MLR_I_C_PMesh.hpp>

namespace MidLevelRenderer {

	//##########################################################################
	//#### MLRIndexedTriMesh with no color no lighting one texture layer  #####
	//##########################################################################


	class MLR_I_C_TMesh:
		public MLR_I_TMesh
	{
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Initialization
	//
	public:
		static void
			InitializeClass();
		static void
			TerminateClass();

		static HGOSHEAP
			PrimitiveHeap;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Constructors/Destructors
	//
	protected:
		MLR_I_C_TMesh(
			ClassData *class_data,
			Stuff::MemoryStream *stream,
			int version
		);
		~MLR_I_C_TMesh();

	public:
		MLR_I_C_TMesh(ClassData *class_data=MLR_I_C_TMesh::DefaultData);

		static MLR_I_C_TMesh*
			Make(
				Stuff::MemoryStream *stream,
				int version
			);

		void
			Save(Stuff::MemoryStream *stream);

	public:
		virtual void
			SetColorData(
				const ColorType *array,
				int point_count
			);
		virtual void
			GetColorData(
				const ColorType **array,
				int *point_count
			);

		virtual int	TransformAndClip(Stuff::Matrix4D *, MLRClippingState, GOSVertexPool*, FogData*, DWORD=0xffffffff, bool=false);

		virtual void
			TransformNoClip(Stuff::Matrix4D*, GOSVertexPool*, FogData*, DWORD=0xffffffff, bool=false);

		bool
			Copy(MLR_I_C_PMesh*);

		void
			CleanMe();

		void
			HurtMe(const Stuff::LinearMatrix4D& pain, Stuff::Scalar radius);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// This functions using the static buffers
	//
		void
			SetClipColor(ColorType &color, int index)
				{
					Check_Object(this); Verify(clipExtraColors->GetLength() > index);
					(*clipExtraColors)[index] = color;
				}

		void
			FlashClipColors(int num)
				{
					Check_Object(this); Verify(clipExtraTexCoords->GetLength() > num);
					
					dataStore->colors.SetLength(num);
					Mem_Copy(dataStore->colors.GetData(), clipExtraColors->GetData(), sizeof(ColorType)*num, sizeof(ColorType)*num);
					SetColorData(dataStore->colors.GetData(), num);
				}

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Class Data Support
	//
	public:
		static ClassData
			*DefaultData;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Testing
	//
	public:
		void
			TestInstance() const;

	protected:
		Stuff::ReadOnlyArrayOf<ColorType> colors;	// Base address of color list 
		Stuff::ReadOnlyArrayOf<ColorType> *actualColors;
	};

	MLR_I_C_TMesh*
		CreateIndexedTriCube_Color_NoLit(
      Stuff::Scalar half, 
			MLRState *state
		);
	MLRShape*
		CreateIndexedTriIcosahedron_Color_NoLit(
			IcoInfo& icoInfo,
			MLRState *state
		);

	MLRShape*
		CreateIndexedTriCone_Color_NoLit(
			Stuff::Scalar start_falloff,
			Stuff::Scalar end_falloff,
			Stuff::Radian angle,
			const Stuff::RGBAColor *color,
			const Stuff::RGBAColor *color2,
			int=6
		);
}
