Re: C++ Draw Callback?

New Message Reply Date view Thread view Subject view Author view

Jan Barglowski (jan++at++euryale.chinalake.navy.mil)
Mon, 2 Dec 1996 10:28:07 -0800 (PST)


Bernard Leclerc wrote:
>
> Jan Barglowski wrote:
>
> > I'd like to have a C++ method as the callback function, set by
> > pfChannel->setTravFunc().
>
> Martin Reddy wrote:
>
> > [...] or, perhaps more elegantly, your callback should be
> > defined as a static member function of the object, e.g.
> >
> > class MyClass {
> > public:
> > static void DrawChannel( pfChannel *chan, void *data );
> > };
> >
> > ....
> > chan->setTravFunc( PFTRAV_DRAW, MyClass::DrawChannel );
> > ....
>
>
>
> Martin's suggestion should be extended a little more by deriving a new
> class from pfChannel. In order to obtain a virtual draw function, I'm
> using a class similar to this:
>
> class myChannel: public pfChannel {
> public:
> myChannel(pfPipe*);
> virtual void draw() { clear(); pfDraw(); }
> private:
> static void drawCallback(pfChannel*, void*);
> };
>
> myChannel::myChannel(pfPipe* p) : pfChannel(p)
> {
> setTravFunc( PFTRAV_DRAW, drawCallback );
> }
>
> void myChannel::drawCallback(pfChannel* chan, void*)
> {
> ((myChannel*) chan)->draw();
> }
>
>
>
> With a class like this one, "new myChannel" will automatically create a
> pfChannel and assign it a DRAW callback which, in fact, is a virtual C++
> method. Remember to use chanData (or a pfCycleBuffer) to maintain frame
> accurate data in all stages (APP, CULL and DRAW).
>
> Is this what you were looking for Jan?
>

Beautiful! I entirely forgot that I could subclass Performer objects.
Thanks to all who responded -- I got lots of interesting OO thoughts on
which to start my mind off on Monday morning..

jan

-- 
Jan Anthony Barglowski	              jan++at++cyclops.chinalake.navy.mil
Real-time Computer Graphics           http://www1.ridgecrest.ca.us/~jan
Naval Air Warfare Center, China Lake  (619) 927-1057

======================================================================= List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/ Submissions: info-performer++at++sgi.com Admin. requests: info-performer-request++at++sgi.com


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:54:04 PDT

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