From: Ran Yakir (rany++at++rtset.co.il)
Date: 01/17/2000 18:05:51
Hello Scott,
As a general rule, I wouldn't try to add or delete channels on the fly. You can
always create the maximum number of channels required for your app, ahead of time,
and just reattach new scenes for them if you need to replace channel db. Also,
pfDelete-ing nodes is bad as it is, since it will eventually fragement your memory,
but sometimes it is unavoidable.
Ran
Scott Herod wrote:
> Hello,
>
> I've been playing with drawing multiple, overlapping channels
> using as a starting point the multichannel example in the demo
> code. I've attached my version to this message.
>
> Adding a pfChannel works ok ( with a several frame pause as
> my O2 loads the cow.obj model ). However, on the first
> pfSync() call after I delete the channel and scene that I
> previously added, I get a core dump in pfChannel::pf_addAppFunc(). The
> following code, results in
> a failure with the call stack listed below it.
>
> ----------------
>
> pfDelete( scene3 );
> pfDelete( chan3 );
>
> // Simulate for twenty seconds.
> while (t < 30.0f) {
> // Go to sleep until next frame time.
> pfSync();
>
> --------
>
> pfChannel::pf_callAppFunc() ["pfLists.h":225]
> pfAppFrame(<stripped>) ["pfProcess.C":3462]
> pfSync(<stripped>) ["pfProcess.C":3484]
> main(argc = 3, argv = 0x7fff2ec4) ["MultiChan.C":196]
> __start(<stripped>) ["crt1text.s":177]
>
> -----------
>
> Is it not possible to delete a pfChannel at run time? I
> used the same draw function for the deleted channel as for
> one of the non-deleted channel. The call-stack hints that
> that might be a problem.
>
> This is:
> performer_eoe 12/09/1999 Performer2.2.6 Execution Environment
> on an O2.
>
> Thanks,
>
> Scott Herod
> herod++at++rtset.com
>
> ------------------------------------------------------------------------
> // Last update at Time-stamp: <00/01/17 16:32:27 herod>
>
> #include <stdlib.h>
>
> #include <Performer/pf/pfChannel.h>
> #include <Performer/pf/pfLightSource.h>
> #include <Performer/pr/pfLight.h>
> #include <Performer/pf/pfDCS.h>
>
> #include <Performer/pfdu.h>
>
> #include <iostream.h>
>
> static void OpenPipeWin(pfPipeWindow *pw);
> static void DrawChannel(pfChannel *chan, void *data);
> static void ClearDrawChannel(pfChannel *chan, void *data);
>
> //
> // Usage() -- print usage advice and exit. This
> // procedure is executed in the application process.
> //
>
> static void Usage (void) {
> pfNotify(PFNFY_FATAL, PFNFY_USAGE, "Usage: multichanC file1.ext file2.ext \n");
> exit(1);
> }
>
> int main (int argc, char *argv[]) {
> float t = 0.0f;
>
> if (argc < 3)
> Usage();
>
> // Initialize Performer
> pfInit();
>
> // Use default multiprocessing mode based on number of
> // processors.
> //
> pfMultiprocess( PFMP_APP_CULL_DRAW );
>
> // Load all loader DSO's before pfConfig() forks
> pfdInitConverter(argv[1]);
> pfdInitConverter(argv[2]);
>
> // Configure multiprocessing mode and start parallel
> // processes.
> //
> pfConfig();
>
> // Attach loaded file to a pfScene.
> pfScene *scene1 = new pfScene;
> pfScene *scene2 = new pfScene;
>
> pfDCS* dcs1 = new pfDCS();
> pfDCS* dcs2 = new pfDCS();
>
> // Append to PFPATH additional standard directories where
> // geometry and textures exist
> //
> pfFilePath(".:/usr/share/Performer/data");
>
> // Read a single file, of any known type.
> pfNode *root1 = pfdLoadFile(argv[1]);
> if (root1 == NULL) {
> pfExit();
> exit(-1);
> }
>
> // Read a single file, of any known type.
> pfNode *root2 = pfdLoadFile(argv[2]);
> if (root2 == NULL) {
> pfExit();
> exit(-1);
> }
>
> // determine extent of scene's geometry
> pfSphere bsphere1;
> root1->getBound(&bsphere1);
> dcs1->addChild( root1 );
> dcs1->setScale( 0.25f );
> scene1->addChild( dcs1 );
> pfLightSource* ls1 = new pfLightSource();
> ls1->setColor( PFLT_DIFFUSE, 1.0f, 1.0f, .8f );
> ls1->setColor( PFLT_AMBIENT, .4f, .4f, .3f );
> ls1->setColor( PFLT_SPECULAR, 0.0f, 0.0f, 0.0f );
> ls1->setPos( 0.0f, -1.0f, 1.0f, 0.0f );
> scene1->addChild( ls1 );
>
> // determine extent of scene's geometry
> pfSphere bsphere2;
> root2->getBound(&bsphere2);
> dcs2->addChild( root2 );
> dcs2->setScale( 0.25f );
> scene2->addChild( dcs2 );
> pfLightSource* ls2 = new pfLightSource();
> ls2->setColor( PFLT_DIFFUSE, .8f, .8f, 1.0f );
> ls2->setColor( PFLT_AMBIENT, .3f, .3f, .4f );
> ls2->setColor( PFLT_SPECULAR, 0.0f, 0.0f, 0.0f );
> ls2->setPos( 0.0f, -1.0f, 1.0f, 0.0f );
> scene2->addChild( ls2 );
>
> // Configure and open GL window
> pfPipe *p = pfGetPipe(0);
> pfPipeWindow *pw = new pfPipeWindow(p);
> pw->setName("IRIS Performer");
> pw->setOriginSize(0, 0, 600, 600);
> pw->config();
>
> // Create and configure a pfChannel.
> pfChannel *chan[2];
>
> pfCoord view;
> view.hpr.set( 0.0f, 0.0f, 0.0f );
> view.xyz.set( 0.0f, -586.0f, 0.0f );
>
> for (int loop=0; loop < 2; loop++) {
> chan[loop] = new pfChannel(p);
> if ( loop == 0 ) {
> // chan[loop]->setTravFunc(PFTRAV_DRAW,DrawChannel);
> chan[loop]->setScene(scene1);
> chan[loop]->setNearFar( 1.0f, 8000000.0f );
> }
> else if ( loop == 1 ) {
> chan[loop]->setTravFunc(PFTRAV_DRAW, ClearDrawChannel);
> chan[loop]->setScene(scene2);
> chan[loop]->setNearFar( 1.0f, 8000000.0f );
> }
> chan[loop]->setFOV(45.0f, 0.0f);
> chan[loop]->setViewport( 0.0f, 1.0f, 0.0f, 1.0f);
> chan[loop]->setView( view.xyz, view.hpr );
> }
>
> // Simulate for twenty seconds.
> while (t < 10.0f) {
> // Go to sleep until next frame time.
> pfSync();
>
> // Compute new view position.
> // 45.0f*t
>
> t = pfGetTime();
> dcs1->setRot( 45.0f*t, 0.0f, 0.0f );
> dcs2->setRot( 45.0f*t, 0.0f, 0.0f );
>
> // Initiate cull/draw for this frame.
> pfFrame();
> }
>
> // Let's add a new channel and render some more
> pfScene *scene3 = new pfScene();
> pfDCS* dcs3 = new pfDCS();
> pfNode* root3 = pfdLoadFile( "cow.obj" );
> dcs3->addChild( root3 );
> dcs3->setScale( 10.0f );
> scene3->addChild( dcs3 );
> pfLightSource* ls3 = new pfLightSource();
> ls3->setColor( PFLT_DIFFUSE, 1.0f, 1.0f, .8f );
> ls3->setColor( PFLT_AMBIENT, .4f, .4f, .3f );
> ls3->setColor( PFLT_SPECULAR, 0.0f, 0.0f, 0.0f );
> ls3->setPos( 0.0f, -1.0f, 1.0f, 0.0f );
> scene3->addChild( ls3 );
> pfChannel* chan3;
> chan3 = new pfChannel( p );
> chan3->setTravFunc(PFTRAV_DRAW, ClearDrawChannel);
> chan3->setScene(scene3);
> chan3->setNearFar( 1.0f, 8000000.0f );
> chan3->setFOV(45.0f, 0.0f);
> chan3->setViewport( 0.0f, 1.0f, 0.0f, 1.0f);
> chan3->setView( view.xyz, view.hpr );
>
>
> // Simulate for twenty seconds.
> while (t < 20.0f) {
> // Go to sleep until next frame time.
> pfSync();
>
> // Compute new view position.
> // 45.0f*t
>
> t = pfGetTime();
> dcs1->setRot( 45.0f*t, 0.0f, 0.0f );
> dcs2->setRot( 45.0f*t, 0.0f, 0.0f );
> dcs3->setRot( 45.0f*t, 0.0f, 0.0f );
>
> // Initiate cull/draw for this frame.
> pfFrame();
> }
>
> pfDelete( scene3 );
> pfDelete( chan3 );
>
> // Simulate for twenty seconds.
> while (t < 30.0f) {
> // Go to sleep until next frame time.
> pfSync();
>
> // Compute new view position.
> // 45.0f*t
>
> t = pfGetTime();
> dcs1->setRot( 45.0f*t, 0.0f, 0.0f );
> dcs2->setRot( 45.0f*t, 0.0f, 0.0f );
>
> // Initiate cull/draw for this frame.
> pfFrame();
> }
>
> // Terminate parallel processes and exit.
> pfExit();
> return 0;
> }
>
> static void ClearDrawChannel (pfChannel *chan, void *) {
> pfVec4 clr = pfVec4( 0.0f, 0.0f, 0.0f, 0.0f );
> pfClear( PFCL_DEPTH, &clr );
> // invoke Performer draw-processing for this frame
> pfDraw();
> }
>
> static void DrawChannel (pfChannel *chan, void *) {
>
> // invoke Performer draw-processing for this frame
> pfDraw();
> }
This archive was generated by hypermail 2b29 : Mon Jan 17 2000 - 18:00:29 PST