Re: pfFlux question

New Message Reply Date view Thread view Subject view Author view

Simon Mills (simon++at++wgs.estec.esa.nl)
Tue, 26 Jan 1999 09:43:43 +0100


Hi pfTeam,

This is a related question/request for enhancement that I have already
brought up once on info-performer but had no response. Now this topic
appears again I thought I'd try again.

Yair Kurzion wrote:
>
> > >There is no direct way to change the buffer size of a Flux. However,
> > instead
> > >of generating Fluxed GeoSet attributes, you can generate a Fluxed
> > GeoSet with
> > >normal (not Fluxed) attributes.
> > >
> > >A Fluxed GeoSet is a multibuffer version of a GeoSet. Each copy of the
> > GeoSet
> > >has separate pointers to attributes, so you can modify/realloc them in
> > an
> > >MP-safe way. Of course, you can attach Fluxed GeoSets to a Geode.
> > >
> > >There are two examples for using fluxed GeoSets:
> > >
> > >1. pguide/libpf/C++/fluxed_gset.C : Simple example. Changes the number
> > of
> > > primitives in a Fluxed GeoSet.
> >
> > I'm still a little confused. I'm looking at the fluxed_gset.C example.
> > If I allocate some initial size array for my coordinates inside my flux
> > callback function, how would I go back and reallocate more memory later
> > on when I have outgrown my list?
>
> Suppose you want to realloc the COORD attribute on a Fluxed GeoSet. Here is
> what you should do (similar to the routine change_prim_count in
> pguide/libpf/C++/fluxed_gset.C):
>
> 1. Get a writable copy of the Fluxed GeoSet. (pfFlux::getWritableData)
>
> This will return a copy of the multi-buffered GeoSet. You can modify its
> attributes as you please because no other process can see this copy
> until you writeComplete it.
>
> 2. Get COORD Attr from the GeoSet you just received. (pfGeoSet::getAttrLists)
>
> Grab the old Attribute lists. Note that each copy of the Fluxed GeoSet
> should point to a different set of Attribute arrays (see below).
>
> 3. Realloc this Attr array to the new size (pfRealloc)
>
> pfMalloc new attributes if they are NULL or pfRealloc if not NULL.
>
> 4. SetAttr on the GeoSet (pfGeoSet::setAttr)
>
> Store the new attributes on the GeoSet.
>
> 5. WriteComplete. (pfFlux::writeComplete)
>
> Tell Flux that you are done modifying the GeoSet and that it may let other
> processes use it.
>
> When you create a new Fluxed GeoSet as in
>
> fluxed_gset = new pfFlux(make_fluxed_gset, PFFLUX_DEFAULT_NUM_BUFFERS);
>
> you should write an init routine make_fluxed_gset that allocates new
> attribute arrays every time it is invoked. This way the different copies of
> the fluxed GeoSet will have different attribute arrays and the above
> manipulation will be MP-safe. The sample code in pguide/libpf/C++/fluxed_gset.C
> does exactly that.

I can create a fluxed geoset no problem as above, however I wish to pass
arguments to my fluxed geoset init function to parameterize some the
dimensions. This is not possible at present and so as a workaround I
place the arguments in globals and read them in my init function. This
is not very elegant. I notice that function pfFlux::callDataFunc()
*does* allow function arguments to be passed. Could this mechanism also
be implemented for the init function?

To illustrate, this is what I'm doing at present:

/* Globals */

/* only used to pass arguments to fluxed geoset creation callback */
static int AllocPnt;
static float Linewidth;
static int Recolor;
static pfVec4 Startcol;
static pfVec4 Endcol;

  
/*************************** C O D E ***************************/

/* Create a fluxed pfGeoSet with correct properties */

static int
createFluxedGSet(pfFluxMemory *fmem)
{
    pfGeoSet *gset; /* ptr to geoset */
    pfGeoState *gSt; /* ptr to geostate */
    pfVec3 *verts; /* vertex arrays */
    pfVec4 *colors; /* color array */
    int *lengths; /* primitive length array */

    /* "Arguments" - get from globals */
    void *arena = pfGetSharedArena();
    int allocPnt = AllocPnt;
    float linewidth = Linewidth;
    int recolor = Recolor;
    pfVec4 startcol;
    pfVec4 endcol;
    pfCopyVec4(startcol, Startcol);
    pfCopyVec4(endcol, Endcol);
    /* end arguments */
     
    /* If null argument return default size of geoset to create */
    if (fmem == NULL)
            return pfFluxedGSetInit(fmem);

    /* Get geoset to create in flux memory */
    pfFluxedGSetInit(fmem);
    gset = (pfGeoSet *) pfGetData(fmem);
     
    /* GeoSet is single linestrip which will grow dynamically */
    pfGSetNumPrims(gset, 1);
    if (recolor)
             pfGSetPrimType(gset, PFGS_LINESTRIPS);
    else
            pfGSetPrimType(gset, PFGS_FLAT_LINESTRIPS);
     
    /* Create array for vertex values of given size */
    verts = (pfVec3 *)pfMalloc(sizeof(pfVec3)*allocPnt, arena);
    pfGSetAttr(gset, PFGS_COORD3, PFGS_PER_VERTEX, verts, NULL);
     
    /* Create array for color values
     * If start and end colours the same only one colour per geoset
required
     * otherwise a colour per vertex is required
     */
    if (recolor) {
        colors = (pfVec4 *)pfMalloc(sizeof(pfVec4)*allocPnt, arena);
        pfGSetAttr(gset, PFGS_COLOR4, PFGS_PER_VERTEX, colors, NULL);
    }
    else {
        colors = (pfVec4 *)pfMalloc(sizeof(pfVec4), arena);
        pfGSetAttr(gset, PFGS_COLOR4, PFGS_OVERALL, colors, NULL);
        pfCopyVec4(colors[0], startcol);
    }

    /* Create array for line length values */
    lengths = (int *)pfMalloc(sizeof(int), arena);
    pfGSetPrimLengths(gset, lengths);
    lengths[0] = 0; /* initially empty! */
     
    /* Set line width */
    pfGSetLineWidth(gset, linewidth);
     
    /* Attach a geostate to the geoset */
    gSt = pfNewGState(arena);
    pfGSetGState(gset, gSt);
     
    /* Transparency required? */
    if (startcol[3] < 1.0f || endcol[3] < 1.0f)
        pfGStateMode(gSt, PFSTATE_TRANSPARENCY, PFTR_ON);
     
    /* Ensure lighting off, texturing off */
    pfGStateMode(gSt, PFSTATE_ENLIGHTING, PF_OFF);
    pfGStateMode(gSt, PFSTATE_ENTEXTURE, PF_OFF);

#ifdef DEBUG
    pfPrint(gset, PFTRAV_SELF, PFPRINT_VB_INFO, NULL);
#endif

    return 0;
}

.
.
.
    /* Setup globals for passing values to fluxed geoset creation
callback */
    AllocPnt = t->allocPnt;
    Linewidth = linewidth;
    Recolor = t->recolor;
    pfCopyVec4(Startcol, startcol);
    pfCopyVec4(Endcol, endcol);

    /* Create empty fluxed geoset to contain the geometry */
    t->fluxedGSet = pfNewFluxInitFunc(createFluxedGSet,
                                                      PFFLUX_DEFAULT_NUM_BUFFERS, arena);
.
.
.

  
> One more note:
> If your GeoSet has an attribute that NEVER needs modification or realloc, you
> can use the same array for setting this attribute every time your init routine
> is invoked. e.g. If your vertex normals change but the vertices themselves
> never change, you can allocate the COORD attribute array only once and use the
> same memory for all COORD attributes.
>
> -yair
>
> --
> \_________ \_____ \__ \__ \_____ Yair Kurzion
> \_________ \_____ \__ \__ \_____ yair++at++sgi.com
> \__ \__ \____\__ \__ http://reality.sgi.com/yair
> \__ \__ \__ Work: (650) 933-6502
> \__ \__ \__ Home: (408) 226-9771
> \__ \__ \__
> =======================================================================
> List Archives, FAQ, FTP: http://www.sgi.com/software/performer/
> Submissions: info-performer++at++sgi.com
> Admin. requests: info-performer-request++at++sgi.com

-- 
Regards, Simon
________________________________________________________________________

Simon C. Mills Modelling & Simulation Section (TOS-EMM) Tel: +31 (0)71 565 3725 European Space Agency (ESA/ESTEC) Fax: +31 (0)71 565 5419 Postbus 299, 2200AG Noordwijk e-mail: simon++at++wgs.estec.esa.nl The Netherlands http://www.estec.esa.nl/wmwww/EMM ________________________________________________________________________


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Tue Jan 26 1999 - 00:43:57 PST

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.