#pragma once

#include "ElementRenderer.hpp"

namespace MidLevelRenderer {
	class MLRPointCloud;
}

namespace ElementRenderer {

	//#########################################################################
	//#########################  PointCloudElement  ################################
	//#########################################################################

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

		typedef Element BaseClass;

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

	public:
		PointCloudElement(unsigned max_points);
		~PointCloudElement();

		static PointCloudElement* Make(
			Stuff::MemoryStream *stream,
			int version,
			ShapeHolder shapes=NULL
		);

		void Save(Stuff::MemoryStream *stream);

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

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Hierarchy
	//
	protected:
		void AttachChild(Element *child);
		void DetachChild(Element *child);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Collision
	//
	protected:
		bool CastCulledRay(CollisionQuery *query);
		Element* FindSmallestElementContainingCulled(SphereTest *test);

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Drawing
	//
	protected:
		void SetDrawState();
		static DrawMethod DrawMethods[DrawStateCount];

		void InheritDrawMethod(
			CameraElement *camera,
			const StateChange *inherited_state,
			int clipping_state
		);
		void OverrideDrawMethod(
			CameraElement *camera,
			const StateChange *inherited_state,
			int clipping_state
		);

		int CountTriangles();

	public:
		MidLevelRenderer::MLRPointCloud* GetPointCloud()
			{Check_Object(this); return m_MLRPointCloud;}

		void SetDataPointers(
			const unsigned *used_points,
			const Stuff::Point3D *point_data,
			const Stuff::RGBAColor *color_data
		);

	protected:
		MidLevelRenderer::MLRPointCloud *m_MLRPointCloud;
	};

}
