Re: Re: [info-performer] bin-user-data

Date view Thread view Subject view Author view

From: Alexej Fink (alexejfink++at++gmx.net)
Date: 11/03/2005 01:04:56


Hello,

> On Wed, 2 Nov 2005 11:29:37 +0100 (MET), Alexej Fink <alexejfink++at++gmx.net>
> wrote:
>
> > Hello,
> >
> > we have a problem submitting a userdata-pointer to bin pre/post funcs:
> > ---- code ----------------------------------------------------
> > //virtual
> > void avMPShaderProgram::setupBin( int bin, pfChannel& chan) {
> > chan.setBinCallBack( bin, PFBIN_CALLBACK_PRE_DRAW,
> > &avMPShaderProgram::pre);
> > chan.setBinCallBack( bin, PFBIN_CALLBACK_POST_DRAW,
> > &avMPShaderProgram::post);
> > chan.setBinUserData( bin, this, sizeof(avMPShaderProgram));
> > ...
> > --------------------------------------------------------------
> >
> > in the callback function "&avMPShaderProgram::pre":
> > ---- code ----------------------------------------------------
> > //static
> > void avMPShaderProgram::pre ( void *userData)
> > {
> > avMPShaderProgram *sp = (avMPShaderProgram*) userData;
> > std::cout << "avMPShaderProgram::pre-userData: " << sp << std::endl <<
> > std::flush;
> > sp->pre_impl(); // virtual member func.
> > }
> > --------------------------------------------------------------
> >
> > we get a different/wrong pointer. Any suggestions?
>
> setBinUserData will actually make a copy of the "object" you
> assign it, and provide a pointer to this copy to your bin callbacks.
> [This is why you also need to provide a size value].
>
> In your case, try something like this:
>
> void avMPShaderProgram::setupBin( int bin, pfChannel& chan) {
> chan.setBinCallBack( bin, PFBIN_CALLBACK_PRE_DRAW,
> &avMPShaderProgram::pre);
> chan.setBinCallBack( bin, PFBIN_CALLBACK_POST_DRAW,
> &avMPShaderProgram::post);
>
> /* allocate a pointer-to-your-class in shared arena */
> avMPShaderProgram** ptrToThis = (avMPShaderProgram**)pfCalloc(1,
> sizeof(avMPShaderProgram*), pfGetSharedArena());
>
> /* set this pointer to point to 'this' */
> *ptrToThis = this;
>
> /* provide a pointer to the pointer-to-your-class;
> note that size is only the sizeof a pointer */
> chan.setBinUserData( bin, ptrToThis, sizeof(avMPShaderProgram*));
> ...
> }
>
> void avMPShaderProgram::pre ( void *userData)
> {
> /* userData is a pointer to a pointer-to-your-class. cast and
> dereference appropriately to obtain the pointer you need. */
> avMPShaderProgram *sp = *((avMPShaderProgram**)userData);
> std::cout << "avMPShaderProgram::pre-userData: " << sp << std::endl <<
>
> std::flush;
> sp->pre_impl(); // virtual member func.
> }
>
> Let me know if this does not work.
Thanks for the fast reply.
It seems that it works without copying data too (as U can see in my second
mail "bin-user-data more info"). In that case I called setBinUserData() with
size set to zero, and finally I get the pointer delivered in the pre/post
funcs, but unfortunately there is also an unexpected call to pre() with
some strange user-data pointer from an unknown bin.

>
> > and one more time:
> >
> > - why is bin-managing "done" by channel-instances?
> >
>
> Binning is tightly related to the cull and draw traversals.
> Both are done at the channel level (see manpages for pfCull
> and pfDraw).
>
1. why not using something like static pfChannel::getBinManager() - to get
bin-managing interface to pfChannel?
otherwise calling bin-funcs on some pfChannel-instance let me think, that
the bins are managed per channel (so differ from channel to channel), and
pfChannel is already too complex.

2. there is no func like insert bin ++at++ some position (so following bins are
shifted correctly) - what could lead to some unwanted behaviour in case,
there are some more transparent bins.

> Paolo Farinelli <paolo++at++sgi.com>
> OpenGL|Performer - Silicon Graphics Inc.
>
> -----------------------------------------------------------------------
> List Archives, Info, FAQ: http://www.sgi.com/software/performer/
> Open Development Project: http://oss.sgi.com/projects/performer/
> Submissions: info-performer++at++sgi.com
> Admin. requests: info-performer-request++at++sgi.com
> -----------------------------------------------------------------------
>
Alexej

-- 
Telefonieren Sie schon oder sparen Sie noch?
NEU: GMX Phone_Flat http://www.gmx.net/de/go/telefonie


Date view Thread view Subject view Author view

This archive was generated by hypermail 2b29 : Thu Nov 03 2005 - 01:05:01 PST