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

		I3DExInteractiveRenderer.h

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

		I3DExRenderer definition

		Author:	Ray Dream
		Date:	3/2/98

		Revision History

		when		who			what & why
		==========	==========	======================================================
		12/25/2000	Charles		removed include TMCArray
		11/15/99	Gilles		Added Dehydrate() && Rehydrate() to delete IR buffers
		07/01/99	Alec		elminated settings call, flags are now in ir pmap,
									added call for the working box
		06/26/99	Alec		moved TInteractiveUserSettings down to interactive
									renderer
		06/18/99	Pierre		added TInteractiveUserSettings class
		05/25/99	Alec		added more space for shadows in EPickForm
		05/19/99	Alec		added call for SetLighting, removed some old GUID,
									added pick form data
		04/14/99	Alec		moved out markers to TPointMesh code
		04/14/99	Alec		added TInteractiveSettings, interface calls for it
		03/08/99	Alec		added PreDrawChannels call for z/color buffer access, 
									removed other obsolete interfaces
		03/01/99	pbk			Added A DrawInGC call.							
		12/09/98	Alec		added in renderable cache management, removed old
									instance maintenance items
		12/01/98	EricG		added GUID for the pick renderer
		11/25/98	Alec		added pick renderer interface
		11/18/98	Alec		DrawInstances now uses TRenderableAndTfmArray,
									added comments around some obsolete items
		11/12/98	Alec		added SetRenderingMode call to interactive renderer
		10/05/98	Alec		changed interface to I3DExInteractiveRenderer,
									added comments, grouped like routines together,	
									named the enums, 
		09/01/98	Eml			I3dExRenderer API change

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

#ifndef __I3DExInteractiveRenderer__
#define __I3DExInteractiveRenderer__

#pragma once

#include "IExtension.h"
#include "I3DShRenderable.h"
#include "I3DShLightSource.h"
#include "IWorkingBox.h"

struct	I3DShCamera;
//struct	I3DShLightsource;
struct	I3DShInstance;
struct	IMCGraphicContext;
class	TMCPixelBucket;
class	TMCColorRGB;

template<class T> class TMCArray;

//****** Globally Unique Ids *************************************************

//MCDEFINE_GUID2	(IID_I3DExInteractiveRenderer,	R_IID_I3DExInteractiveRenderer);
//MCDEFINE_GUID2	(IID_I3DExPickRenderer,			R_IID_I3DExPickRenderer);

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

// A designator for the type of color channel to return
enum EIRColorChannel
{
	kIRColorChannel_kColor = 1	// a 32-bit, 8-bit / component, integer color buffer
	
	// Possibilities for other channels, require multiple passes
	// kIRColorChannel_kNormal,		
	// kIRColorChannel_kTexture,
};

// a designator for the type of depth channel to return
enum EIRDepthChannel
{
	kIRDepthChannel_kDepth = 1 // a 32-bit, floating-pt, 1/z buffer

	// for soft shadows, might want to support an average depth buffer
	// kIRDepthChannel_kAverageDepth = 2; // a 32-bit, floating-pt, 1/z buffer
};

//------------------------------------------------------

/*
struct I3DExInteractiveRenderer	: public IExDataExchanger
{
	// note that much of the functionality is accessible through the data exchanger
	// G/SetParameter provide access to the fields of the renderer for toggling states
	
	// ****************************************************************************
	//							SetCamera	
	// 
	// -Description:
	//
	// Sets the camera used for the rendering
	//
	// -Parameters:
	//
	// camera:			The camera used for the rendering
	// viewPane:		The coordinates of the view pane (be careful this is not in camera coordinates!
	//					You need to apply the zoom and pan to the camera coordinates).
	//
	virtual MCCOMErr MCCOMAPI SetCamera				(I3DShCamera* camera, const TBBox2D& viewPane)=0;
	virtual MCCOMErr MCCOMAPI SetLighting			(const TLightAndTfmArray&	lights,	const TMCColorRGB& ambientLightColor)=0;
	
	// convenience function to convert renderables to light and tfm array
	// note lights are only created by this if they have a renderable
	virtual MCCOMErr MCCOMAPI ConvertLighting		(const TRenderableAndTfmArray&	instances, TLightAndTfmArray& lights)=0;
		
	// to set the working box information, don't forget to invalidate renderer if it changes
	virtual void MCCOMAPI	SetWorkingBox			(IWorkingBox* workingBox)=0; // can be NULL

	// delete all the caches, something traumatic has happened to the database
	virtual void MCCOMAPI DeleteAllRenderableCaches	() = 0;
	// delete a single cache
	virtual void MCCOMAPI DeleteRenderableCache		(I3DShRenderable& rend)=0;
	// this call gives the renderer a chance to respond to a mod in a renderable
	virtual void MCCOMAPI UpdateRenderableCache		(I3DShRenderable& rend, const ERenderableMod change)=0;
	
	// An optional call that the default interactive renderer supports.  The caller supplies pixel buckets to 
	// render channel data from the renderer into.  Only two channels at a time, so multiple passes may be 
	// required to generate the various channels.  This call is followed with DrawInstances, PostDraw.
	virtual MCCOMErr MCCOMAPI PreDrawChannels(
			TMCPixelBucket*			colorChannel,
			EIRColorChannel			colorChannelType,
			TMCPixelBucket*			depthChannel,
			EIRDepthChannel			depthChannelType,
			const TMCRect&			windowContentRect, 
			const TMCRect& 			windowUpdateRect,
			const boolean			useAverageZ) = 0;

	// rendering consists of PreDraw/DrawInstances/PostDraw in combination
	// shoud PostDraw be called even if DrawInstances should fail ? (right now it's not)
	virtual MCCOMErr MCCOMAPI PreDraw				(void* awnd, const TMCRect& windowContentRect, const TMCRect& windowUpdateRect)=0;
	virtual MCCOMErr MCCOMAPI DrawInstances			(const TRenderableAndTfmArray& instances)=0;
	virtual MCCOMErr MCCOMAPI PostDraw				()=0;
	
	// this is an opportunity for the renderer to update the screen without re-rendering
	// what if no renderer support to do this ?
	virtual MCCOMErr MCCOMAPI DrawOnScreen			(void* awnd,const TMCRect& windowContentRect, const TMCRect& windowUpdateRect)=0;
	virtual MCCOMErr MCCOMAPI DrawInGC				(IMCGraphicContext* gc,const TMCRect& windowContentRect, const TMCRect& windowUpdateRect)=0;

	// this sets the background color (shouldn't this be a little more expandable 
	// for bg images, eglobal environment maps, fog, etc.)
	virtual MCCOMErr MCCOMAPI SetEraseColor			(const TMCColorRGBA& acolor) = 0;
	
	// one hopefully temporary way to change rendering modes
	virtual MCCOMErr MCCOMAPI SetRenderingMode		(const uint32 renderingMode) = 0;
	virtual uint32	 MCCOMAPI GetRenderingMode		() const = 0;
	virtual MCCOMErr MCCOMAPI GetRenderingModeIDs	(TMCArray<ResourceID>& renderingModes) const = 0;

	// tell the renderer about the render activity taking place
	virtual MCCOMErr MCCOMAPI SetRenderActivity		(const uint32 renderActivity) = 0;
	virtual MCCOMErr MCCOMAPI Set2DZoomAndPan		(TVector2 Zoom,TVector2 Pan) = 0;

	// free all render buffers to dehydrate InteractiveRenderer when it's not activated
	virtual MCCOMErr MCCOMAPI Dehydrate				() = 0;
	virtual MCCOMErr MCCOMAPI Rehydrate				() = 0;
};
*/
enum EPickMode
{
	// These may eventually be broken into a bit mask for various pick attributes
	// that we need back from the renderer.  For example, some picks may only need
	// the object id which lets the picker stop after a single polygon renders.  I'm
	// concerned about the TRenderPick growing too large as more data is returned.
	kPickMode_Closest	= 0,
	kPickMode_All		= 1
};

enum EPickForm
{
	// the drop shadow forms
	kPickForm_ShadowX		= 1,
	kPickForm_ShadowY,
	kPickForm_ShadowZ,
	kPickForm_ShadowGround  = 7,
	kPickForm_ShadowMax		= kPickForm_ShadowGround, // to quickly test for shadowForm < kPickForm_ShadowMax

	// the actual shape of the object
	kPickForm_Actual		= 15,
	kPickForm_Max			= 0x7fffffff // not a valid constant
};

struct TRenderPick
{
	// this transports render pick data out to the caller
	uint32 		fRenderableID;			// which renderable in the array
	real 		fMeshID; 				// which LOD mesh out of the renderable
	uint32 		fPieceID;				// which piece of that mesh
	EPickForm	fForm;					// rendered form of the object

	// might want to just return the 3d point in world space instead of this
	// not sure that I like having depth comparisons done by caller
	real		fInverseDepth;			// inverse depth value 1 = near, 0 = far 
};	

typedef TMCArray<TRenderPick> TRenderPickArray;

/// OBSOLETE: this interface is not used at this point.
///
struct I3DExPickRenderer : public IMCUnknown
{
	// use these calls in place of PreDraw, DrawInstances, PostDraw for render picks.
	// note that for area picks, it is best to select all objects as the pick mode 
	// and select everyone. 
	virtual MCCOMErr MCCOMAPI PrePick		(
											const TMCRect&		windowContentRect, 
											const TMCRect& 		windowPickArea,
											const EPickMode 	pickMode,
											TRenderPickArray& 	renderPicks) = 0;
	virtual MCCOMErr MCCOMAPI PickInstances	(const TRenderableAndTfmArray& instances) = 0;
	virtual MCCOMErr MCCOMAPI PostPick		() = 0;
	
	// ideally the pick data should be kept by the pick render and we query it 
	// for the information that we need.
};
	

#endif