00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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"
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
00047 draw_rwlock = vrLockCreate();
00048 vrLockWriteSet(draw_rwlock);
00049 #else
00050 msgInfo << "Creating draw barrier for " << vrContext->config->num_windows
00051 << " active FreeVR walls and master process.\n" << sendmsg;
00052
00053
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
00073
00074
00075 vrLockFree(draw_rwlock);
00076 #else
00077
00078 free_to_FreeVR_memory(draw_barrier);
00079 #endif
00080 }
00081
00082
00083 void FreeVRScene::draw(DisplayDevice *display) {
00084 #if defined(FREEVRUSERWLOCK)
00085
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);
00093 vrLockWriteSet(draw_rwlock);
00094 }
00095 #else
00096
00097 wkf_thread_barrier(draw_barrier, 0);
00098 Scene::draw(display);
00099 wkf_thread_barrier(draw_barrier, 0);
00100 #endif
00101 }
00102
00103
00104
00105 void FreeVRScene::draw(DisplayDevice *display, vrRenderInfo *rendinfo) {
00106 #if defined(FREEVRUSERWLOCK)
00107
00108 if (display->is_renderer_process()) {
00109
00110 vrRenderTransformUserTravel(rendinfo);
00111 Scene::draw(display);
00112
00113 } else {
00114
00115 vrLockWriteRelease(draw_rwlock);
00116 vmd_msleep(1);
00117 vrLockWriteSet(draw_rwlock);
00118 }
00119 #else
00120
00121 wkf_thread_barrier(draw_barrier, 0);
00122 Scene::draw(display);
00123 wkf_thread_barrier(draw_barrier, 0);
00124 #endif
00125 }
00126
00127
00128 int FreeVRScene::prepare() {
00129
00130
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();
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