Yair Kurzion (yair++at++polygon.engr.sgi.com)
Tue, 26 Jan 1999 12:31:41 -0800 (PST)
The reason for not implementing such an init-function-data feature is that
pfFlux may call the init function any time during the execution of your
program. This happens every time pfFlux decides to add a new Flux buffer. It
means that the init-function-data has to remain untouched in memory after the
creation of the Fluxed Geoset.
Assuming pfNewFluxInitFunc took init-function-data: when creating an extra copy
of the Fluxed Geoset on the fly, Flux would call the initialization routine,
and therefore would have to supply the original init-function-data. So, this
isn't really init-function-data, but more like user-data.
This is exactly why they put user-data on a pfObject.
Since a pfFlux is also a pfObject, and pfObjects can carry user-data, you can
attach user-data to any pfFlux:
pfUserData ((pfObject *) fluxed_gset, (void *) fluxed_gset_user_data);
The routine pfuNewGSetShadowNode in asdfly/pfuLightPoints.c uses pfObject
user-data in order to initialize fluxed GeoSets. Here is its logic:
1. Create a Fluxed GeoSet using pfNewFluxInitFunc. The init function calls
pfFluxedGSetInit to create the correct GeoSet structure in the Flux buffer.
It checks for user-data on the Flux pfObject. At this stage, there is no
user-data so it does nothing.
2. Prepare a block of data with enough information for filling in the contents
of the GeoSets.
3. call pfFluxCallDataFunc and use this block to fill in all the CURRENTLY
ALLOCATED Fluxed GeoSet buffers.
At this point, all the GeoSet buffers contain valid information. We still have
to make sure that newly created Flux buffers get initialized the same way.
4. Set the previous block of information to be the user-data of the Flux
pfObject.
If pfFlux creates a new buffer on the fly, it calls the original init function
(the one supplied in pfNewFluxInitFunc) on the new buffer. This time, the
Flux pfObject has user-data so we use it to attach contents to the new GeoSet.
Here is roughly what the Flux init function in asdfly looks like:
int fluxed_gset_create_func (pfFluxMemory *fmem)
{
pfGeoSet *gset;
pfFlux *flux;
void *flux_data;
if (fmem == NULL)
return pfFluxedGSetInit(fmem);
pfFluxedGSetInit(fmem);
gset = (pfGeoSet*)pfGetData(fmem);
... Other initializations that don't require additional data
...
... Grab the parent Flux of the Flux memory.
... This is derived from pfObject so we can get its user-data.
flux = pfGetFluxMemoryFlux(fmem);
... If we have user-data, then this must be a newly generated buffer.
... Use the user-data to fill information into this GeoSet buffer.
flux_data = pfGetUserData ((pfObject *) flux);
if (flux_data)
fluxed_gset_init_func ((void *) gset, flux_data);
return 0;
}
It's a bit complicated. However, having pfNewFluxInitFunc remember your
init-function-data would be ugly (not to mention - a cause for trouble).
-yair
--
\_________ \_____ \__ \__ \_____ Yair Kurzion
\_________ \_____ \__ \__ \_____ yair++at++sgi.com
\__ \__ \____\__ \__ http://reality.sgi.com/yair
\__ \__ \__ Work: (650) 933-6502
\__ \__ \__ Home: (408) 226-9771
\__ \__ \__
This archive was generated by hypermail 2.0b2 on Tue Jan 26 1999 - 12:31:46 PST