//////////////////////////////////////////////////////////////////////
//
//                             Pixie
//
// Copyright © 1999 - 2003, Okan Arikan
//
// Contact: okan@cs.berkeley.edu
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
// 
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
// 
// You should have received a copy of the GNU General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////
//
//  File				:	options.h
//  Classes				:	COptions
//  Description			:
//
////////////////////////////////////////////////////////////////////////
#ifndef OPTIONS_H
#define OPTIONS_H

#include "common/global.h"
#include "common/containers.h"
#include "common/algebra.h"
#include "rendererc.h"
#include "xform.h"
#include "ri.h"
#include "shader.h"
#include "dsply.h"

// Possible projections
typedef enum {
	OPTIONS_PROJECTION_PERSPECTIVE,			// Perspective projection
	OPTIONS_PROJECTION_ORTHOGRAPHIC			// Orthographic projection
} EProjectionType;

// The search paths are kept as a linked list of the following items
typedef struct TSearchpath {
	char		*directory;
	TSearchpath	*next;
} TSearchpath;

// This is the depth filter type
typedef enum {
	DEPTH_MIN,
	DEPTH_MAX,
	DEPTH_AVG,
	DEPTH_MID
} EDepthFilter;

// Options flags
const	unsigned int		OPTIONS_FLAGS_CUSTOM_SCREENWINDOW	=	1<<0;	// The screenwindow is fixed
const	unsigned int		OPTIONS_FLAGS_CUSTOM_FRAMEAR		=	1<<1;	// The frame aspect ratio is fixed
const	unsigned int		OPTIONS_FLAGS_CUSTOM_RESOLUTION		=	1<<2;	// The resolution is fixed
const	unsigned int		OPTIONS_FLAGS_CUSTOM_CLIPPING		=	1<<3;	// The near/far clipping planes have been set by user
const	unsigned int		OPTIONS_FLAGS_FALSECOLOR_RAYTRACES	=	1<<4;	// Create a false color image of the effort being spent on the image
const	unsigned int		OPTIONS_FLAGS_INHERIT_ATTRIBUTES	=	1<<12;	// The object instance inherit attributes from the parent
const	unsigned int		OPTIONS_FLAGS_MOTIONBLUR			=	1<<13;	// We have motion blur in the scene
const	unsigned int		OPTIONS_FLAGS_FOCALBLUR				=	1<<14;	// We have depth of field in the scene
const	unsigned int		OPTIONS_FLAGS_DEEP_SHADOW_RENDERING	=	1<<16;	// We're rendering a deep shadow map
const	unsigned int		OPTIONS_FLAGS_USE_RADIANCE_CACHE	=	1<<17;	// Use the new radiance cache
const	unsigned int		OPTIONS_FLAGS_PROGRESS				=	1<<18;	// Display the progress


///////////////////////////////////////////////////////////////////////
// Class				:	COptions
// Description			:	This class settings that are constant accross a frame
// Comments				:
// Date last edited		:	7/4/2001
class COptions {
public:


	///////////////////////////////////////////////////////////////////////
	// Class				:	CDisplay
	// Description			:	Holds a display setting
	// Comments				:
	// Date last edited		:	7/4/2001
	class CDisplay {
	public:
									///////////////////////////////////////////////////////////////////////
									// Class				:	TDisplayParameter
									// Description			:	Holds a display parameter
									// Comments				:
									// Date last edited		:	7/4/2001
									typedef struct {
										char			*name;
										ParameterType	type;
										int				numItems;
										void			*data;
									} TDisplayParameter;


									CDisplay();
									CDisplay(const CDisplay *);
									~CDisplay();

		char						*outDevice;		// The name of the out device
		char						*outName;		// The name of the image
		char						*outSamples;	// The samples to go into the display
		CDisplay					*next;
		float						quantizer[5];	// The quantization data

		int							numParameters;
		TDisplayParameter			*parameters;
	};

	///////////////////////////////////////////////////////////////////////
	// Class				:	CClipPlane
	// Description			:	Holds a user defined clip plane description
	// Comments				:
	// Date last edited		:	7/4/2001
	class CClipPlane {
	public:
									CClipPlane();
									CClipPlane(const CClipPlane *);

		vector						normal;			// Normal vector in camera space
		float						d;				// normal.P+d=0;
		CClipPlane					*next;			// Next clipping plane
	};

	
								COptions();
								COptions(const COptions *);
	virtual						~COptions();

								// The following method is used to convert from a custom color space to RGB if- entered
	void						convertColor(vector &c,const float *f)	const;









								////////////////////////////////////////////////////////////////////
								// options start here
								////////////////////////////////////////////////////////////////////
	int							xres,yres;										// Output resolution

	int							frame;											// The frame number given by frameBegin

	float						pixelAR;										// Pixel aspect ratio
	float						frameAR;										// Frame aspect ratio

	float						cropLeft,cropRight,cropTop,cropBottom;			// The crop window
	float						screenLeft,screenRight,screenTop,screenBottom;	// The screen window

	float						clipMin,clipMax;								// Clipping bounds

	float						pixelVariance;									// The maximum tolerable pixel color variation

	float						jitter;											// Amount of jitter in samples

	char						*hider;											// Hider name

	TSearchpath					*archivePath;									// RIB search path
	TSearchpath					*proceduralPath;								// Procedural primitive search path
	TSearchpath					*texturePath;									// Texture search path
	TSearchpath					*shaderPath;									// Shader search path
	TSearchpath					*displayPath;									// Display search path
	char						*temporaryPath;									// Where tmp files are stored

	int							pixelXsamples,pixelYsamples;					// Number of samples to take in X and Y

	float						gamma,gain;										// Gamma correction stuff

	float						pixelFilterWidth,pixelFilterHeight;				// Pixel filter data
	RtFilterFunc				pixelFilter;

	float						colorQuantizer[5];								// The quantization data
	float						depthQuantizer[5];

	CDisplay					*displays;										// List of displays to send the output

	CClipPlane					*clipPlanes;									// List of used defined clipping planes

	float						relativeDetail;									// The relative detail multiplier

	EProjectionType				projection;										// Projection type
	float						fov;											// Field of view for perspective projection

	int							nColorComps;									// Custom color space stuff
	float						*fromRGB,*toRGB;

	float						fstop,focallength,focaldistance;				// Depth of field stuff

	float						shutterOpen,shutterClose;						// Motion blur stuff

	unsigned int				flags;											// Flags

	CArray<CShaderInstance *>	*allLights;										// An array of all allocated lights in the options context

								////////////////////////////////////////////////////////////////////
								// Pixie dependent options
								////////////////////////////////////////////////////////////////////

	int							endofframe;										// The end of frame statstics number
	char						*filelog;										// The name of the log file

	int							maxTextureSize;									// Maximum amount of texture data to keep in memory (in bytes)

	int							maxShaderCache;									// The maximum shader cache amount

	int							maxGridSize;									// Maximum number of points to shade at a time

	int							maxRayDepth;									// Maximum raytracing recursion depth

	int							maxPhotonDepth;									// The maximum number of photon bounces

	int							bucketWidth,bucketHeight;						// Bucket dimentions in samples

	int							maxEyeSplits;									// Maximum number of eye splits
																				// The number of times the bucket will be rendered
	int							maxHierarchyDepth;								// The maximum depth of the hierarchy
	int							maxHierarchyLeafObjects;						// The maximum number of objects for a leaf

	float						tsmThreshold;									// Transparency shadow map threshold

	char						*causticIn,*causticOut;							// The caustics in/out file name
	char						*globalIn,*globalOut;							// The global photon map 
	char						*volumeIn,*volumeOut;							// The volume photon map 

	int							numEmitPhotons;									// The number of photons to emit for the scene

	int							shootStep;										// The number of rays to shoot at a time

	EDepthFilter				depthFilter;									// Holds the depth filter type
};


TSearchpath					*optionsGetSearchPath(const char *,TSearchpath *);				// Compute the search path

#endif

