OpenGL and RenderMan - Object Instancing
[ contents ]
Object Instancing

RenderMan

The RenderMan Interface allows for predefining models and then subsequently create instances of those models. This is particularly helpful in animation, where every frame redraws the object in question, or in a case when you have a number of identical objects in one frame. Only procedures that declare geometry can be called, no transformation procedures are allowed, and only surfaces of the same type may be instanced in one retained model.

OpenGL

OpenGL offers a fairly sophisticated object and state instancing scheme. a display list is a group of OpenGL commands that have been stored for later execution. When a display list is invoked, the commands in it are executed in the order in which they were issued. Almost all of the OpenGL commands can be stored in display lists, geometric transformations and geometry calls alike. Display lists may improve performance.


RtObjectHandle RiObjectBegin()
RiObjectEnd()

A block of RenderMan surface declaration calls bounded by calls to RiObjectBegin() and RiObjectEnd() define a retained model. The model is thereafter referred to by the object handle returned by RiObjectBegin(). Objects created before RiFrameBegin() will be valid for all of the frames, while an object created in the world block will only be valid for that frame.

RtObjectHandle square_handle;

square_handle = RiObjectBegin();
...draw geometry here
RiObjectEnd();

RiObjectInstance(handle)

An instance of the model is created in the current space by calling RiObjectInstance(), passing it the model's handle. This includes in the scene any primatives in the model exactly as they were defined previously. The current transformation is applied to the surface geometry when the object is instanced, not when it is defined. All attributes are assigned during instancing, not during definition.

RtObjectHandle(square_handle);

for(i = 0; 1 < 100; ++1){
RiObjectInstance(square_handle);
}

int glGenList(range)

Allocates range number of contigous previously unallocated display-list indices. The integer returned is the index that marks the beginning of a contiguous block of empty display-list indices. Zero is returned if the requested number of indices isn't available, or if range is zero.

int listindex;

listindex = glGenList(1);

glNewList(list, mode)
glEndLIst

glNewList() specifies the start of a display list. All OpenGL routines that are called after glNewList() and before glEndList() are stored in a display list, except for a few restricted routines that can't be stored. list is a nonzero positive integer that uniquely identifies the display list. mode can be GL_COMPILE_AND_EXECUTE and GL_COMPILE. GL_COMPILE can be used to just create the list, use the former if you want to create and then immediately execute the list.

glNewList(listindex, GL_COMPILE);
...draw geometry here
glEndList();

glCallList(list)

This routine executes the display list specified by list. The commands in the display list are executed in the order they were saved, just as if they where issued without using the display list. if list hasn't been defined, nothing happens.

glCallList(listindex);