The functions listed here provide a set of tools for reading RIB and RIB-like files. There is only a small set of functions that a person using the Affine Toolkit needs to become familiar with. This small set of functions rely on the remaining set of functions shown in the alphabetical list below. To help skip over some of the lower level functions refer to the Quick Reference List below to get some pointers to the most commonly used functions.
PRIB_HASHATOM RibAddItem( RIB_HASHHND hash, RIB_UINT32 type, ... )
Adds an item to the hash table hash given the item's type and data. The data is given in a variable argument list in a format dependent on the value type.
Refer to Hash Item Types for the parameters that are used for the "..." in RibAddItem().
To get a hash table handle from a RIB handle refer to RibGetHashHandle().
A hash atom can be one of the following types:
kRIB_HASH_RIREQUESTCODE
kRIB_HASH_LIGHTHANDLE
kRIB_HASH_OBJECTHANDLE
kRIB_HASH_STRINGTOKEN
kRIB_HASH_STRING
kRIB_HASH_VARIABLE
kRIB_HASH_COORDSYS
kRIB_HASH_USER
Values assigned to type that are from kRIB_HASH_USER upto kRIB_HASH_TYPEMASK & (kRIB_HASH_USER + n) inclusively can be used to store data in a format specific to the tool using the hash library. Refer to User Hash Item Types for placing user data into a hash table.
Two flags kRIB_HASH_FREEDATA and kRIB_HASH_FREEEXTDATA can be ORed into the value given to type to indicate to RibDestroyHashTable() what data can be freed. By default the data referred to by a hash item is not freed without the appropriate flags set.
The pointers given to RibAddItem() are used in the hash table and can not be freed until the item is removed from the hash table or the hash table is destroyed with RibDestroyHashTable().
int RibBegin( RIB_HANDLE rib, RtToken name )
Note that RibBegin() has the Prefix Rib, not simply Ri.
The RenderMan Interface has a function RiBegin() that takes a filename indicating where the output is to be written. If the value is RI_NULL, then standard output is used.
To allow the output filename to be specified, the RIB Reader library provides RibBegin() to allow a RiBegin-like function listed in the RI table at position kRIB_BEGIN to be called with the parameter name. Once RibBegin() has been called the string name can be freed.
To prevent multiple RiBegin() calls reaching the output library that hooks out the ritable, use RibBegin() if an output file must be specified.
RibBegin() does not have to be called unless an output filename needs to be given. RibRead() will call RibBegin() automatically. A flag is set that prevents multiple Begin/End calls reaching the output library. If you call RibBegin() a matching RibEnd() call is optional because RibClose() makes a call to RibEnd(). RibEnd() is really provided to allow the source code to have matching Begin/End calls. Although it can be used to terminate the output of a RIB file before RibRead() has completed reading the input RIB file or stream.
RibBegin() sets a status flag called kRIB_STATUS_BEGUN after the RI Table's kRIB_BEGIN function is called.
Refer to Functions For Reading RIB Files for a description of what RI Tables are and how they provide a mechanism for subclassing RI functions.
Refer to A Real Quick Overview for examples using RibBegin().
Also refer to RibEnd().
int RibBufferRead( RIB_HANDLE rib, char *buffer, unsigned int size )
Acts like fread() except that the number of bytes read is kept track of for RibGetByteOffset(). The number of lines ('\n' characters) is not accounted for.
int RibClearError( RIB_HANDLE rib )
Clears the last error encountered.
Refer to RibGetError() and RibSetError().
int RibClose( RIB_HANDLE rib )
Closes the file represented by rib and frees resources such as a hash table and any buffers used by rib. The RIB handle rib is no longer a valid handle after RibClose() is called. RibClose also calls RibEnd().
If the hash table associated with rib was created with RibCreateHashTable() and the RIB file was opened with RibOpenWithHashTable(), the hash table is treated as an external resource that needs to be freed separately from closing rib. To free a hash table use RibDestroyHashTable().
If rib was opened with the function RibOpenSubfile() then any tables and buffers used by the parent are left alone and are not freed.
Refer to A Real Quick Overview for examples using RibClose().
int RibCloseFile( RIB_HANDLE rib )
Closes the file represented by rib and does not free any buffers or tables. This function allows a tool to fclose() a file without loosing any data such as the data in the RIB's associated hash table. The RIB handle rib is still valid and can be used in subsequent Rib calls.
int RibCacheVector( RIB_HANDLE rib,
RtInt n, RtToken **paTokens, RtPointer **paParams )
This function is used by RibReadParameterList() in affine/readrib/paraml.c. Most tools should not need to call this function directly.
RibCacheVector() increases the size of four arrays associated with each RIB handle so that each can hold a minimum of nparams items of data. The arrays are used for reading of token/parameter pairs that form the parameter lists of RIB statements. Two of the arrays are used to separately store the token names and a pointer to the parameter data associated with each token name. The other two of the four arrays provide information about each token/parameter pair: the type of data the token name represents and the number of items of the token type the parameter data holds.
The four arrays together are referred to as the vector cache in the Affine Toolkit source code. The name vector cache is from the token/parameter arrays used in the vector form of the RI calls. Once RibReadParameterList() has read a RIB statement's parameter list, data is stored in four arrays storing the token names, parameter data arrays, the type of each parameter data array, and the number of items in each parameter data array.
Initially when a RIB handle is created the four arrays (tokencache, paramcache, typecache, and ncache) are each given the size of kRIB_VECTORCACHEINCR (about 30) values. This size is normally large enough for most RIB statement's parameter list, but if needed these arrays can be grown by increments of kRIB_VECTORCACHEINCR.
RibCacheVector() is the function used to check if the vector cache needs to be grown. The value nparams indicates the number of additional token/parameter pairs that are going to be added. Typically the token/parameter pairs are read-in one at a time and RibCacheVector() is called with nparams equal to one to indicate one more item is being added to the vector cache.
RibGetVectorCacheInfo() is used to access the types and sizes of the token/parameter pairs. It also returns the number of vertices found in the "P", "Pw", or "Pz" arrays if present. RibGetVectorCacheInfo() and RibCacheVector() were designed for functions doing the actual reading of a RIB statement. Information such as the number of vertices found in a given positional array ("P", "Pw", or "Pz") is stored in an internal array ncache for parsing such things as a Polygon statement.
int RibCopyVectorCache( RIB_HANDLE rib,
RtInt n, RtToken **paTokens, RtPointer **paParams )
Makes a copy of n items from the start of a RIB statement's token/parameter pairs based on the vector cache. The token names and parameter data are copied into two newly malloc'ed blocks of memory that can be used in the vector form of an RI call. RibCopyVectorCache() assumes that it is being called from a RI-like function hooked into rib's associated RI table.
PRIB_BUFFER RibCreateBuffer( RIB_HANDLE rib )
The RIB Reader library uses a linked list of 255 character long buffers to handle reading strings and arrays of unknown length. During RibOpen() and RibOpenWithHashTable(), RibCreateBuffer() is called to setup a structure (RIB_BUFFER) that keeps track of the linked list of 255 character buffers (RIB_BUFFERITEM).
Refer to RibDestroyBuffer().
RtFloat *RibCreateFloatArrayFromBuffer( RIB_HANDLE rib, RIB_UINT32 options )
If RibSaveToBuffer() was called to save characters retrieved by RibGetChar() into a buffer and a set of IEEE 32-bit floats has been read, RibCreateFloatArrayFromBuffer() will malloc a block of memory for the array, copy the contents of the rib's buffer into the malloc'ed memory block and return a pointer to it.
The data in the buffer is not removed and anymore characters read by RibGetChar() will be appended to the contents of the buffer until RibSaveToBuffer() or RibResetBuffer() is called.
RIB_HASHHND RibCreateHashTable( int size )
Creates a double hash table of length size and width kRIB_HASH_SECONDSIZE. To find an element in the hash table two hash functions are used. The first reduces the search to row position inclusively between 0 and size-1. The second hash function narrows the search further to a column position inclusively between 0 and kRIB_HASH_SECONDSIZE-1.
By default RibOpen() calls RibCreateHashTable() with size kRIB_HASH_TABLESIZE. The value size should be a prime number, so the hashing functions can work efficiently.
RtInt *RibCreateIntegerArrayFromBuffer( RIB_HANDLE rib, RIB_UINT32 options )
If RibSaveToBuffer() was called to save characters retrieved by RibGetChar() into a buffer and a set of 32-bit integers has been read, RibCreateIntegerArrayFromBuffer() will malloc a block of memory for the array, copy the contents of the rib's buffer into the malloc'ed memory block and return a pointer to it.
The data in the buffer is not removed and anymore characters read by RibGetChar() will be appended to the contents of the buffer until RibSaveToBuffer() or RibResetBuffer() is called.
char *RibCreateStringFromBuffer( RIB_HANDLE rib, RIB_UINT32 options )
If RibSaveToBuffer() was called to save characters retrieved by RibGetChar() into a buffer and a set of ASCII characters has been read, RibCreateStringFromBuffer() will malloc a block of memory for the array, copy the contents of the rib's buffer into the malloc'ed memory block and return a pointer to it.
Binary characters are replaced with an ASCII representation such as '\n' or an ASCII octal value '\000'.
The data in the buffer is not removed and anymore characters read by RibGetChar() will be appended to the contents of the buffer until RibSaveToBuffer() or RibResetBuffer() is called.
int RibCreateStringsFromBuffer( RIB_HANDLE rib, RtInt n, RtString **r )
Parameter lists can have arrays of strings for tokens defined as varying or vertex strings. Once the entire array of n strings has been read into rib's buffer, RibCreateStringsFromBuffer() creates a block of memory large enough for n pointers and the n NULL terminated strings. The pointers to the beginning of the strings.
One memory block is used for the array of pointers and the character strings so that a function listed in the RI table receives this data it can free it the same way all other arrays are freed by making a single call to RibFree() with the pointer to the array.
PRIB_HASHATOM RibDeclare( RIB_HANDLE rib, char *name, char *declaration )
Associates the RIB file or stream rib with a type declaration for the variable or attribute name name. Subsequent statements that are read from rib will be able to handle parameter lists using name. Refer to the RI Specification regarding RiDeclare().
RibDeclare() adds name to a hash table associated with rib. The string pointed to by name is freed when its entry in the hash table is removed by RibRemoveItem() or destroyed when RibClose() or RibDestroyHashTable() is called.
RibClose() happens to simply call RibDestroyHashTable() if the status flag kRIB_STATUS_EXTERNHASHTBL is not set. Refer to RibOpenWithHashTable() regarding the status flag kRIB_STATUS_EXTERNHASHTBL.
Because name is added to a hash table as a pointer to a string, RibDeclare() assumes that name was a malloced piece of data that is freeable.
The library libribhash.a calls RibAddItem() directly not RibDeclare(). RibDeclare() is provided for the libraries libribrdr.a, libribwrtr.a and libributil.a to use. Utilities can also use RibDeclare() to extend the standard set of attribute and variables names that may appear in a parameter list.
int RibDefaultArchiveRecordHandler( RIB_HANDLE rib )
The default behavior of RibDefaultArchiveRecordHandler() can be altered with RibSetHintTable(). If RibSetHintTable() is used to associate a hint table to rib, RibDefaultArchiveRecordHandler() will identify standard hints and call the appropriate hint function.
Refer to RibGetHintTableSize() and RibGetHintTable(). By default a RIB handle has no hint table and RibGetHintTable() will return NULL.
int RibDefaultErrorHandler( RIB_HANDLE rib,
int code, int severity,
PRIB_ERROR error )
Prints the standard error message indicated by the RenderMan Specification using the values code and severity. If the status flag kRIB_OPTION_ERRMSG_VERBOSE is set, a more verbose error message follows based on data given in error. By default the flag kRIB_OPTION_ERRMSG_VERBOSE is set when rib is opened. RibSetOptions() can be used to turn the verbose flag off.
Refer to RibSetErrorHandler() and RibGetErrorHandler().
int RibDefaultHintHandler( RIB_HANDLE rib )
Used as a basic function in hint tables assigned to RIB handles. The preceding '##' should have already been read and the hint name should be in rib's buffer.
RibDefaultHintHandler() reads the input until a '\n' is encountered, calls RibCreateStringFromBuffer() to create a memory block to store the entire hint, and calls the function at the kRIB_ARCHIVERECORD position of the archive table is called with "structure" as the first parameter. Once the RI Table function returns, RibDefaultHintHandler() checks for the kRIB_STATUS_KEEPDATA flag and if not there frees the string that has the hint statement.
Refer to RibGetHintTableSize(), RibGetHintTable() and RibSetHintTable().
int RibDestroyBuffer( PRIB_BUFFER pbuf )
int RibDestroyHashTable( RIB_HASHHND hash )
Frees all data listed in the hash table hash and then the arrays used to store the hash table itself. Once complete, hash is no longer a valid handle.
int RibDestroyHashTableKeepData( RIB_HASHHND hash )
Destroys the hash table and the hash atoms listed in the hash table, but the data pointed to by each atom is left untouched.
int RibEnd( RIB_HANDLE rib )
Note that RibEnd() has the Prefix Rib, not simply Ri.
RibEnd() sets a status flag called kRIB_STATUS_ENDED after the RI Table's kRIB_END function is called. The flag prevents RibEnd() from calling the RI Table's kRIB_END call again.
RibEnd() can be used to cleanly terminate the reading of a RIB file rib before the RIB file has been entirely read. Using RibEnd() in this manner requires that it be called from a RI function hooked in rib's RI Table. Once RibEnd() sets the status flag kRIB_STATUS_ENDED, RibRead() will return control to the tool that called it instead of reading the next available RIB statement.
Refer to RibBegin(). RibEnd() can be called from a tool using the RIB Reader library without having called a matching RibBegin(). RibRead() will call RibBegin() and RibClose() makes a call to RibEnd(). Special status flags kRIB_STATUS_BEGUN and kRIB_STATUS_ENDED prevent begin and end functions listed in the RI Table from getting multiple calls.
int RibErrorNumberOfValues( RIB_HANDLE hrib, RtToken parameterID, RtInt expected_nitems, RtInt received_nitems )
Reports an error where a token/parameter pair has an array of data of the wrong length. The token that identifies the token/parameter pair is parameterID. The values expected_nitems and received_nitems gives the number of expected and actual items respectively. Each item can be made up of any number of floats, integers or strings. For example a matrix involves 16 floats. Error messages measure in the number of floats, integers and strings and not the number of matrices or colors. RibErrorNumberOfValues() converts expected_nitems and received_nitems into values compatible with the phrasing of the error messages by finding the type associated with the parameterID in declarations stored in rib's hash table.
Refer to RibSetError().
PRIB_HASHATOM RibFindMatch( RIB_HASHHND hash, RIB_UINT32 type, int code, void *data )
Used to retrieve an item that has been added to a hash table hash. A type using one of the following constants is required:
enum {
kRIB_HASH_UNKNOWN,
kRIB_HASH_RIREQUESTCODE,
kRIB_HASH_LIGHTHANDLE,
kRIB_HASH_OBJECTHANDLE,
kRIB_HASH_STRINGTOKEN,
kRIB_HASH_STRING,
kRIB_HASH_VARIABLE,
kRIB_HASH_COORDSYS,
kRIB_HASH_LAST,
kRIB_HASH_USER = 1024
};
Values of kRIB_HASH_USER and greater only have meaning for a tool using
the hash table library. When searching RibFindMatch() uses the value
code as a hash value and unique ID along with type only if
data is NULL. If data points to a string, the hash library
will use the string to create a hash value and use strcmp() to find a match
after a possible matching item's type matched.
Light and object handles are identified by a code value that represents their sequence number. Variables and coordinate systems are identified by their string names. Strings and RI requests are identified by the code given in the RIB file's binary encoding.
PRIB_HASHATOM RibFindNextMatch( RIB_HASHHND hash, PRIB_HASHATOM atom )
To allow for application specific user items in the hash table that have a type of kRIB_HASH_USER or greater, the hash table library allows for multiple user items to have matching types and codes. Each hash item has an extended field that can be given a pointer to the data making the hash item unique. A tool making use of this ability calls RibFindMatch() first, determines if there actually is a match given by looking at the extended data and if there is no match continues the search with RibFindNextMatch().
void RibFree( void *p )
Frees a memory block pointed to by p. This allows a central place for altering how the memory is freed. The Affine Toolkit source code uses a macro _RibFree() defined in affine/include/ribhash.h instead of calling RibFree() directly. This macro is used so that if a flag RIB_MEMORY_TESTS is defined, the macro will call special compiled version of RibFree() that keeps track of memory leaks.
If the Affine libraries are compiled with RIB_MEMORY_TESTS not defined, the macro _RibFree() is simply replaced with free(). This is to avoid the extra function call involved in calling RibFree() which without the memory tests simply calls free().
Refer to Rib Memory Functions for more detail on the memory handling functions.
Refer to Memory Allocations in the section More Advanced Subclassing for how pointers to memory are handled in Ri-like calls called from the RIB Reader Library.
void RibFreeBasisMatrix( void *p )
Frees a memory block pointed to by p. A check is done to see if the memory is one of the RI_ constants which can not be freed. If an RI_ constant such RiPowerBasis is given, RibFreeBasisMatrix() simply returns without error.
Refer to Rib Memory Functions for more detail on the memory handling functions.
Refer to Memory Allocations in the section More Advanced Subclassing for how pointers to memory are handled in Ri-like calls called from the RIB Reader Library.
int RibFreeVectorCache( RIB_HANDLE rib )
Internal call used to free a set of arrays that store pointers for token/parameter pairs, number of elements found and type of the parameter data.
int RibFreeVectorData( RIB_HANDLE hrib,
RtInt nparms, RtToken *tokens, RtPointer *parms )
RibFreeVectorData() frees nparms of strings used by the array tokens and nparms data arrays pointed to by the array parms.
PRIB_HINTTABLE RibGetArcRecHandler( RIB_HANDLE rib )
Returns the function pointer to the archieve record handler registered with rib by the function RibSetArchiveRecordHandler().
PRIB_BUFFERITEM RibGetBufferItem( PRIB_BUFFER pBuffer )
This function is used by functions in affine/readrib/streamio.c. Most tools should not need to call this function directly.
Returns an available RIB_BUFFERITEM structure or creates a new one.
unsigned int RibGetBufferLength( RIB_HANDLE rib )
Returns the number of bytes stored in rib's buffer. This function is used when an array has been read into the buffer and a contiguous block of memory needs to be created to copy the array into.
unsigned long int RibGetByteOffset( RIB_HANDLE rib )
Returns the presnt position in the file or number of bytes read from the input stream.
int RibGetChar( RIB_HANDLE rib )
Returns the next character in a file or stream.
PRIB_HASHATOM RibGetConflictingHashAtom( RIB_HASHHND hash )
If a RibAddItem() returns NULL, an existing item matching in the hash table hash matches the item being added. RibGetConflictingHashAtom() returns a non-NULL pointer if an existing item did in fact conflict with an item being added to a hash table.
Normally the already existing hash item is then altered to match the data the new item would have provided in the hash table.
To alter an existing hash table's item, refer to the functions RibSetDefinedLightHandle(), RibSetDefinedObjectHandle(), RibSetDefinedString(), RibSetDefinedRIRequest(). RibSetHashExtendedData(), and RibSetStringAtom().
To access data in a hash table's item, use RibGetDefinedLightHandle(), RibGetDefinedObjectHandle(), RibGetDefinedString(), RibGetDefinedRIRequest(). RibGetHashExtendedData(), and RibGetStringAtom().
int RibGetDefinedRIRequest( PRIB_HASHATOM a )
The RIB binary format includes statements that associate a number to a given RIB statement name. The number is a part of an abbreviated form of the RIB statement name. If an hash table atom represents the association of a number to a RIB statement name, the number can be retrieved using RibGetDefinedRIRequest(). The atom can be found by calling RibFindMatch() given type kRIB_HASH_RIREQUESTCODE and the RIB statement name as a string.
RtLightHandle RibGetDefinedLightHandle( PRIB_HASHATOM atom )
Light sources are given ID numbers in a RIB file or stream. These ID numbers are called sequence numbers because they normally enumerate the light sources from 1 to n. The RenderMan Interface C bindings gives each light source a LightHandle to identify each light source. To show the association between a seuence number and its light source handle, the hash table stores atoms that can be found given the sequence number. RibGetDefinedLightHandle() returns the light source handle once the hash atom is found.
The correct atom can be found by calling RibFindMatch() given type kRIB_HASH_LIGHTHANDLE and the sequence number.
RtObjectHandle RibGetDefinedObjectHandle( PRIB_HASHATOM atom )
Objects are given ID numbers in a RIB file or stream. These ID numbers are called sequence numbers because they normally enumerate the objects from 1 to n. The RenderMan Interface C bindings gives each object an ObjectHandle to identify each object. To show the association between a seuence number and its object handle, the hash table stores atoms that can be found given the sequence number. RibGetDefinedObjectHandle() returns the light source handle once the hash atom is found.
The correct atom can be found by calling RibFindMatch() given type kRIB_HASH_OBJECTHANDLE and the sequence number.
char *RibGetDefinedString( PRIB_HASHATOM atom )
The correct atom can be found by calling RibFindMatch() given type kRIB_HASH_STRING and the ID number.
Refer to RibSetDefinedString().
PRIB_ERROR RibGetError( RIB_HANDLE rib )
Returns a pointer to RIB_ERROR structure that describes the last error set. This pointer points to a memory block included in a larger structure that is freed when rib is closed.
Do not free the returned pointer.
Refer to RibSetError().
PRIB_ERRORFILTERPROC RibGetErrorHandler( RIB_HANDLE rib )
Returns a function pointer of the presently set error handler.
Refer to RibSetErrorHandler() and RibDefaultErrorHandler().
char *RibGetErrorMsg( int code )
Returns the RenderMan Standard error message for the following codes:
#define RIE_NOERROR ((RtInt)0) #define RIE_NOMEM ((RtInt)1) #define RIE_SYSTEM ((RtInt)2) #define RIE_NOFILE ((RtInt)3) #define RIE_BADFILE ((RtInt)4) #define RIE_VERSION ((RtInt)5) #define RIE_INCAPABLE ((RtInt)11) #define RIE_UNIMPLEMENT ((RtInt)12) #define RIE_LIMIT ((RtInt)13) #define RIE_BUG ((RtInt)14) #define RIE_NOTSTARTED ((RtInt)23) #define RIE_NESTING ((RtInt)24) #define RIE_NOTOPTIONS ((RtInt)25) #define RIE_NOTATTRIBS ((RtInt)26) #define RIE_NOTPRIMS ((RtInt)27) #define RIE_ILLSTATE ((RtInt)28) #define RIE_BADMOTION ((RtInt)29) #define RIE_BADSOLID ((RtInt)30) #define RIE_BADTOKEN ((RtInt)41) #define RIE_RANGE ((RtInt)42) #define RIE_CONSISTENCY ((RtInt)43) #define RIE_BADHANDLE ((RtInt)44) #define RIE_NOSHADER ((RtInt)45) #define RIE_MISSINGDATA ((RtInt)46) #define RIE_SYNTAX ((RtInt)47) #define RIE_MATH ((RtInt)61) #define RIE_INFO ((RtInt)0) #define RIE_WARNING ((RtInt)1) #define RIE_ERROR ((RtInt)2) #define RIE_SEVERE ((RtInt)3)
unsigned int RibGetFileName( RIB_HANDLE rib )
Returns the filename given to RibOpen(), RibOpenWithHashTable(), or RibOpenSubfile().
void* RibGetHashExtendedData( PRIB_HASHATOM atom )
Returns the extended data field of atom.
Refer to RibGetConflictingHashAtom().
RIB_HASHHND RibGetHashHandle( RIB_HANDLE rib )
Returns the handle of rib's hash table.
PRIB_HINTTABLE RibGetHintTable( RIB_HANDLE rib )
Returns a pointer to a table of function pointers that handle the RenderMan standard hints. The table has the following order and default values:
PRIB_ARCRECFILTERPROC gRibHintTable[] = {
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##CameraOrientation */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##CapabilitiesNeeded */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##CreationDate */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##Creator */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##For */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##Frames */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##Include */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##RenderMan */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##Scene */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##Shaders */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler /* ##Textures */
};
Refer to RibGetHintTableSize() and RibSetHintTable(). By default a RIB handle has no hint table and RibGetHintTable() will return NULL.
Also refer to RibDefaultHintHandler() for an example of a hint handler function.
int RibGetHintTableSize( RIB_HANDLE rib )
Returns size in bytes of a table of function pointers to handle all the supported hints.
Refer to RibGetHintTable() and RibSetHintTable()
Also refer to RibDefaultHintHandler() for an example hint handling function used in a hint table.
int RibGetLastChar( RIB_HANDLE hrib )
Returns the last character read by RibGetChar().
int RibGetLastErrorCode( RIB_HANDLE rib )
Returns the last error code set by RibSetError().
int RibGetLastErrorSeverity( RIB_HANDLE rib )
Returns the level of severity for the last error code set by RibSetError().
int RibGetLastNUniform( RIB_HANDLE rib )
Returns a the number of uniform parameters that the RIB Reader library calculated for a given Ri call. This function should only be called from a Ri-like function hooked into the Ri table of rib.
Refer to RibSetLastNUniform()
int RibGetLastNVarying( RIB_HANDLE rib )
Returns a the number of varying parameters that the RIB Reader library calculated for a given Ri call. This function should only be called from a Ri-like function hooked into the Ri table of rib.
Refer to RibSetLastNVarying()
int RibGetLastNVertex( RIB_HANDLE rib )
Returns a the number of vertex parameters that the RIB Reader library calculated for a given Ri call. This function should only be called from a Ri-like function hooked into the Ri table of rib.
Refer to RibSetLastNVertex()
int RibGetLastSequence( RIB_HANDLE rib )
To get the last read sequence number, use RibGetLastSequence(). RibGetLastSequence() is typically called from a RI function that was listed in the RI table associated with a RIB handle or a RI call that has hooked into the calling chain that starts at a given RI table.
There is a sequence number when reading a RIB binding. The sequence number is not there when calling such calls as RiLightSource() as shown below:
##RenderMan RIB
version 3.03
LightSource "ambientlight" 1
Refer to RibSetLastSequence().
unsigned int RibGetLineCount( RIB_HANDLE rib )
Returns the number of '\n' characters that have been encounted so far. This value may not be very helpful if the input is a binary encoded RIB file. To query whether any binary characters were encountered use RibGetStatus() and check for the status flag kRIB_STATUS_ENCODEDDATA.
int RibGetNColorSamples( RIB_HANDLE rib )
Returns the number of color channels set by RibSetNColorSamples(). When a RIB handle is created the default number of channels is 3. This value affects how Color statements are read and the size of RtColor structures.
RIB_UINT32 RibGetOptions( RIB_HANDLE hrib )
Returns the option flags set for a given RIB handle. The possible option flags are kRIB_OPTION_READ_SUBFILES and kRIB_OPTION_ERRMSG_VERBOSE.
The option flag kRIB_OPTION_READ_SUBFILES makes the RIB Reader Library open subfiles referenced by ReadArchive calls.
The option flag kRIB_OPTION_ERRMSG_VERBOSE makes the RIB Reader Library print a longer error message along with the rather undescriptive RenderMan Standard error message.
Refer to RibSetOptions().
PRIB_RITABLE RibGetParameterTypeInfo( RIB_HANDLE rib, int *uniform, int *varying, int *vertex )
Returns a the number of uniform, varying and vertex parameters that the RIB Reader library calculated for a given Ri call. This function should only be called from a Ri-like function hooked into the Ri table of rib.
Refer to macros RibGetLastNUniform() RibGetLastNVarying() RibGetLastNVertex() RibSetLastNUniform() RibSetLastNVarying() RibSetLastNVertex()
PRIB_RITABLE RibGetRITable( RIB_HANDLE rib )
Returns a pointer to a table of Ri calls that has been associated to the RIB handle rib.
The function RibSetRITable() changes what RI table is associated with rib.
int RibGetRITableSize( RIB_HANDLE rib )
Returns the size in bytes needed to store a Ri table. Refer to gRibRITable[] as an example table.
RIB_UINT32 RibGetStatus( RIB_HANDLE hrib )
Returns the Status Flags that are set for the RIB input hrib.
char *RibGetStringAtom( PRIB_HASHATOM a )
Retrieves the string of hash atom a if it is of hash atom type kRIB_HASH_STRING.
Refer to RibSetStringAtom().
int RibGetTypeClassNames( unsigned int code, char **c, char **t )
Variable names must have their class and type declared with a Declare statement before they can be used in a parameter list. The RIB Reader library automatically adds variable declarations to a hash table associated to a RIB file. A tool can also call RibDeclare() to perform this function for additional variable names unique to the tool being implemented. RibFindMatch() can be used to query a variable already in a hash table.
Once a variable has been declared and added to a RIB's hash table, its class and type has been converted into a single integer. RibGetTypeClassNames() can be used to return two strings naming the class and type. If either the c or t parameters are NULL, RibGetTypeClassNames() simply skips over the code that would have returned a string pointer for that parameter without giving an error.
The following lists the class and type strings along with their assocaited KRIB_ integer values used to encode them:
kRIB_FLOATTYPE -- "float"
kRIB_STRINGTYPE -- "string";
kRIB_POINTTYPE -- "point";
kRIB_COLORTYPE -- "color";
kRIB_NORMALTYPE -- "normal";
kRIB_VECTORTYPE -- "vector";
kRIB_HPOINTTYPE -- "hpoint";
kRIB_INTTYPE -- "int";
kRIB_FLOATPAIRTYPE -- "float pair";
kRIB_INTPAIRTYPE -- "integer pair";
kRIB_STANDALONETYPE -- "standalone";
no type code set -- "unknown";
kRIB_VERTEXCLASS -- "vertex";
kRIB_VARYINGCLASS -- "varying";
kRIB_UNIFORMCLASS -- "uniform";
no class code set -- "uniform";
The pointers to strings given to c and t should not be freed. They are constant strings linked into the Affine library being used.
int RibGetUserParameters( char *table, int ntable,
RtInt n, RtToken tokens[], RtPointer parms[],
RtPointer output[] )
Refer to the tool tokentbl for a description of the format of ntable.
Refer to Sorting Through the Data for an example using RibGetUserParameters().
int RibGetUVStep( RIB_HANDLE hrib, RtInt *ustep, RtInt *vstep )
When reading a RIB file statements such as Patch and PatchMesh require u and v step values. Refer to specification for the use of step values. By default the u and v step values are set to 3. To query the present setting use RibGetUVStep()
Refer to RibSetUVStep() for more information on U and V step values and setting them.
int RibGetVectorCache( RIB_HANDLE rib,
RtInt *n, RtToken **tokens, RtPointer **params )
Returns the last read parameter list using vector form in *n, *tokens, *params.
The pointers assigned to n, tokens, params should not be freed.
int RibGetVectorCacheInfo( RIB_HANDLE rib, RtInt *n, RtInt *nvertices,
unsigned int **types, unsigned int **sizes )
Returns information about the last read parameter list read. Associated with each token/parameter pair returned by RibGetVectorCache() is a type and parameter data size. The type uses the following flags for a token's declaration:
kRIB_UNKNOWNCLASS kRIB_UNIFORMCLASS kRIB_VARYINGCLASS kRIB_VERTEXCLASS kRIB_CONSTANTCLASS kRIB_UNKNOWNTYPE kRIB_FLOATTYPE kRIB_STRINGTYPE kRIB_POINTTYPE kRIB_COLORTYPE kRIB_NORMALTYPE kRIB_VECTORTYPE kRIB_HPOINTTYPE kRIB_INTTYPE kRIB_MATRIXTYPE kRIB_FLOATPAIRTYPE kRIB_INTPAIRTYPE kRIB_STANDALONETYPE
int RibHandleArchiveRecord( RIB_HANDLE rib )
Calls rib's archive record handler if there is one, otherwise the comment or structure that has been found is read and discarded. By default RibDefaultArchiveRecordHandler() is called.
int RibHandlePrefix( RIB_HANDLE rib )
Comments, binary encoded RI requests, or binary encoded string definitions can be located inbetween statement data and token/parameter pairs. RibHandlePrefix() is called before each atomic item of data to handle any comments or special codes that may appear.
int RibHashValueFromInt( RIB_HASHHND hash, int key )
Creates a hash value from integer value key.
int RibHashValueFromString( RIB_HASHHND hash, char* p )
Creates a hash value from string p.
int RibHashValueFromStringN( RIB_HASHHND hash, char *p, int n )
Creates a hash value from n characters in string p.
int RibIgnoreArchiveRecords( RIB_HANDLE rib )
Sets rib's pointer to an archive record handler to NULL and disables lines of text following a '#' character from being forwarded to a RiArchiveRecord() function in rib's RI table.
int RibIgnoreLastChar( RIB_HANDLE rib )
Removes a character from rib's input buffer if the status flag kRIB_STATUS_SAVETOBUFFER is set.
int RibIncrLineCount( RIB_HANDLE rib )
Increments rib's present line count by one. Line count is used when printing error messages.
int RibIncrBufferLength( RIB_HANDLE rib )
Increments the count of bytes used in a buffer that RibGetChar() can be set to copy input to when a status flag of kRIB_STATUS_SAVETOBUFFER is set.
int RibIncrByteOffset( RIB_HANDLE rib )
Increments rib's present byte offset count into the input file by one. Byte offset count is used when printing error messages for binary encoded RIBs.
int RibIsaBinaryChar( char c )
Returns RI_TRUE if the character c has the bit 0200 set. Otherwise RI_FALSE is returned.
int RibIsaDelimitor( char c )
Returns RI_TRUE if the character c meets the following condition:
(c)=='[' || (c)=='#' || c=='\"' )
Otherwise RI_FALSE is returned.
int RibIsanEncodedDefinition( char c )
Returns RI_TRUE if the character c meets the following condition:
((c) >= 0314 && (c) <= 0316)
Otherwise RI_FALSE is returned.
int RibIsanEncodedRIRequest( char c )
Returns RI_TRUE if the character c meets the following condition:
((c)==0246)
Otherwise RI_FALSE is returned.
int RibIsaLetter( char c )
Returns RI_TRUE if the character c meets the following condition:
(( (c) >= 'a' && (c) <= 'z' ) || ( (c) >= 'A' && (c) <= 'Z' ))
Otherwise RI_FALSE is returned.
int RibIsaStdASCIIChar( char c )
Returns RI_TRUE if the character c meets the following condition:
((c) >= 32 && (c) <= 126 && (c) != '\"' && (c) != '\\' )
Otherwise RI_FALSE is returned.
int RibIsaWhiteSpace( char c )
Returns RI_TRUE if the character c is a space, linefeed, tab, or a return. Otherwise RI_FALSE is returned.
RtBoolean RibIsaNumberNext( RIB_HANDLE hrib )
Returns RI_TRUE if a number follows after the present position in the RIB file or stream rib. This function looks for an ASCII digit, plus sign, minus sign, decimal point, character of octal values 0244 or 0245, or a value inclusively inbetween octal values 0200 and 0217.
Comments and encoded definitions for strings or RI requests do not cause RibIsaStringNext() to return RI_FALSE if encountered. Comments are given to the RI function in the kRIB_ARCHIVERECORD position of rib's RI table. Encoded definitions are added to rib's hash table.
RtBoolean RibIsaStringNext( RIB_HANDLE hrib )
Returns RI_TRUE if a string follows after the present position in the RIB file or stream rib. This function looks for a quote or a binary character equal to octal value 0317 or inclusively inbetween octal values 0220 and 0243.
Comments and encoded definitions for strings or RI requests do not cause RibIsaStringNext() to return RI_FALSE if encountered. Comments are given to the archive handler associated with rib's RI table. By default RibOpen() sets up RibDefaultArchiveRecordHandler() as the default archive handler.
int RibKeepData( RIB_HANDLE rib )
Called from a RI function listed in rib's RI table to set a status flag kRIB_STATUS_KEEP_DATA to inform the RIB Reader library that the pointers to memory blocks given to the present RI call are not to be freed after the RI call returns control back to the RIB Reader library.
Refer to More Advanced Subclassing.
void *RibMalloc( unsigned int size )
Allocates a memory block of size size. This allows a central place for altering how the memory is malloc'ed. The Affine Toolkit source code uses a macro _RibMalloc() defined in affine/include/ribhash.h instead of calling RibMalloc() directly. This macro is used so that if a flag RIB_MEMORY_TESTS is defined, the macro will call special compiled version of RibMalloc() that keeps track of memory leaks.
If the Affine libraries are compiled with RIB_MEMORY_TESTS not defined, the macro _RibMalloc() is simply replaced with malloc(). This is to avoid the extra function call involved in calling RibMalloc() which without the memory tests simply calls malloc().
Refer to Rib Memory Functions for more detail on the memory handling functions.
Refer to Memory Allocations in the section More Advanced Subclassing for how pointers to memory are handled in Ri-like calls called from the RIB Reader Library.
PMEM_TEST RibMemoryTestInit( void )
When affine/ribhash/ and affine/readrib/ are compiled with a flag RIB_MEMORY_TESTS defined, RibMalloc(), RibRealloc() and RibFree() are altered to keep track of source code line numbers and memory leaks. RibMemoryTestInit() needs to be called before the test versions of the memory functions are called.
int RibMemoryTestMalloc( char *file, unsigned int line,
void *p, unsigned int size )
Internal call used by the test version of RibMalloc() to keep track of possible memory leaks. The pointer p is a pointer returned to a memory block of size size by malloc().
int RibMemoryTestFree( char *file, unsigned int line, void *p )
Internal call used by the test version of RibFree() to keep track of possible memory leaks. The pointer p is a pointer returned to a memory block of size size by free().
int RibMemoryTestResults( PMEM_TEST pmemtest )
Prints the results gathered during the reading of a RIB file. If a pointer returned by malloc() does not have a matching call to free() a memory leak has occured and the source code file and line number of the unmatched malloc() call is printed.
The output of RibMemoryTestResults() takes the form of the following example:
Valid _RibMalloc() calls: 137
Valid _RibFree() calls: 137
Step overs during _RibFree(): 0
Invalid _RibFree() calls: 0
Memory leaks found: 0
The term step overs is in reference to a counter that keeps track of when a last-to-first order of freeing malloc'ed memory blocks is not strickly followed. Following a last-to-first order in freeing memory blocks is not always possible. A count of violations to this general rule is really a test for the RIB Reader library's source code.
int RibMemoryTestStepOverAllowed( void )
To prevent a call to RibFree() from incrementing a global step over counter, RibMemoryTestStepOverAllowed() precedes the RibFree() call. The source code of the RIB Reader library needs the flag RIB_MEMORY_TESTS defined for this extra code to be included during a build.
Refer to RibMemoryTestResults() for a description of step overs.
Opens filename and if table is not NULL it will be used as a table of function pointers to a complete set of Ri calls. The memory pointed to by table is used until RibClose() is called. The string filename is copied by RibOpen() and can be freed anytime after RibOpen() is called.
Refer to A Real Quick Overview for examples using RibOpen().
Opens filename and returns a RIB handle.
The string filename is copied by RibOpenWithHashTable() and can be freed anytime after RibOpenWithHashTable() is called.
The parameter hashtable must be a valid RIB hash table or RibOpenWithHashTable() will return NULL. RibOpenWithHashTable() sets a status flag kRIB_STATUS_EXTERNHASHTBL to identify the RIB hash table hashtable as being created separately from the RIB handle. The status flag kRIB_STATUS_EXTERNHASHTBL tells RibClose() to not free hashtable when closing the file rib.
RibOpenWithHashTable() allows a hash table to be created and modified before a RIB file or stream is opened. Tools such as affine/ributil/ribfixer.c make use of RibOpenWithHashTable() to add user data to the default hash table while the command line parameters are being validated.
Refer to RibCreateHashTable(). For more detail on using the hash table library (libribhash.a) refer to RIB Hash Table.
RIB_HANDLE RibOpenSubfile( RIB_HANDLE rib, char *filename )
Opens the file called filename with a parent file rib. RibOpenSubfile() is used for such operations as handling recursively appearing ReadArchive statements. To prevent RibClose() and RibCloseFile() from trying to free rib's tables and buffers, a status flag kRIB_STATUS_SUBFILEOPEN is set for the new child RIB handle.
Refer to RibGetStatus() and RibSetStatus() regarding kRIB_STATUS_SUBFILEOPEN.
Note there is no RibCloseSubfile(), just use RibClose().
int RibOption( RIB_HANDLE hrib, RtToken name, RtToken token, RtPointer param )
Note that RibOption() has the Prefix Rib, not simply Ri.
Calls the function at the kRIB_OPTION position of rib's RI Table with a RenderMand Interface RiOption-like call. RibOption() is used when a RiOption() call needs to be given to the output library hooked into rib's RI Table.
int RibPutChar( RIB_HANDLE rib, int c )
When RibSaveToBuffer() is called to store copies of incoming characters into a buffer, RibPutChar() can be used to add more characters to the buffer as if they had been a part of the original RIB input file or stream. Calls to functions such as RibCreateStringFromBuffer() will include in the output the inserted caharacters added by RibPutChar().
RibPutChar() is used mostly to replace binary string characters with their ASCII representation. A character of octal value 0243 will be dropped from the buffer by a call to RibIgnoreLastChar(). RibPutChar() is then called four times with the following sequence of characters: '\', '2', '4', and '3'. The resulting string made from the buffer will include the substring "\243" instead of a single binary character.
Refer to RibGetChar() and RibUngetChar().
RIB_UINT32 RibQueryClassType( RIB_HASHHND hash, char *variable, RIB_UINT32 *n )
To read a RIB statement's parameter list, the class and type of a variable such as "P", "Pw" or "Porig" needs to be retrieved from the hash table. RibQueryClassType() returns a 32-bit value with a class and type flag ORed together. The following are the class and type flags available:
enum {
kRIB_UNKNOWNCLASS = 0x00000000,
kRIB_UNIFORMCLASS = 0x00010000,
kRIB_VARYINGCLASS = 0x00020000,
kRIB_VERTEXCLASS = 0x00030000,
kRIB_CONSTANTCLASS = 0x00040000,
kRIB_LASTCLASS = 0x00050000
};
enum {
kRIB_UNKNOWNTYPE,
kRIB_FLOATTYPE,
kRIB_STRINGTYPE,
kRIB_POINTTYPE,
kRIB_COLORTYPE,
kRIB_NORMALTYPE,
kRIB_VECTORTYPE,
kRIB_HPOINTTYPE,
kRIB_INTTYPE,
kRIB_MATRIXTYPE,
kRIB_FLOATPAIRTYPE,
kRIB_INTPAIRTYPE,
kRIB_STANDALONETYPE,
kRIB_LASTTYPE
};
Use the the bit masks kRIB_CLASS_MASK, kRIB_TYPE_MASK and kRIB_CLASSTYPE_MASK to create a value that can be directly compared with the above listed flags.
RtBoolean RibQueryKeepData( RIB_HANDLE rib )
Returns nonzero value if pointers given in a present Ri call point to memory areas that should not be freed. The function RibShouldFreeData() performs the same action except that it also resets a status flag called kRIB_STATUS_KEEP_DATA.
RibQueryKeepData() is typically called from a RI function listed in the rib's Ri table or that gets called by a chain of functions where the first in the chain is listed in the rib's Ri table. The chaining of functions is how the Affine Toolkit allows subclassing of Ri calls. When a Ri function is hooked into a Ri table the function pointer already present in the table should be saved and called by the Ri function being hooked in. This procedure creates a chain of functions where each function in the chain is responsible for calling the next in the chain and handling freeing of any memory allocated and forwarded on in the chain. If a function later in the chain decides to use a given memory block created by a previous function in the chain, RibKeepData() is called and the previous function that allocated the memory must call RibQueryKeepData() to find out if it is alright to free the data it created and forwarded on in the chain.
A Ri function must call RibQueryKeepData() if 1) it called RibKeepData() to prevent data given to it from being freed when the chain of Ri calls is complete, 2) memory is allocated and given to the next function in the chain, and 3) one of the following functions in the chain needs to keep one of the allocated memory blocks mention in step 2 (inshort RibKeepData() is called by a following function in the chain).
If a Ri function did not need to call RibKeepData() but does allocate memory to that is forwarded on in the chain (inshort the above mentioned steps 2 and 3 occured, but not step 1), then RibShouldFreeData() is used instead of RibQueryKeepData().
The difference between RibShouldFreeData() and RibQueryKeepData() is whether or not a status flag kRIB_STATUS_KEEP_DATA should remain set as Ri functions return control back to the previous function in the chain.
RIB_HANDLE RibRead( RIB_HANDLE rib )
Reads a RIB file or stream identified with the RIB handle rib. RibRead requires that a RI Table be assigned to rib either by giving a pointer to the table as the second parameter to RibOpen() or by calling RibSetRITable().
Refer to A Real Quick Overview for examples using RibRead().
int RibReadArchiveRecord( RIB_HANDLE rib )
Called after a '#' character has been read indicating that the following characters up to a '\n' is a comment or hint. This function can be used to skip over archive records or store them into the buffer depending on the flag used in the last call to RibSaveToBuffer().
int RibReadArrayAndLength( RIB_HANDLE hrib, RIB_UINT32 options, int *numberof, void **pp )
Reads an array into a buffer, determines the array's length, allocates memory for the array and copies the buffer into the newly allocated memory returned in *pp. The number of items in the array is is returned in *numberof.
Refer to Read Option Flags for Arrays for values to assign the parameter options.
int RibReadDefiningBinCode( RIB_HANDLE rib, int alreadyreadin )
Called when a character of octal value 0314 or 0316 is encounterd. The library uses the macro RibIsanEncodedDefinition() to check this condition and if true, calls RibReadDefiningBinCode() to handle an encoded RI request or string definition.
int RibReadFileForToken( RIB_HANDLE rib, char *table )
Given a table produced by tokentbl that has an encoded list of string tokens to look for, RibReadFileForToken() will read rib expecting a only a matching token. If a character read in diverges from the possible strings, a value of EOF or kRIB_ERRRC_INDEX is returned.
int RibReadFloatingPoint( RIB_HANDLE rib, RtFloat *flt )
Reads an ASCII or binary encoded floating point value and places it into flt. If an invalid character is encountered rib's error handler is called with a syntax error.
int RibReadFloatingPointArray( RIB_HANDLE rib, RIB_UINT32 options,
int numberof, RtFloat **array )
Allocates a block of memory to store an array of numberof floats once it has been read from rib. If an invalid character is encountered rib's error handler is called with a syntax error.
Refer to Read Option Flags for Arrays for values to assign the parameter options.
int RibReadInteger( RIB_HANDLE rib, RtInt *i )
Reads an ASCII or binary encoded integer value and places it into i. If an invalid character is encountered rib's error handler is called with a syntax error.
int RibReadIntegerArray( RIB_HANDLE hrib, RIB_UINT32 options,
int numberof, RtInt **array)
Allocates a block of memory to store an array of numberof integers once it has been read from rib. If an invalid character is encountered rib's error handler is called with a syntax error.
Refer to Read Option Flags for Arrays for values to assign the parameter options.
int RibReadParameterList( RIB_HANDLE rib, int require,
int uniform, int varying, int vertex,
RtInt *pn, RtToken **paTokens, RtPointer **paParams )
Called after a RIB statement and standard parameters have been read and before the statements parameter list is expected. Comments and binary encoded string and RI request definitions are also handled.
The values uniform, varying and vertex describe the number of values a variable of type uniform, varying and vertex require respectively. The value require takes one of the following values:
kRIB_REQUIRE_NOTHING kRIB_REQUIRE_P kRIB_REQUIRE_P_OR_PW kRIB_REQUIRE_P_OR_PZStatements such as NuPatch require position data P or Pw to be included in the parameter list and require is used to indicate which if any of the positional variables is required.
The values pn, paTokens and paParams are assigned a vectorized form of the parameter list that is expected to follow the present statement. If there is no parameter list *pn is assigned a value of zero. If required positional data is duplicated or missing rib's error handler is called.
int RibReadRIBCallParameters( RIB_HANDLE rib, char *cparams, int asizes[], void *params )
After a statement name such as NuPatch and before the statement's parameter list, are a set of standard parameters. Sphere for example has the statndard parameters radius, zmin, zmax, and thetamax as its standard parameters. RibReadRIBCallParameters() uses an entry from the table gRibCParams[] linked in libribhash.a to automatically handle reading the standard parameters and return a block of memory that contains the values. The array asizes describes to RibReadRIBCallParameters() the sizes of any expected arrays in the order they appear.
int RibReadRIRequestToken( RIB_HANDLE hrib )
Binary encoded format allows for a RIB statement to be represented by a number called a RI request code or RI request token. RibReadRIRequestToken() handles reading the value that represents a RIB statement.
RibReadRIRequestToken() returns an RI Table index after reading an expected one byte token that identifies an entry in the hash table. The character 0246 has already been read in.
int RibReadString( RIB_HANDLE rib, RIB_UINT32 options, RtString *p )
Reads an ASCII or binary encoded string and returns a pointer to the string in p. The memory used for the string is allocated and must be freed. If the string is added into a hash table as a variable or string, RibDestroyHashTable() will free the data automatically.
Refer to Read Option Flags for Arrays for values to assign the parameter options.
int RibReadStringArray( RIB_HANDLE hrib, RIB_UINT32 options, int numberof, RtString **array)
Reads an array of numberof strings, and assigns *array a pointer to the string array. The memory used is allocated and must be freed when no longer needed.
Refer to Read Option Flags for Arrays for values to assign the parameter options.
int RibReadStringForToken( char *s, char *table, char **tokenend )
Searches for a token listed in a tokentbl encoded table in the string s. If a match followed by a white space, binary encoded character, quote, '#' or '[' *tokenend points to the next character.
Refer to RibReadFileForToken().
int RibReadThroughUndeclaredData( RIB_HANDLE hrib )
If a parameter list contains a token (parameter ID) that has not been declared with a Declare statement, a array of data of unknown length and type probably follows the unknown token. The RIB Reader will attempt to skip over the unknown and recover gracefully.
If the attempt to skip over an array fails, RibReadThroughUndeclaredData() reports a syntax error by calling RibSetError().
int RibReadVer35Option( RIB_HANDLE rib )
To provide backward compatibility with RIB files made before PRMan 3.6, RibReadVer35Option replaces the function that reads NuPatch statements with a 3.5 PRMan compatible NuPatch reading function. RibReadVer35Option() changes a function pointer in a table of pointers given by gRibReadTable[].
The table gRibReadTable[] is a global value that once modified by RibReadVer35Option() affects all subsequently opened RIB files. RibReadVer35Option() replaces the pointer gRibReadTable[kRIB_NUPATCH] with an internal function called RibReadVer35NuPatchV(). To switch back an forth bewteen 3.5 and 3.6 compatibility use RibReadVer35Option() and RibReadVer36Option().
Version 3.5 of PRMan was the last version of PRMan to have only four varying values for each NuPatch. Version 3.6 of PRMan redefined how the parameters given used in NuPatch statements should be read.
int RibReadVer36Option( RIB_HANDLE rib )
Undoes the action taken by RibReadVer35Option(). By default the RIB Reader handles PRMan 3.6 compatible RIB files. RibReadVer36Option only needs to be called when switching back and forth between 3.5 and 3.6 compatibility.
void *RibRealloc( void *p, unsigned int size )
Reallocates a memory block to a new size of size given a pointer to the memory p. Because a memory block may need to be replaced to expand it's size by memory at a different location, a pointer is returned. The possible return values matches that of the standard realloc() function.
RibRealloc provides a central place for altering how the memory is realloc'ed. The Affine Toolkit source code uses a macro _RibRealloc() defined in affine/include/ribhash.h instead of calling RibRealloc() directly. This macro is used so that if a flag RIB_MEMORY_TESTS is defined, the macro will call special compiled version of RibRealloc() that keeps track of memory leaks.
If the Affine libraries are compiled with RIB_MEMORY_TESTS not defined, the macro _RibRealloc() is simply replaced with realloc(). This is to avoid the extra function call involved in calling RibRealloc() which without the memory tests simply calls realloc().
Refer to Rib Memory Functions for more detail on the memory handling functions.
Refer to Memory Allocations in the section More Advanced Subclassing for how pointers to memory are handled in Ri-like calls called from the RIB Reader Library.
int RibRemoveItem( RIB_HASHHND hash, PRIB_HASHATOM atom )
Removes hash item atom from the hash table hash. If the flags kRIB_HASH_FREEDATA and kRIB_HASH_FREEEXTDATA have been ORed into the atom's type value, each flag's associated data field will be freed.
The handle atom will no longer be valid after RibRemoveItem() is called.
Refer to RibAddItem() and Hash Item Types.
int RibResetBuffer( RIB_HANDLE rib )
Each RIB handle has an associated buffer to store incoming data such as strings and arrays that are of unknown length. The buffer is really a linked list of small buffers. When a new string or array is about to be read RibResetBuffer() reduces the size of a RIB handle's link list of buffers to just one RIB_BUFFERITEM data structure.
Refer to RibCreateBuffer(), RibSaveToBuffer(), and RibDestroyBuffer().
int RibSaveToBuffer( RIB_HANDLE rib, int flag )
The RenderMan Standard allows strings to have unlimited length. To handle reading strings of arbitrary length, the RIB Reader library relies on storing in-coming data into a linked list of buffers. Most strings do not exceed 250 characters which fits easily into one buffer, so the ability to link together several buffers will not be used very often and should not slow performance. RibSaveToBuffer() sets a flag that indicates that all following input should be saved into a buffer to be assembled later into one contiguous block of memory.
Some arrays are of unknown length such as the nvertices array in a GeneralPolygon statement. To handle reading an array of integers, floats or strings that is of unknown length the function RibReadArrayAndLength() uses RibSaveToBuffer() to store the array until its length is known and memory can be allocated.
RibSaveToBuffer() calls RibResetBuffer() to reduce the size of a RIB handle's link list of buffers to just one RIB_BUFFERITEM data structure. An assumption is made that if RIB file had one string requiring multiple RIB_BUFFERITEMs, there might be more long strings so once a RIB_BUFFERITEM has been allocated it is either in use or listed as available for use. RIB_BUFFERITEMs are deallocated when the RIB is closed. This saves many extra calls to malloc and free RIB_BUFFERITEMs.
int RibSetArchiveRecordHandler( RIB_HANDLE rib, PRIB_ARCRECFILTERPROC p )
By default a RIB is given RibDefaultArchiveRecordHandler() as the function to handle lines of RIB data preceded with a '#'. To change the function receiving control when a '#' is encountered, RibSetArchiveRecordHandler() replaces the present function with pp.
As a minimum the function p must read characters using RibGetChar() until a '\n' is found. Use RibReadArchiveRecord() to perform this simple function.
Refer to RibGetArcRecHandler().
Refer to RibIgnoreArchiveRecords().
int RibSetDefinedLightHandle( PRIB_HASHATOM a,
int sequence, RtLightHandle lh )
Sets hash atom a's fields code and extdata to sequence and lh.
int RibSetDefinedObjectHandle( PRIB_HASHATOM a,
int sequence, RtObjectHandle oh )
Sets hash atom a's fields code and extdata to sequence and oh.
int RibSetDefinedRIRequest( PRIB_HASHATOM a, int token, int ripID )
Sets hash atom a's fields code and extdata to token and ripID.
int RibSetDefinedString( PRIB_HASHATOM a, int token, char *s )
Sets hash atom structure a's code and and extdata fields with token and s respectively. The token is an integer value that was assigned to represent string s by a binary encoded string definition in a RIB file. Once the definition has been read and added to a RIb's hash table, the token can be used as an abbreviated form of the string.
int RibSetError( RIB_HANDLE rib, int code, int severity, PRIB_ERROR error )
int RibSetErrorHandler( RIB_HANDLE rib, PRIB_ERRORFILTERPROC p )
Changes the default error handler to function pointer p. By default a RIB is assigned RibDefaultErrorHandler() as the error handler.
int RibSetHashExtendedData( PRIB_HASHATOM a, void *t )
Sets hash atom structure a's extdata field to t.
int RibSetHintTable( RIB_HANDLE rib, PRIB_HINTTABLE table )
Assigns table, a table of hint handling functions called a hint table, to rib.
When RibSetHintTable() has associated table with rib, RibDefaultArchiveRecordHandler() will identify the standard hints and forward the hint's data onto a matching hint function listed in a RIB handle's hint table. By default a RIB handle does not have a hint table, but RibSetHintTable() can assign a RIB handle a table of function pointers to act as a hint table.
A global variable gRibHintTable[] is provided in the RIB Reader library as a basic hint table. A tool using the RIB Reader library could copy this table or simply use if global alterations are acceptable.
PRIB_ARCRECFILTERPROC gRibHintTable[] = {
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##CameraOrientation */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##CapabilitiesNeeded */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##CreationDate */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##Creator */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##For */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##Frames */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##Include */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##RenderMan */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##Scene */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler,/* ##Shaders */
(PRIB_ARCRECFILTERPROC)RibDefaultHintHandler /* ##Textures */
};
Refer to RibGetHintTableSize() and RibGetHintTable(). By default a RIB handle has no hint table and RibGetHintTable() will return NULL.
To access the pointers in a hint table use the following named index offsets:
enum {
kRIB_CAMERAORIENTATION_HINT, /* ##CameraOrientation */
kRIB_CAPABILITIESNEEDED_HINT, /* ##CapabilitiesNeeded */
kRIB_CREATIONDATE_HINT, /* ##CreationDate */
kRIB_CREATOR_HINT, /* ##Creator */
kRIB_FOR_HINT, /* ##For */
kRIB_FRAMES_HINT, /* ##Frames */
kRIB_INCLUDE_HINT, /* ##Include */
kRIB_RENDERMAN_HINT, /* ##RenderMan */
kRIB_SCENE_HINT, /* ##Scene */
kRIB_SHADERS_HINT, /* ##Shaders */
kRIB_TEXTURES_HINT, /* ##Textures */
kRIB_LAST_HINT
};
int RibSetLastNUniform( RIB_HANDLE rib, int nuniform )
Sets the number of uniform parameters as number that the RIB Reader library calculated for a given Ri call. This function should only be called from a Ri-like function hooked into the Ri table of rib.
Refer to RibGetLastNUniform()
int RibSetLastNVarying( RIB_HANDLE rib, int nuniform )
Sets the number of varying parameters as number that the RIB Reader library calculated for a given Ri call. This function should only be called from a Ri-like function hooked into the Ri table of rib.
Refer to RibGetLastNVarying()
int RibSetLastNVertex( RIB_HANDLE rib, int nuniform )
Sets the number of vertex parameters as number that the RIB Reader library calculated for a given Ri call. This function should only be called from a Ri-like function hooked into the Ri table of rib.
Refer to RibGetLastNVertex()
int RibSetLastSequence( RIB_HANDLE rib, int n )
The RIB statements LightSource, AreaLightSource and ObjectBegin have a sequence number that appears after the shader name. The sequence number gives the light source or object an ID number. When abstracted to the Ri calls the ID number takes the form of a lighthandle or objecthandle that is returned from RiLightSource(), RiLightSourceV(), RiAreaLightSource(), RiAreaLightSourceV(), or RiObjectBegin().
A tool may want the actual sequence number read in the file. The function RibGetLastSequence() returns the last sequence number read from a RIB file. This last sequence number is set by the function that reads in a complete RIB statement calling RibSetLastSequence().
RibGetLastSequence() is typically called from a RI function that was listed in the RI table associated with a RIB handle or a RI call that has hooked into the calling chain that starts at a given RI table.
int RibSetNColorSamples( RIB_HANDLE rib, int n )
A color can be 1 to n channels. by defualt it is 3 channels, but RibSetNColorSamples() will alter rib's default to n. Subsequent RIB statements that use variables declared as type color, must have n channels.
int RibSetOptions( RIB_HANDLE hrib, RIB_UINT32 mask, RIB_UINT32 flags )
Sets option flags that affect how a RIB file is handled. Refer to RibGetOptions() for the possible flags.
int RibSetRITable( RIB_HANDLE rib, PRIB_RITABLE table )
Associates a table of Ri calls to a RIB handle. This function allows an RI table to be assigned after RibOpenWithHashTable() was used to open a RIB file or after RibOpen() was called with NULL as the ritable parameter.
RibSetRITable() could also be used to dynamically change the set of Ri calls that are called as a RIB file is read in. For example a tool may need to change the set or Ri calls depending on a file's version number.
Refer to RibGetRITable().
int RibSetStringAtom( PRIB_HASHATOM a, int token, char *s )
When writing a RIB file in binary encoded format, string definitions are made that define an integer as a more compact way of referring to a string rather than writing the entire string out. RibSetStringAtom() sets the code and data fields of hash atom structure atom to token and s respectively.
Refer to RibGetStringAtom().
int RibSetStatus( RIB_HANDLE hrib, RIB_UINT32 mask, RIB_UINT32 flags )
Sets the Status Flags that are set for the RIB input hrib. The mask indicates which flags can be changed and flags has the kRIB_STATUS_* values to be set ORed together. To set a flag to zero OR its kRIB_STATUS_* value into the mask value but not into the flags value. Use zero for flags if no flags are to be set.
int RibSetUVStep( RIB_HANDLE rib, RtInt ustep, RtInt vstep )
Sets rib's U and V step values that are both by default set to 3, but depending on the basis used by RiCurve, RiPatch and RiPatchMesh the U and V step values may need to altered.
RibRead() will alter the U and V step values after reading a Basis statement from the input rib. The values are altered before calling the Ri function at position kRIB_BASIS in rib's RI Table.
Refer to RibGetUVStep().
RtBoolean RibShouldFreeData( RIB_HANDLE rib )
Returns nonzero value if pointers given in a present Ri call point to memory areas that should not be freed. Functions the same as RibQueryKeepData() except that it resets a status flag called kRIB_STATUS_KEEP_DATA.
A Ri function must call RibShouldFreeData() if 1) it did not call RibKeepData() to prevent data given to it from being freed when the chain of Ri calls is complete but it did, 2) allocate memory that was given to the next function in the chain, and 3) one of the following functions in the chain called RibKeepData() to keep one of the allocated memory blocks mention in step 2.
If RibKeepData() was called by the present Ri function and the above steps 2 and 3 also occurred then RibQueryKeepData() should be called instead of RibShouldFreeData().
The difference between RibShouldFreeData() and RibQueryKeepData() is whether or not a status flag kRIB_STATUS_KEEP_DATA should remain set as Ri functions return control back to the previous function in the chain.
Refer to RibKeepData() for how to tell the RIB Reader that pointers given to a RI call are pointing to data that can not be freed upon completion of the RI call.
int RibUngetChar( RIB_HANDLE rib, int c )
Places the character c back undoing the last RibGetChar().
int RibVectorCacheInit( RIB_HANDLE hrib, RtInt n )
Refer to RibCacheVector() and RibFreeVectorCache().
RtVoid Rib_version( RtFloat version )
RIB files can have a version statement which is marked by the word "version" (lowercase 'v') and followed by a floating point value. Rib_Version handles these calls by simply a doing a simple return.
The underscore is present because the version statement was never officially added to the RenderMan Standard. There was some mention that it would have been added in version 4.0 of the specification, but Pixar doesn't appear to be planning any further releases of the specification. But just incase "version" is ever added to the specification an extra underscore was added in the RI table index name kRIB__VERSION and the function Rib_version() to distinguish them from any future additions to the standard.