1 ////////////////////////////////////////////////////////////////////// 2 // 3 // Pixie 4 // 5 // Copyright � 1999 - 2003, Okan Arikan 6 // 7 // Contact: okan@cs.utexas.edu 8 // 9 // This library is free software; you can redistribute it and/or 10 // modify it under the terms of the GNU Lesser General Public 11 // License as published by the Free Software Foundation; either 12 // version 2.1 of the License, or (at your option) any later version. 13 // 14 // This library is distributed in the hope that it will be useful, 15 // but WITHOUT ANY WARRANTY; without even the implied warranty of 16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 // Lesser General Public License for more details. 18 // 19 // You should have received a copy of the GNU Lesser General Public 20 // License along with this library; if not, write to the Free Software 21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 // 23 /////////////////////////////////////////////////////////////////////// 24 /////////////////////////////////////////////////////////////////////// 25 // 26 // File : renderer.h 27 // Classes : CRendererContext 28 // Description : This file defines the main renderer interface 29 // 30 //////////////////////////////////////////////////////////////////////// 31 #ifndef RENDERER_H 32 #define RENDERER_H 33 34 #include "common/global.h" 35 #include "common/algebra.h" 36 #include "shader.h" 37 #include "rendererc.h" // Renderer constants 38 #include "texture.h" 39 #include "options.h" 40 #include "shader.h" 41 #include "object.h" 42 #include "shadeop.h" 43 #include "resource.h" 44 #include "riInterface.h" 45 #include "variable.h" 46 47 48 class CShadingContext; 49 class CIrradianceCache; 50 class CPhotonMap; 51 class CParticipatingMedium; 52 class CDelayedObject; 53 class CDelayedInstance; 54 class CNetFileMapping; 55 56 /////////////////////////////////////////////////////////////////////// 57 // Class : CRendererContext 58 // Description : Holds the global rendering context 59 // Comments : 60 class CRendererContext : public CRiInterface { 61 public: 62 63 CRendererContext(const char *ribName=NULL,const char *netString=NULL); 64 ~CRendererContext(); 65 66 /////////////////////////////////////////////////////////////////////// 67 // Renderer interface 68 /////////////////////////////////////////////////////////////////////// 69 void RiDeclare(const char *,const char *); 70 71 void RiFrameBegin(int); 72 void RiFrameEnd(void); 73 void RiWorldBegin(void); 74 void RiWorldEnd(void); 75 76 void RiFormat(int xres,int yres,float aspect); 77 void RiFrameAspectRatio(float aspect); 78 void RiScreenWindow(float left,float right,float bot,float top); 79 void RiCropWindow(float xmin,float xmax,float ymin,float ymax); 80 void RiProjectionV(const char *name,int n,const char *tokens[],const void *params[]); 81 void RiClipping(float hither,float yon); 82 void RiClippingPlane(float x,float y,float z,float nx,float ny,float nz); 83 void RiDepthOfField(float fstop,float focallength,float focaldistance); 84 void RiShutter(float smin,float smax); 85 86 void RiPixelVariance(float variation); 87 void RiPixelSamples(float xsamples,float ysamples); 88 void RiPixelFilter(float (*function)(float,float,float,float),float xwidth,float ywidth); 89 void RiExposure(float gain,float gamma); 90 void RiImagerV(const char *name,int n,const char *tokens[],const void *params[]); 91 void RiQuantize(const char * type,int one,int qmin,int qmax,float ampl); 92 void RiDisplayV(const char *name,const char * type,const char * mode,int n,const char *tokens[],const void *params[]); 93 void RiCustomDisplayV(const char *name, RtToken mode, RtDisplayStartFunction, RtDisplayDataFunction, RtDisplayFinishFunction, RtInt n, RtToken tokens[], RtPointer params[]); 94 void RiDisplayChannelV(const char * channel,int n,const char *tokens[],const void *params[]); 95 96 void RiHiderV(const char * type,int n,const char *tokens[],const void *params[]); 97 void RiColorSamples(int N,float *nRGB,float *RGBn); 98 void RiRelativeDetail(float relativedetail); 99 void RiOptionV(const char *name,int n,const char *tokens[],const void *params[]); 100 101 void RiAttributeBegin(void); 102 void RiAttributeEnd(void); 103 void RiColor(float *Cs); 104 void RiOpacity(float *Cs); 105 void RiTextureCoordinates(float s1,float t1,float s2,float t2,float s3,float t3,float s4,float t4); 106 107 void *RiLightSourceV(const char *name,int n,const char *tokens[],const void *params[]); 108 void *RiAreaLightSourceV(const char *name,int n,const char *tokens[],const void *params[]); 109 110 void RiIlluminate(const void *light,int onoff); 111 void RiSurfaceV(const char *name,int n,const char *tokens[],const void *params[]); 112 void RiAtmosphereV(const char *name,int n,const char *tokens[],const void *params[]); 113 void RiInteriorV(const char *name,int n,const char *tokens[],const void *params[]); 114 void RiExteriorV(const char *name,int n,const char *tokens[],const void *params[]); 115 void RiShadingRate(float size); 116 void RiShadingInterpolation(const char * type); 117 void RiMatte(int onoff); 118 119 void RiBound(float *bound); 120 void RiDetail(float *bound); 121 void RiDetailRange(float minvis,float lowtran,float uptran,float maxvis); 122 void RiGeometricApproximation(const char * type,float value); 123 void RiGeometricRepresentation(const char * type); 124 void RiOrientation(const char * orientation),RiReverseOrientation(void); 125 void RiSides(int nsides); 126 127 void RiIdentity(void); 128 void RiTransform(float transform[][4]); 129 void RiConcatTransform(float transform[][4]); 130 void RiPerspective(float fov); 131 void RiTranslate(float dx,float dy,float dz); 132 void RiRotate(float angle,float dx,float dy,float dz); 133 void RiScale(float dx,float dy,float dz); 134 void RiSkew(float angle,float dx1,float dy1,float dz1,float dx2,float dy2,float dz2); 135 void RiDeformationV(const char *name,int n,const char *tokens[],const void *params[]); 136 void RiDisplacementV(const char *name,int n,const char *tokens[],const void *params[]); 137 void RiCoordinateSystem(const char * space); 138 void RiCoordSysTransform(const char * space); 139 140 RtPoint *RiTransformPoints(const char *fromspace,const char *tospace,int npoints,RtPoint *points); 141 142 void RiTransformBegin(void); 143 void RiTransformEnd(void); 144 145 void RiAttributeV(const char *name,int n,const char *tokens[],const void *params[]); 146 147 void RiPolygonV(int nvertices,int n,const char *tokens[],const void *params[]); 148 void RiGeneralPolygonV(int nloops,int *nverts,int n,const char *tokens[],const void *params[]); 149 void RiPointsPolygonsV(int npolys,int *nverts,int *verts,int n,const char *tokens[],const void *params[]); 150 void RiPointsGeneralPolygonsV(int npolys,int *nloops,int *nverts,int *verts,int n,const char *tokens[],const void *params[]); 151 void RiBasis(float ubasis[][4],int ustep,float vbasis[][4],int vstep); 152 void RiPatchV(const char * type,int n,const char *tokens[],const void *params[]); 153 void RiPatchMeshV(const char * type,int nu,const char * uwrap,int nv,const char * vwrap,int n,const char *tokens[],const void *params[]); 154 void RiNuPatchV(int nu,int uorder,float *uknot,float umin,float umax,int nv,int vorder,float *vknot,float vmin,float vmax,int n,const char *tokens[],const void *params[]); 155 void RiTrimCurve(int nloops,int *ncurves,int *order,float *knot,float *amin,float *amax,int *n,float *u,float *v,float *w); 156 157 void RiSphereV(float radius,float zmin,float zmax,float thetamax,int n,const char *tokens[],const void *params[]); 158 void RiConeV(float height,float radius,float thetamax,int n,const char *tokens[],const void *params[]); 159 void RiCylinderV(float radius,float zmin,float zmax,float thetamax,int n,const char *tokens[],const void *params[]); 160 void RiHyperboloidV(float *point1,float *point2,float thetamax,int n,const char *tokens[],const void *params[]); 161 void RiParaboloidV(float rmax,float zmin,float zmax,float thetamax,int n,const char *tokens[],const void *params[]); 162 void RiDiskV(float height,float radius,float thetamax,int n,const char *tokens[],const void *params[]); 163 void RiTorusV(float majorrad,float minorrad,float phimin,float phimax,float thetamax,int n,const char *tokens[],const void *params[]); 164 void RiProcedural(void * data,float *bound,void (*subdivfunc)(void *,float),void (*freefunc)(void *)); 165 void RiGeometryV(const char * type,int n,const char *tokens[],const void *params[]); 166 167 void RiCurvesV(const char * degree,int ncurves,int nverts[],const char * wrap,int n,const char *tokens[],const void *params[]); 168 void RiPointsV(int npts,int n,const char *tokens[],const void *params[]); 169 void RiSubdivisionMeshV(const char * scheme,int nfaces,int nvertices[],int vertices[],int ntags,const char * tags[],int nargs[],int intargs[],float floatargs[],int n,const char *tokens[],const void *params[]); 170 void RiBlobbyV(int nleaf,int ncode,int code[],int nflt,float flt[],int nstr,const char *str[],int n,const char *tokens[],const void *params[]); 171 172 void RiSolidBegin(const char * type); 173 void RiSolidEnd(void); 174 void *RiObjectBegin(void); 175 176 void RiObjectEnd(void); 177 void RiObjectInstance(const void *handle); 178 void RiMotionBeginV(int N,float times[]); 179 void RiMotionEnd(void); 180 181 void RiMakeTextureV(const char *pic,const char *tex,const char * swrap,const char * twrap,float (*filterfunc)(float,float,float,float),float swidth,float twidth,int n,const char *tokens[],const void *params[]); 182 void RiMakeBumpV(const char *pic,const char *tex,const char * swrap,const char * twrap,float (*filterfunc)(float,float,float,float),float swidth,float twidth,int n,const char *tokens[],const void *params[]); 183 void RiMakeLatLongEnvironmentV(const char *pic,const char *tex,float (*filterfunc)(float,float,float,float),float swidth,float twidth,int n,const char *tokens[],const void *params[]); 184 void RiMakeCubeFaceEnvironmentV(const char *px,const char *nx,const char *py,const char *ny,const char *pz,const char *nz,const char *tex,float fov,float (*filterfunc)(float,float,float,float),float swidth,float twidth,int n,const char *tokens[],const void *params[]); 185 void RiMakeShadowV(const char *pic,const char *tex,int n,const char *tokens[],const void *params[]); 186 void RiMakeBrickMapV(int nb,const char **src,const char *dest,int n,const char *tokens[],const void *params[]); 187 188 void RiArchiveRecord(const char * type,const char *format,va_list args); 189 void RiReadArchiveV(const char *filename,void (*callback)(const char *,...),int n,const char *tokens[],const void *params[]); 190 191 void *RiArchiveBeginV(const char *name, int n,const char *tokens[],const void *parms[]); 192 void RiArchiveEnd(void); 193 194 void RiResourceV(const char *handle,const char *type,int n,const char *tokens[],const void *parms[]); 195 void RiResourceBegin(void); 196 void RiResourceEnd(void); 197 198 void RiIfBeginV(const char *expr,int n,const char *tokens[],const void *parms[]); 199 void RiElseIfV(const char *expr,int n,const char *tokens[],const void *parms[]); 200 void RiElse(void); 201 void RiIfEnd(void); 202 203 void RiError(int,int,const char *); 204 205 206 // The following functions provide access to the graphics state 207 CXform *getXform(int); // Get the active XForm 208 CAttributes *getAttributes(int); // Get the active Attributes 209 COptions *getOptions(); // Get the active Options 210 CShaderInstance *getShader(const char *,int,int,const char **,const void **); // Load a shader 211 212 // Delayed object junk 213 void processDelayedObject(CShadingContext *context,CDelayedObject *,void (*subdivisionFunction)(void *,float),void *,const float *,const float *); 214 void processDelayedInstance(CShadingContext *context,CDelayedInstance *instance); 215 216 void addObject(CObject *); // Add an object into the scene 217 void addInstance(const void *); // Add an instance into the scene 218 void rendererThread(const void *); 219 220 private: 221 222 /////////////////////////////////////////////////////////////////////// 223 // Class : CInstance 224 // Description : This class is allocated at objectBegin only to hold 225 // a list of objects 226 // Comments : 227 class CInstance { 228 public: 229 CObject *objects; 230 }; 231 232 CArray<CXform *> *savedXforms; // Used to save/restore the graphics state 233 CArray<CAttributes *> *savedAttributes; // Saved attributes 234 CArray<COptions *> *savedOptions; // Saved options 235 CArray<CResource *> *savedResources; // Saved resources 236 CInstance *instance; // The current instance object 237 CObject *delayed; // The current delayed object 238 CArray<CInstance *> *instanceStack; // The stack of object lists 239 CArray<CInstance *> *allocatedInstances; // The list of allocated object instances 240 CXform *currentXform; // The current graphics state 241 CAttributes *currentAttributes; 242 COptions *currentOptions; 243 CResource *currentResource; 244 // Some RenderMan Interface related variables 245 int numExpectedMotions; // The number of expected motions in a motion block 246 int numMotions; // The number of motions so far 247 float *keyTimes; // The key times 248 float *motionParameters; // The arrays of motion parameters 249 int maxMotionParameters; // The maximum number of motion parameters that can be stored 250 const char *lastCommand; // The text of the last motion command 251 int riExecTag; // The exec tag count for the RI interface 252 253 void init(CProgrammableShaderInstance *); // Execute the init code of a shader 254 int ifParse(const char *expr); // Evaluate a condition 255 int addMotion(float *parameters,int parameterSize,const char *name,float *&p0,float *&p1); 256 }; 257 258 259 #endif 260 261