/****************************************************************************************************

		BasicRenderables.h
		Copyright: (c) 2001 Eovia Corp. All rights reserved.

		Author:	Arnaud
		Date:	12/8/2003

****************************************************************************************************/

#ifndef __BasicRenderables__
#define __BasicRenderables__

#if CP_PRAGMA_ONCE
#pragma once
#endif


#include "MCCountedObject.h"
#include "MCBasicTypes.h"
#include "CountedRenderable.h"

#include "I3DShRenderable.h"


//simple class to help implement renderables (wireframe renderables)
//This class uses a color and a bbox reference to save memory (be careful !!)
 

class TRenderableHelper : public TCountedRenderable
{
protected:
	TRenderableHelper(TMCColorRGB&	inColorRef, TBBox3D& inBBoxRef, TRenderableFlags& inFlagsRef) : fColorRef(inColorRef), fBBoxRef(inBBoxRef) , fFlagsRef(inFlagsRef) {}
	~TRenderableHelper() {}

public:

	virtual I3DShRenderable::EType	MCCOMAPI GetGeometryType	() const = 0;	//MUST be implemented!
	
	virtual void	 MCCOMAPI GetBoundingBox	(TBBox3D& bb)					{ bb = fBBoxRef; }

	TRenderableFlags MCCOMAPI GetRenderableFlags( void ) const					{ return fFlagsRef; }

protected:
	virtual MCCOMErr MCCOMAPI SelfGetShadingApproximation(TShadingApproximation& shadingApprox, uint32 uvSpaceID) const
	{
		shadingApprox.Init();
		shadingApprox.fDiffuseColor= fColorRef;
		return MC_S_OK;
	}

		
protected:
	TBBox3D&			fBBoxRef;
	TMCColorRGB&		fColorRef;		//color for all the elements in the renderable
	TRenderableFlags&	fFlagsRef;
};



class TPointMeshRenderable : public TRenderableHelper
{
public:
	static void Create(	TRenderableHelper**	outRenderable, 
						TMCColorRGB&		inColorRef, 
						TBBox3D&			inBBoxRef,
						TRenderableFlags&	inFlagsRef,
						TPointMesh&			inPointMeshRef)
	{
		TMCCountedCreateHelper<TRenderableHelper> result(outRenderable);
		result = new TPointMeshRenderable(inColorRef, inBBoxRef, inFlagsRef, inPointMeshRef);
	}

	virtual I3DShRenderable::EType	MCCOMAPI GetGeometryType	() const		{ return kType_Point; }
	virtual const TPointMesh*		MCCOMAPI GetPointMesh		() const		{ return &fPointMeshRef; }

protected:
	TPointMeshRenderable(	TMCColorRGB&		inColorRef, 
							TBBox3D&			inBBoxRef,
							TRenderableFlags&	inFlagsRef,
							TPointMesh&			inPointMeshRef) 
	: TRenderableHelper(inColorRef, inBBoxRef, inFlagsRef), fPointMeshRef(inPointMeshRef)  {}

	~TPointMeshRenderable() {}


protected:
	TPointMesh&	fPointMeshRef;	
};



class TSegmentMeshRenderable : public TRenderableHelper
{
public:	
	static void Create(	TRenderableHelper**	outRenderable, 
						TMCColorRGB&		inColorRef, 
						TBBox3D&			inBBoxRef,
						TRenderableFlags&	inFlagsRef,
						TSegmentMesh&		inSegmentMeshRef)
	{
		TMCCountedCreateHelper<TRenderableHelper> result(outRenderable);
		result = new TSegmentMeshRenderable(inColorRef, inBBoxRef, inFlagsRef, inSegmentMeshRef);
	}

	virtual I3DShRenderable::EType	MCCOMAPI GetGeometryType	() const		{ return kType_Segment; }
	virtual const TSegmentMesh*		MCCOMAPI GetSegmentMesh		() const		{ return &fSegmentMeshRef; }

protected:
	TSegmentMeshRenderable(	TMCColorRGB&		inColorRef, 
							TBBox3D&			inBBoxRef,
							TRenderableFlags&	inFlagsRef,
							TSegmentMesh&		inSegmentMeshRef) 
	: TRenderableHelper(inColorRef, inBBoxRef, inFlagsRef), fSegmentMeshRef(inSegmentMeshRef)  {}

	~TSegmentMeshRenderable() {}

protected:
	TSegmentMesh&	fSegmentMeshRef;	
};


#endif


