#pragma once
#define MLR_MLRINDEXEDPRIMITIVEBASE_HPP

#include "MLR.hpp"
#include "MLRPrimitiveBase.hpp"

namespace MidLevelRenderer {

	//##########################################################################
	//###################    MLRIndexedPrimitiveBase    ########################
	//##########################################################################

	class MLRIndexedPrimitiveBase:
		public MLRPrimitiveBase
	{
	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Initialization
	//
	public:
		static void
			InitializeClass();
		static void
			TerminateClass();
		static ClassData
			*DefaultData;

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

	public:
		MLRIndexedPrimitiveBase(ClassData *class_data);

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

		virtual void
			Save(Stuff::MemoryStream *stream);

		virtual	void	InitializeDrawPrimitive(BYTE, int=0);

		virtual void
			SetCoordData(
				const Stuff::Point3D *array,
				int point_count
			);

		virtual void
			SetIndexData(
				const BYTE *index_array,
				int index_count
			);

		virtual void
			GetIndexData(
				const BYTE **index_array,
				int *index_count
			);

		virtual WORD*
			GetGOSIndices(int=0)
				{ Check_Object(this); return gos_indices; }

		int
			GetNumGOSIndices()
				{ Check_Object(this); return numGOSIndices; }

		virtual void
			Transform(Stuff::Matrix4D*);

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

		virtual void	FindFacePlanes() = 0;

		virtual int
			FindVisibleVertices() = 0;

		void
			TheIndexer(int num)
				{
					Check_Object(this);
					dataStore->index.SetLength(num);
					BYTE *in = dataStore->index.GetData();
					for(BYTE i=0;i<num;i++)
					{
						in[i] = i;
					}
					SetIndexData(in, num);
				}

		virtual bool
			FogMesh(const Stuff::LinearMatrix4D *worldToShape, const Stuff::Point3D *cameraPos, FogData *fogData);

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

		bool
			CheckIndicies();

	protected:
		static Stuff::DynamicArrayOf<BYTE>	*visibleIndexedVertices; // , Max_Number_Vertices_Per_Mesh

		Stuff::ReadOnlyArrayOf<BYTE>	index;	// List of color indexes 

		static Stuff::DynamicArrayOf<WORD> *clipExtraIndex; // , Max_Number_Vertices_Per_Mesh

		WORD *gos_indices;
		WORD	numGOSIndices;

		WORD visibleIndexedVerticesKey;
	};

}
