Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

FreeVRScene.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 /***************************************************************************
00009  * RCS INFORMATION:
00010  *
00011  *      $RCSfile: FreeVRScene.C,v $
00012  *      $Author: johns $        $Locker:  $             $State: Exp $
00013  *      $Revision: 1.43 $       $Date: 2020/02/26 15:51:10 $
00014  *
00015  ***************************************************************************/
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <freevr.h>
00032 
00033 #include "FreeVRScene.h"
00034 #include "FreeVRRoutines.h"
00035 #include "DisplayDevice.h"
00036 #include "Inform.h"
00037 #include "utilities.h"
00038 #include "VMDApp.h" // for VMDexit()
00039 
00040 #define FREEVRUSERWLOCK 1
00041 
00043 FreeVRScene::FreeVRScene(VMDApp *vmdapp) : app(vmdapp) {
00044 #if defined(FREEVRUSERWLOCK)
00045   msgInfo << "Creating R/W lock for shared mem access sync.\n" << sendmsg;
00046 //  draw_rwlock = vrLockCreate(vmdapp->freevrcontext); // allocate an RW Lock
00047   draw_rwlock = vrLockCreate();    // allocate an RW Lock
00048   vrLockWriteSet(draw_rwlock);     // start out locked for writing
00049 #else
00050   msgInfo << "Creating draw barrier for " << vrContext->config->num_windows 
00051           << " active FreeVR walls and master process.\n" << sendmsg;
00052 
00053   // setup the drawing barrier used to control slave rendering processes
00054   draw_barrier =(wkf_barrier_t *) malloc_from_FreeVR_memory(sizeof(wkf_barrier_t));
00055   if (draw_barrier == NULL) {
00056     msgErr << "CANNOT ALLOCATE SHARED MEMORY FOR FreeVRScene CLASS !!!"
00057            << sendmsg;
00058   }
00059   memset(draw_barrier, 0, sizeof(wkf_barrier_t));
00060 
00061   if (getenv("VMDFREEVRDRAWPROCS") != NULL) {
00062     wkf_thread_barrier_init_proc_shared(draw_barrier, atoi(getenv("VMDFREEVRDRAWPROCS")) + 1);
00063   } else {
00064     wkf_thread_barrier_init_proc_shared(draw_barrier, vrContext->config->num_windows + 1);
00065   }
00066 #endif
00067 }
00068 
00070 FreeVRScene::~FreeVRScene(void) {
00071 #if defined(FREEVRUSERWLOCK)
00072   // XXX somehow we need to get the rendering slaves to 
00073   //     exit cleanly rather than getting stuck in mid-draw
00074   //     attempting to do various stuff when the world goes away. 
00075   vrLockFree(draw_rwlock); // delete the drawing rwlock
00076 #else
00077   // free things allocated from shared memory
00078   free_to_FreeVR_memory(draw_barrier);
00079 #endif
00080 }
00081 
00082 // Called by FreeVR, on each of the child rendering processes
00083 void FreeVRScene::draw(DisplayDevice *display) {
00084 #if defined(FREEVRUSERWLOCK)
00085   /* NOTE: the default build uses this RW-LOCK code */
00086   if (display->is_renderer_process()) {
00087     vrLockReadSet(draw_rwlock);
00088     Scene::draw(display);
00089     vrLockReadRelease(draw_rwlock);
00090   } else {
00091     vrLockWriteRelease(draw_rwlock);
00092     vmd_msleep(1); // give 'em 1 millisecond to draw before re-locking
00093     vrLockWriteSet(draw_rwlock); 
00094   }
00095 #else
00096   // Barrier synchronization for all drawing processes and the master
00097   wkf_thread_barrier(draw_barrier, 0); // wait for start of drawing
00098   Scene::draw(display);                // draw the scene
00099   wkf_thread_barrier(draw_barrier, 0); // wait for end of drawing.
00100 #endif
00101 }
00102 
00103 /* BS: this version makes use of the special vrRenderInfo conduit that passes properties from FreeVR into the render routine */
00104 // Called by FreeVR, on each of the child rendering processes
00105 void FreeVRScene::draw(DisplayDevice *display, vrRenderInfo *rendinfo) {
00106 #if defined(FREEVRUSERWLOCK)
00107   /* NOTE: the default build uses this RW-LOCK code */
00108   if (display->is_renderer_process()) {
00109     //vrLockReadSet(draw_rwlock);       /* BS: this is hanging in the version that uses vrRenderInfo! */
00110     vrRenderTransformUserTravel(rendinfo);
00111     Scene::draw(display);
00112     //vrLockReadRelease(draw_rwlock);   /* BS: this is hanging in the version that uses vrRenderInfo! */
00113   } else {
00114     /* BS: a question -- why do non-rendering processes get here? */
00115     vrLockWriteRelease(draw_rwlock);
00116     vmd_msleep(1); // give 'em 1 millisecond to draw before re-locking
00117     vrLockWriteSet(draw_rwlock); 
00118   }
00119 #else
00120   // Barrier synchronization for all drawing processes and the master
00121   wkf_thread_barrier(draw_barrier, 0); // wait for start of drawing
00122   Scene::draw(display);                // draw the scene
00123   wkf_thread_barrier(draw_barrier, 0); // wait for end of drawing.
00124 #endif
00125 }
00126 
00127 // this is called by the parent!
00128 int FreeVRScene::prepare() {
00129   // check if the ESC key is being pressed; if so, quit
00130   // note: THIS IS A HACK, just for Bill Sherman
00131   if(vrGet2switchValue(0)) {
00132     vrExit();
00133     app->VMDexit("Exiting due to FreeVR escape key being pressed", 10, 4);
00134   }
00135 
00136   return Scene::prepare(); // call regular scene prepare method
00137 }
00138 
00139 void *FreeVRScene::operator new(size_t s) {
00140   return malloc_from_FreeVR_memory(s);
00141 }
00142 
00143 void FreeVRScene::operator delete(void *p, size_t) {
00144   free_to_FreeVR_memory(p);
00145 }
00146 

Generated on Wed Dec 4 02:43:40 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002