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

		I3DRenderHelper.h

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

		Author:	Charles
		Date:	09/15/99
		

		Revision History

		when		who			what & why
		==========	==========	======================================================
		09/15/99	Charles		created

*****************************************************************************************/
#ifndef __I3DRenderHelper__
#define __I3DRenderHelper__

#if CP_PRAGMA_ONCE
#pragma once
#endif

#include "MCCompObj.h"
#include "InterfaceIDs.h"
#include "RenderTypes.h"

struct I3DShScene;
struct I3DShCamera;
struct I3DRenderingCallbacks;

struct IShParameterComponent;
struct IShChannel;
struct IShRasterLayer;

class RenderFilterNeeds;
class TMCNetStream;

// {7EF13C2E-6BDB-11d3-B729-0050046FFD0A}
MCDEFINE_GUID2(IID_I3DRenderHelper,R_IID_I3DRenderHelper);

// *****************************************************************************
//						struct I3DRenderHelper	
// *****************************************************************************


#ifndef qDemoVersion //regular interface

/// \addtogroup ExternalInterface
/// \{

// ****************************************************************************
//								I3DRenderHelper
// 
/// The Render Helper is the class the controls the rendering. The render helper
/// use a final renderer to render an image or a movie. The render helper provides
/// services such as tiling and multiprocessor support.
///
/// <P>You cannot implement your own RenderHelper. However you can instantiate it
/// to render previews or images. To instantiante a renderHelper, use the following
/// code:</P>
///
/// \code
/// 
/// TMCCountedPtr<IMCUnknown> unknown;
/// gComponentUtilities->CreateIUnknown('rhlp','1st ',NULL,&unknown);
/// ThrowIfNil(unknown);
///
/// TMCCountedPtr<I3DRenderHelper> renderHelper;
/// unknown->QueryInterface(IID_I3DRenderHelper,(void**)&renderHelper);
/// ThrowIfNil(renderHelper);
///
/// \endcode
///
/// If you already have a scene document in memory, you can access the renderHelper
/// of the scene by using the following code:
///
/// \code
///
/// TMCCountedPtr<I3DRenderingModule> renderingModule;
/// scene->GetSceneRenderingModule(&renderingModule);
///
/// TMCCountedPtr<I3DRenderHelper> renderHelper;
/// renderingModule->GetRenderHelper(&renderHelper);
///
/// \endcode
///
/// <P>All the 'set' functions only modify the renderHelper settings and not the
/// sceneRenderingModule settings</P>
/// 
struct I3DRenderHelper : public IMCUnknown
{
	// ****************************************************************************
	//								SetScene
	// 
	/// Set the scene that will be rendered.
	/// 
	/// \param scene  The scene that will be rendered.
	/// 
	virtual MCCOMErr	MCCOMAPI	SetScene(I3DShScene *scene)=0;

	// ****************************************************************************
	//								SetCamera
	// 
	/// Sets the rendering camera.
	/// 
	/// \param camera  The rendering camera.
	/// 
	virtual MCCOMErr	MCCOMAPI	SetCamera(I3DShCamera *camera)=0;

	// ****************************************************************************
	//								SetRenderSize
	// 
	/// Sets the size of the production frame ( width,height are in pixel )
	/// 
	/// \param width              width of the production frame in pixel
	/// \param height             height of the production frame in pixel
	/// \param pixelAspectRation  Ratio between the width and height of a pixel.
	/// 
	virtual MCCOMErr	MCCOMAPI	SetRenderSize(uint32 width,uint32 height,real pixelAspectRation=1.0f)=0;

	// ****************************************************************************
	//								SetBufferNeeds
	// 
	/// Sets the GBuffers that need to be rendered.
	/// 
	/// \param needs  A bitfield that specifies which GBuffer should be rendered.
	/// 
	virtual MCCOMErr	MCCOMAPI	SetBufferNeeds(RenderFilterNeeds &needs)=0;

	// ****************************************************************************
	//								EnablePostRendering
	// 
	/// Enable/Disable post rendering
	/// 
	/// \param enable  True if the postrendering is enabled.
	/// 
	virtual MCCOMErr	MCCOMAPI	EnablePostRendering(boolean enable)=0;

	// ****************************************************************************
	//								EnableMultiPass
	// 
	/// Enable/Disable the rendering of the multipass elements.
	/// 
	/// \param enable  True if the multipass is enabled.
	/// 
	virtual MCCOMErr	MCCOMAPI	EnableMultiPass(boolean enable)=0;

	// ****************************************************************************
	//								SetTiling
	// 
	/// Sets the size of a tile for the rendering. Note that the actual size of the
	/// tiles might be slightly bigger since the renderer will be given a chance
	/// to optimize the tile size for best performance.
	/// 
	/// \param tileWidth   Width in pixel of a tile.
	/// \param tileHeight  Height in pixel of a tile.
	/// 
	virtual MCCOMErr	MCCOMAPI	SetTiling(real tileWidth,real tileHeight)=0;


	// ****************************************************************************
	//								StartNetworkRendering
	// 
	/// Perform a network rendering session. This function is used by rendering
	/// node when they start the network rendering.
	/// 
	/// \param stream        An open stream of communication with the server
	/// \param syncThreadID  The id of the current thread
	/// 
	virtual void		MCCOMAPI	StartNetworkRendering(TMCNetStream& stream,int32 syncThreadID)=0;

	// ****************************************************************************
	//								RenderArea
	// 
	/// Renders one frame using the current settings
	/// 
	/// \param callbacks      Callbacks
	/// \param synch          False if a new non-preemptive thread must be launched for the rendering.
	/// \param synchThreadID  Identifier of the thread if synch is true   
	/// \param renderArea     SubArea to render (if null, we use production frame)
	/// 
	virtual MCCOMErr	MCCOMAPI	RenderArea(
										I3DRenderingCallbacks*	callbacks,				// callbacks called during rendering
										boolean					synch=true,				// if false, we launch a non-preemptive thread
										int32					synchThreadID=0,		// if (synch==true) id of the thread we are in, ( 0 will always work....)
										const TRenderArea*		renderArea=NULL)=0;		// 

	// ****************************************************************************
	//								GetRasterLayer
	// 
	/// Returns the color buffer (must be called within a callback of the rendering)
	/// 
	/// \param rasterLayer  The color buffer.
	/// 
	virtual MCCOMErr	MCCOMAPI	GetRasterLayer(IShRasterLayer ** rasterLayer) = 0;

	// ****************************************************************************
	//								GetGBuffers
	// 
	/// Returns an array containing the gBuffers that have been calculated. The order
	/// is the order of their identifiers.
	/// 
	/// \param gBuffers  The array of GBuffers.
	/// 
	virtual MCCOMErr	MCCOMAPI	GetGBuffers(TMCCountedPtrArray<IShChannel> &gBuffers)=0;

	// ****************************************************************************
	//								AbortRendering
	// 
	/// Stops the current rendering if there is one.
	/// 
	virtual MCCOMErr	MCCOMAPI	AbortRendering()=0;

	// ****************************************************************************
	//								PauseRendering
	// 
	/// Pauses the current rendering
	/// 
	virtual MCCOMErr	MCCOMAPI	PauseRendering()=0;

	// ****************************************************************************
	//								CreateRendererNoAddRef
	// 
	/// Create a new renderer that will be used for the next rendering.
	/// 
	/// \param classID  The classID of the final renderer to use.
	/// 
	virtual IShParameterComponent* MCCOMAPI CreateRendererNoAddRef(IDType classID)=0;

	// ****************************************************************************
	//								GetIsInBatchQueue
	// 
	/// Return the current rendering mode
	/// 
	virtual	boolean		MCCOMAPI	GetIsInBatchQueue()=0;

	// ****************************************************************************
	//								IsStillRendering
	// 
	/// Returns true as long as the rendering is not finished
	/// 
	virtual boolean		MCCOMAPI	IsStillRendering()=0;

	// ****************************************************************************
	//								SetAlphaChannelOptions
	// 
	/// Call to control the rendering of the alpha channel
	/// 
	/// \param renderAlpha           true if the alpha should be rendered 
	/// \param usePreMultipledAlpha  true if the alpha should be premultiplied
	/// 
	virtual void		MCCOMAPI	SetAlphaChannelOptions(boolean renderAlpha,boolean usePreMultipledAlpha=false)=0;
};

/// \}

#else 	//(qDemoVersion) begin scrambled interface
struct I3DRenderHelper : public IMCUnknown
{
	virtual MCCOMErr	MCCOMAPI	AbortRendering()=0;
	virtual void		MCCOMAPI	SetAlphaChannelOptions(boolean renderAlpha,boolean usePreMultipledAlpha=false)=0;
	virtual boolean		MCCOMAPI	IsStillRendering()=0;
	virtual MCCOMErr	MCCOMAPI	RenderArea(
										I3DRenderingCallbacks*	callbacks,				// callbacks called during rendering
										boolean					synch=true,				// if false, we launch a non-preemptive thread
										int32					synchThreadID=0,		// if (synch==true) id of the thread we are in, ( 0 will always work....)
										const TRenderArea*		renderArea=NULL)=0;		// subArea to render ( if null, we use production frame)	
	virtual MCCOMErr	MCCOMAPI	GetRasterLayer(IShRasterLayer ** rasterLayer) = 0;
	virtual MCCOMErr	MCCOMAPI	SetRenderSize(uint32 width,uint32 height,real pixelAspectRation=1.0f)=0;
	virtual MCCOMErr	MCCOMAPI	SetBufferNeeds(RenderFilterNeeds &needs)=0;
	virtual MCCOMErr	MCCOMAPI	EnablePostRendering(boolean enable)=0;
	virtual MCCOMErr	MCCOMAPI	SetScene(I3DShScene *scene)=0;
	virtual void		MCCOMAPI	StartNetworkRendering(TMCNetStream& stream,int32 syncThreadID)=0;
	virtual MCCOMErr	MCCOMAPI	SetCamera(I3DShCamera *camera)=0;	
	virtual MCCOMErr	MCCOMAPI	GetGBuffers(TMCCountedPtrArray<IShChannel> &gBuffers)=0;
	virtual MCCOMErr	MCCOMAPI	SetTiling(real tileWidth,real tileHeight)=0;	
	virtual IShParameterComponent* MCCOMAPI CreateRendererNoAddRef(IDType classID)=0;
	virtual	boolean		MCCOMAPI	GetIsInBatchQueue()=0;
//	virtual boolean		MCCOMAPI	IsRendering()=0;
};
#endif	//(qDemoVersion) end scrambled

#endif