/*************************************************************************
 * ri.h - header file for Entropy                                        *
 *************************************************************************/

#ifndef RI_H
#define RI_H 1

#ifdef __cplusplus
extern "C" {
#endif

#define RtVoid  void
typedef short   RtBoolean;
typedef int     RtInt;
typedef float   RtFloat;
typedef char   *RtToken;
typedef char   *RtString;
typedef void   *RtPointer;

typedef RtFloat RtColor[3];
typedef RtFloat RtPoint[3];
typedef RtFloat RtVector[3];
typedef RtFloat RtNormal[3];
typedef RtFloat RtHpoint[4];
typedef RtFloat RtMatrix[4][4];
typedef RtFloat RtBasis[4][4];
typedef RtFloat RtBound[6];

typedef RtFloat (*RtFilterFunc)(RtFloat, RtFloat, RtFloat, RtFloat);
typedef void  (*RtErrorHandler)(RtInt code, RtInt severity, char *msg);
typedef void  (*RtProcSubdivFunc)(RtPointer data, RtFloat deta);
typedef void  (*RtProcFreeFunc)(RtPointer data);
typedef void  (*RtArchiveCallback)(RtToken, char *, ...);
typedef void  (*RtFunc)();

typedef RtPointer RtObjectHandle;
typedef RtPointer RtLightHandle;
typedef RtPointer RtContextHandle;

#define RI_FALSE    0
#define RI_TRUE     1
#define RI_INFINITY (RtFloat)1.0e38
#define RI_EPSILON  (RtFloat)1.0e-10

#ifndef NULL
#define NULL 0
#endif
#define RI_NULL NULL


extern RtToken  RI_FRAMEBUFFER, RI_FILE;
extern RtToken  RI_RGB, RI_RGBA, RI_RGBZ, RI_RGBAZ, RI_A, RI_Z, RI_AZ;
extern RtToken  RI_PERSPECTIVE, RI_ORTHOGRAPHIC;
extern RtToken  RI_HIDDEN, RI_PAINT;
extern RtToken  RI_CONSTANT, RI_SMOOTH;
extern RtToken  RI_FLATNESS, RI_FOV;

extern RtToken  RI_AMBIENTLIGHT, RI_POINTLIGHT, RI_DISTANTLIGHT, RI_SPOTLIGHT;
extern RtToken  RI_INTENSITY, RI_LIGHTCOLOR, RI_FROM, RI_TO, RI_CONEANGLE,
                RI_CONEDELTAANGLE, RI_BEAMDISTRIBUTION;
extern RtToken  RI_MATTE, RI_METAL, RI_SHINYMETAL,
                RI_PLASTIC, RI_PAINTEDPLASTIC;
extern RtToken  RI_KA, RI_KD, RI_KS, RI_ROUGHNESS, RI_KR,
                RI_TEXTURENAME, RI_SPECULARCOLOR;
extern RtToken  RI_DEPTHCUE, RI_FOG, RI_BUMPY;
extern RtToken  RI_MINDISTANCE, RI_MAXDISTANCE, RI_BACKGROUND,
                RI_DISTANCE, RI_AMPLITUDE;

extern RtToken  RI_INSIDE, RI_OUTSIDE, RI_LH, RI_RH;
extern RtToken  RI_P, RI_PZ, RI_PW, RI_N, RI_NP, RI_CS,
                RI_OS, RI_S, RI_T, RI_ST;
extern RtToken  RI_BILINEAR, RI_BICUBIC;
extern RtToken  RI_PRIMITIVE, RI_INTERSECTION, RI_UNION, RI_DIFFERENCE;
extern RtToken  RI_PERIODIC, RI_NONPERIODIC, RI_CLAMP, RI_BLACK, RI_MIRROR;
extern RtToken  RI_IGNORE, RI_PRINT, RI_ABORT, RI_HANDLER;
extern RtToken  RI_ORIGIN, RI_IDENTIFIER, RI_NAME;
extern RtToken  RI_COMMENT, RI_STRUCTURE, RI_VERBATIM;
extern RtToken  RI_LINEAR, RI_CUBIC, RI_WIDTH, RI_CONSTANTWIDTH;

extern RtToken  RI_CURRENT, RI_WORLD, RI_OBJECT, RI_SHADER;
extern RtToken  RI_RASTER, RI_NDC, RI_SCREEN, RI_CAMERA, RI_EYE;

extern RtToken  RI_HOLE, RI_CREASE, RI_CORNER, RI_INTERPOLATEBOUNDARY;

extern RtToken  RI_USER;

extern RtBasis  RiBezierBasis, RiBSplineBasis, RiCatmullRomBasis,
                RiHermiteBasis, RiPowerBasis;

#define RI_BEZIERSTEP       ((RtInt)3)
#define RI_BSPLINESTEP      ((RtInt)1)
#define RI_CATMULLROMSTEP   ((RtInt)1)
#define RI_HERMITESTEP      ((RtInt)2)
#define RI_POWERSTEP        ((RtInt)4)

extern RtInt RiLastError;



/* Basic control flow, scoping, stacks */
void RiBegin (RtToken name);
void RiEnd (void);
RtContextHandle RiGetContext (void);
void RiContext (RtContextHandle handle);
void RiFrameBegin (RtInt number);
void RiFrameEnd (void);
void RiWorldBegin (void);
void RiWorldEnd (void);
void RiAttributeBegin (void);
void RiAttributeEnd (void);
void RiTransformBegin (void);
void RiTransformEnd (void);
void RiSolidBegin (RtToken type);
void RiSolidEnd(void);
void RiMotionBegin (RtInt N, ...);
void RiMotionBeginV (RtInt N, RtFloat times[]);
void RiMotionEnd (void);
RtToken RiDeclare (char *name, char *declaration);

/* Options */
void RiClipping (RtFloat hither, RtFloat yon);
void RiClippingPlane (RtFloat px, RtFloat py, RtFloat pz,
		      RtFloat nx, RtFloat ny, RtFloat nz);
void RiColorSamples (RtInt N, RtFloat *nRGB, RtFloat *RGBn);
void RiCropWindow (RtFloat xmin, RtFloat xmax, RtFloat ymin, RtFloat ymax);
void RiDepthOfField (RtFloat fstop, RtFloat focallength, RtFloat focaldistance);
void RiDisplay  (char *name, RtToken type, RtToken mode, ...);
void RiDisplayV (char *name, RtToken type, RtToken mode,
		 RtInt n, RtToken tokens[], RtPointer params[]);
void RiExposure (RtFloat gain, RtFloat gamma);
void RiFormat (RtInt xres, RtInt yres, RtFloat aspect);
void RiFrameAspectRatio (RtFloat aspect);
void RiHider  (RtToken type, ...);
void RiHiderV (RtToken type, RtInt n, RtToken tokens[], RtPointer params[]);
void RiImager  (char *name, ...);
void RiImagerV (char *name, RtInt n, RtToken tokens[], RtPointer params[]);
void RiOption  (char *name, ...);
void RiOptionV (char *name, RtInt n, RtToken tokens[], RtPointer params[]);
void RiPixelFilter (RtFilterFunc function, RtFloat xwidth, RtFloat ywidth);
void RiPixelSamples (RtFloat xsamples, RtFloat ysamples);
void RiPixelVariance (RtFloat variation);
void RiProjection  (char *name, ...);
void RiProjectionV (char *name, RtInt n, RtToken tokens[], RtPointer params[]);
void RiQuantize (RtToken type, RtInt one, RtInt qmin, RtInt qmax, RtFloat ampl);
void RiRelativeDetail (RtFloat relativedetail);
void RiScreenWindow (RtFloat left, RtFloat right, RtFloat bot, RtFloat top);
void RiShutter (RtFloat opentime, RtFloat closetime);


/* Filters */
RtFloat RiBoxFilter (RtFloat x, RtFloat y, RtFloat xwidth, RtFloat ywidth);
RtFloat RiCatmullRomFilter (RtFloat x, RtFloat y, RtFloat xwidth, RtFloat ywidth);
RtFloat RiGaussianFilter (RtFloat x, RtFloat y, RtFloat xwidth, RtFloat ywidth);
RtFloat RiSincFilter (RtFloat x, RtFloat y, RtFloat xwidth, RtFloat ywidth);
RtFloat RiTriangleFilter (RtFloat x, RtFloat y, RtFloat xwidth, RtFloat ywidth);

/* Attributes */
void RiAttribute  (char *name, ...);
void RiAttributeV (char *name, RtInt n, RtToken tokens[], RtPointer params[]);
void RiBound (RtBound bound);
void RiColor (RtColor Cs);
void RiDetail (RtBound bound);
void RiDetailRange (RtFloat minvis, RtFloat lowtran,
		    RtFloat uptran, RtFloat maxvis);
void RiGeometricApproximation (RtToken type, RtFloat value);
void RiGeometricRepresentation (RtToken type);
void RiIlluminate (RtLightHandle light, RtBoolean onoff);
void RiMatte (RtBoolean onoff);
void RiOpacity (RtColor Cs);
void RiOrientation (RtToken orientation);
void RiReverseOrientation (void);
void RiShadingInterpolation (RtToken type);
void RiShadingRate (RtFloat size);
void RiSides (RtInt nsides);
void RiTextureCoordinates (RtFloat s1, RtFloat t1, RtFloat s2, RtFloat t2,
			   RtFloat s3, RtFloat t3, RtFloat s4, RtFloat t4);

/* Shaders */
RtLightHandle RiAreaLightSource  (char *name, ...);
RtLightHandle RiAreaLightSourceV (char *name, RtInt n,
				  RtToken tokens[], RtPointer params[]);
void RiAtmosphere  (char *name, ...);
void RiAtmosphereV (char *name, RtInt n, RtToken tokens[], RtPointer params[]);
void RiDisplacement  (char *name, ...);
void RiDisplacementV (char *name, RtInt n,
			RtToken tokens[], RtPointer params[]);
void RiExterior  (char *name, ...);
void RiExteriorV (char *name, RtInt n, RtToken tokens[], RtPointer params[]);
void RiInterior  (char *name, ...);
void RiInteriorV (char *name, RtInt n, RtToken tokens[], RtPointer params[]);
RtLightHandle RiLightSource  (char *name, ...);
RtLightHandle RiLightSourceV (char *name, RtInt n,
			      RtToken tokens[], RtPointer params[]);
void RiSurface  (char *name, ...);
void RiSurfaceV (char *name, RtInt n, RtToken tokens[], RtPointer params[]);

/* Transformations */
void RiConcatTransform (RtMatrix transform);
void RiCoordinateSystem (RtToken space);
void RiCoordSysTransform (RtToken space);
void RiIdentity (void);
void RiPerspective (RtFloat fov);
void RiRotate (RtFloat angle, RtFloat dx, RtFloat dy, RtFloat dz);
void RiScale (RtFloat dx, RtFloat dy, RtFloat dz);
void RiSkew (RtFloat angle, RtFloat dx1, RtFloat dy1, RtFloat dz1,
	     RtFloat dx2, RtFloat dy2, RtFloat dz2);
void RiTransform (RtMatrix transform);
void RiTranslate (RtFloat dx, RtFloat dy, RtFloat dz);

RtPoint *RiTransformPoints (RtToken fromspace, RtToken tospace,
			    RtInt npoints, RtPoint *points);

/* Geometric Primitives (and a couple gprim-specific attributes) */
void RiBasis (RtBasis ubasis, RtInt ustep, RtBasis vbasis, RtInt vstep);
void RiBlobby (RtInt nleaf, RtInt ncode, RtInt code[],
	       RtInt nflt, RtFloat flt[], RtInt nstr, RtString str[], ...);
void RiBlobbyV (RtInt nleaf, RtInt ncode, RtInt code[],
		RtInt nflt, RtFloat flt[], RtInt nstr, RtString str[],
		RtInt n, RtToken tokens[], RtPointer params[]);
void RiCone (RtFloat height, RtFloat radius, RtFloat thetamax, ...);
void RiConeV (RtFloat height, RtFloat radius, RtFloat thetamax, 
	      RtInt n, RtToken tokens[], RtPointer params[]);
void RiCurves (RtToken degree, RtInt ncurves,
	       RtInt nverts[], RtToken wrap, ...);
void RiCurvesV (RtToken degree, RtInt ncurves, RtInt nverts[], RtToken wrap,
		RtInt n, RtToken tokens[], RtPointer params[]);
void RiCylinder (RtFloat radius, RtFloat zmin, RtFloat zmax, 
		 RtFloat thetamax, ...);
void RiCylinderV (RtFloat radius, RtFloat zmin, RtFloat zmax, RtFloat thetamax,
		  RtInt n, RtToken tokens[], RtPointer params[]);
void RiDisk (RtFloat height, RtFloat radius, RtFloat thetamax, ...);
void RiDiskV (RtFloat height, RtFloat radius, RtFloat thetamax, 
	      RtInt n, RtToken tokens[], RtPointer params[]);
void RiGeneralPolygon (RtInt nloops, RtInt *nverts, ...);
void RiGeneralPolygonV (RtInt nloops, RtInt *nverts,
			RtInt n, RtToken tokens[], RtPointer params[]);
void RiGeometry (RtToken type, ...);
void RiGeometryV (RtToken type, RtInt n, RtToken tokens[], RtPointer params[]);
void RiHyperboloid (RtPoint point1, RtPoint point2, RtFloat thetamax, ...);
void RiHyperboloidV (RtPoint point1, RtPoint point2, RtFloat thetamax, 
		     RtInt n, RtToken tokens[], RtPointer params[]);
void RiNuPatch (RtInt nu, RtInt uorder, RtFloat *uknot,
		  RtFloat umin, RtFloat umax, RtInt nv, RtInt vorder,
		  RtFloat *vknot, RtFloat vmin, RtFloat vmax, ...);
void RiNuPatchV (RtInt nu, RtInt uorder, RtFloat *uknot,
		 RtFloat umin, RtFloat umax, RtInt nv, RtInt vorder,
		 RtFloat *vknot, RtFloat vmin, RtFloat vmax, 
		 RtInt n, RtToken tokens[], RtPointer params[]);
void RiParaboloid (RtFloat rmax, RtFloat zmin,
		     RtFloat zmax, RtFloat thetamax, ...);
void RiParaboloidV (RtFloat rmax, RtFloat zmin, RtFloat zmax, RtFloat thetamax, 
		    RtInt n, RtToken tokens[], RtPointer params[]);
void RiPatch (RtToken type, ...);
void RiPatchV (RtToken type, RtInt n, RtToken tokens[], RtPointer params[]);
void RiPatchMesh (RtToken type, RtInt nu, RtToken uwrap,
		    RtInt nv, RtToken vwrap, ...);
void RiPatchMeshV (RtToken type, RtInt nu, RtToken uwrap, RtInt nv,
		   RtToken vwrap, RtInt n, RtToken tokens[], RtPointer params[]);
void RiPoints (RtInt npts,...);
void RiPointsV (RtInt npts, RtInt n, RtToken tokens[], RtPointer params[]);
void RiPointsGeneralPolygons (RtInt npolys, RtInt *nloops,
			      RtInt *nverts, RtInt *verts, ...);
void RiPointsGeneralPolygonsV (RtInt npolys, RtInt *nloops,
			       RtInt *nverts, RtInt *verts, 
			       RtInt n, RtToken tokens[], RtPointer params[]);
void RiPointsPolygons (RtInt npolys, RtInt *nverts, RtInt *verts, ...);
void RiPointsPolygonsV (RtInt npolys, RtInt *nverts, RtInt *verts, 
			RtInt n, RtToken tokens[], RtPointer params[]);
void RiPolygon (RtInt nvertices, ...);
void RiPolygonV (RtInt nvertices, RtInt n, RtToken tokens[], RtPointer params[]);
void RiSphere (RtFloat radius, RtFloat zmin,
	       RtFloat zmax, RtFloat thetamax, ...);
void RiSphereV (RtFloat radius, RtFloat zmin, RtFloat zmax, RtFloat thetamax,
		RtInt n, RtToken tokens[], RtPointer params[]);
void RiSubdivisionMesh (RtToken scheme, RtInt nfaces,
			RtInt nvertices[], RtInt vertices[],
			RtInt ntags, RtToken tags[], RtInt nargs[],
			RtInt intargs[], RtFloat floatargs[], ...);
void RiSubdivisionMeshV (RtToken scheme, RtInt nfaces,
			 RtInt nvertices[], RtInt vertices[],
			 RtInt ntags, RtToken tags[], RtInt nargs[],
			 RtInt intargs[], RtFloat floatargs[], 
			 RtInt n, RtToken tokens[], RtPointer params[]);
void RiTorus (RtFloat majorrad, RtFloat minorrad, RtFloat phimin,
	      RtFloat phimax, RtFloat thetamax, ...);
void RiTorusV (RtFloat majorrad, RtFloat minorrad, RtFloat phimin,
	       RtFloat phimax, RtFloat thetamax,
	       RtInt n, RtToken tokens[], RtPointer params[]);
void RiTrimCurve (RtInt nloops, RtInt *ncurves, RtInt *order,
		  RtFloat *knot, RtFloat *amin, RtFloat *amax,
		  RtInt *n, RtFloat *u, RtFloat *v, RtFloat *w);
/* Procedural primitives */
void RiProcedural (RtPointer data, RtBound bound,
		   RtProcSubdivFunc subdivfunc, RtProcFreeFunc freefunc);
void RiProcDelayedReadArchive (RtPointer data, RtFloat detail);
void RiProcRunProgram (RtPointer data, RtFloat detail);
void RiProcDynamicLoad (RtPointer data, RtFloat detail);
void RiProcFree (RtPointer data);
/* Object Instancing */
RtObjectHandle RiObjectBegin (void);
void RiObjectEnd (void);
void RiObjectInstance (RtObjectHandle handle);



/* Texture map creation */
void RiMakeCubeFaceEnvironment (char *px, char *nx, char *py,
				char *ny, char *pz, char *nz,
				char *tex, RtFloat fov, RtFilterFunc filterfunc,
				RtFloat swidth, RtFloat twidth, ...);
void RiMakeCubeFaceEnvironmentV (char *px, char *nx, char *py,
				 char *ny, char *pz, char *nz,
				 char *tex, RtFloat fov, RtFilterFunc filterfunc,
				 RtFloat swidth, RtFloat twidth,
				 RtInt n, RtToken tokens[], RtPointer params[]);
void RiMakeLatLongEnvironment (char *pic, char *tex, RtFilterFunc filterfunc,
			       RtFloat swidth, RtFloat twidth, ...);
void RiMakeLatLongEnvironmentV (char *pic, char *tex, RtFilterFunc filterfunc,
				RtFloat swidth, RtFloat twidth,
				RtInt n, RtToken tokens[], RtPointer params[]);
void RiMakeShadow (char *pic, char *tex, ...);
void RiMakeShadowV (char *pic, char *tex,
		    RtInt n, RtToken tokens[], RtPointer params[]);
void RiMakeTexture (char *pic, char *tex, RtToken swrap, RtToken twrap,
		    RtFilterFunc filterfunc, RtFloat swidth, RtFloat twidth, ...);
void RiMakeTextureV (char *pic, char *tex, RtToken swrap, RtToken twrap,
		     RtFilterFunc filterfunc, RtFloat swidth, RtFloat twidth,
		     RtInt n, RtToken tokens[], RtPointer params[]);

/* Error Handlers */
void RiErrorHandler (RtErrorHandler handler);
void RiErrorAbort (RtInt code, RtInt severity, char *message);
void RiErrorIgnore (RtInt code, RtInt severity, char *message);
void RiErrorPrint (RtInt code, RtInt severity, char *message);

/* Reading and writing archive files */
void RiArchiveRecord (RtToken type, char *format, ...);
void RiReadArchive (RtString filename, RtArchiveCallback callback, ...);
void RiReadArchiveV (RtString filename, RtArchiveCallback callback,
		     int n, RtToken tokens[], RtPointer params[]);



/*
    Error codes

     1 - 10     System and File errors
    11 - 20     Program Limitations
    21 - 40     State Errors
    41 - 60     Parameter and Protocol Errors
    61 - 80     Execution Errors
*/

#define RIE_NOERROR         0

#define RIE_NOMEM           1       /* Out of memory */
#define RIE_SYSTEM          2       /* Miscellaneous system error */
#define RIE_NOFILE          3       /* File nonexistant */
#define RIE_BADFILE         4       /* Bad file format */
#define RIE_VERSION         5       /* File version mismatch */
#define RIE_DISKFULL        6       /* Target disk is full */

#define RIE_INCAPABLE      11       /* Optional RI feature */
#define RIE_OPTIONAL       11       /* Optional RI feature */
#define RIE_UNIMPLEMENT    12       /* Unimplemented feature */
#define RIE_LIMIT          13       /* Arbitrary program limit */
#define RIE_BUG            14       /* Probably a bug in renderer */

#define RIE_NOTSTARTED     23       /* RiBegin not called */
#define RIE_NESTING        24       /* Bad begin-end nesting */
#define RIE_NOTOPTIONS     25       /* Invalid state for options */
#define RIE_NOTATTRIBS     26       /* Invalid state for attributes */
#define RIE_NOTPRIMS       27       /* Invalid state for primitives */
#define RIE_ILLSTATE       28       /* Other invalid state */
#define RIE_BADMOTION      29       /* Badly formed motion block */
#define RIE_BADSOLID       30       /* Badly formed solid block */

#define RIE_BADTOKEN       41       /* Invalid token for request */
#define RIE_RANGE          42       /* Parameter out of range */
#define RIE_CONSISTENCY    43       /* Parameters inconsistent */
#define RIE_BADHANDLE      44       /* Bad object/light handle */
#define RIE_NOSHADER       45       /* Can't load requested shader */
#define RIE_MISSINGDATA    46       /* Required parameters not provided */
#define RIE_SYNTAX         47       /* Declare type syntax error */

#define RIE_MATH           61       /* Zerodivide, noninvert matrix, etc. */

#define RIE_MISC          101       /* Uncategorized error */


/* Error severity levels */
#define RIE_INFO            0       /* Rendering stats & other info */
#define RIE_WARNING         1       /* Something seems wrong, maybe okay */
#define RIE_ERROR           2       /* Problem.  Results may be wrong */
#define RIE_SEVERE          3       /* So bad you should probably abort */

#ifdef __cplusplus
}
#endif


#endif  /* RI_H */

