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 /*************************************************************************** 00010 * RCS INFORMATION: 00011 * 00012 * $RCSfile: CaveRoutines.C,v $ 00013 * $Author: johns $ $Locker: $ $State: Exp $ 00014 * $Revision: 1.38 $ $Date: 2019/01/17 21:20:58 $ 00015 * 00016 *************************************************************************** 00017 * DESCRIPTION: 00018 * 00019 * routines to get memory from and return memory to the 00020 * CAVE shared memory arena 00021 ***************************************************************************/ 00022 00023 #include <cave_ogl.h> 00024 00025 #include "CaveRoutines.h" 00026 #include "Inform.h" 00027 #include "VMDApp.h" 00028 #include "CaveDisplayDevice.h" 00029 #include "CaveScene.h" 00030 00031 #if defined(__irix) 00032 static void *shared_CAVE_memory_arena = NULL; 00033 #endif 00034 00035 #define CAVEMAGICINIT 3141 00036 static int vmd_cave_initialized_flag = 0; // global init state variable 00037 00038 int vmd_cave_is_initialized() { 00039 if (vmd_cave_initialized_flag == CAVEMAGICINIT) 00040 return 1; 00041 else 00042 return 0; 00043 } 00044 00045 void vmd_set_cave_is_initialized() { 00046 vmd_cave_initialized_flag = CAVEMAGICINIT; 00047 } 00048 00049 void *malloc_from_CAVE_memory(size_t size) { 00050 #if defined(__irix) 00051 // Allocate memory from our shared memory arena 00052 if (shared_CAVE_memory_arena == NULL) { 00053 // this should be fun. 00054 msgErr << "Shared CAVE memory not allocated. Prepare to crash and burn." 00055 << sendmsg; 00056 return NULL; 00057 } else { 00058 // get memory from the CAVE shared memory arena 00059 return amalloc(size, shared_CAVE_memory_arena); 00060 } 00061 #else 00062 // Allocate from shared CAVE pool 00063 void *retval = CAVEMalloc(size); 00064 if (!retval) 00065 // this should be fun. 00066 msgErr << "Not enough shared CAVE memory. Prepare to crash and burn." 00067 << sendmsg; 00068 return retval; 00069 #endif 00070 } 00071 00072 void free_to_CAVE_memory(void *data) { 00073 #if defined(__irix) 00074 // Free memory from our shared memory arena 00075 afree(data, shared_CAVE_memory_arena); 00076 #else 00077 // Free from CAVE shared memory pool 00078 CAVEFree(data); 00079 #endif 00080 } 00081 00082 // get megs o' memory from the CAVE, and create the arena 00083 // Warning: Don't make me do this twice. 00084 void grab_CAVE_memory(size_t megs) { 00085 #if defined(__irix) 00086 // Make our own shared memory arena using the CAVE to set it up, 00087 // done on IRIX due to old revs of the CAVE library having bugs etc. 00088 size_t size = (megs>1?megs:1) * 1024L * 1024L; 00089 shared_CAVE_memory_arena = CAVEUserSharedMemory(size); 00090 00091 if (!shared_CAVE_memory_arena) 00092 msgErr << "Bad juju in the arena. We're gonna die!" << sendmsg; 00093 else 00094 msgInfo << "Created arena." << sendmsg; 00095 #else 00096 // Trust the CAVE library to setup enough shared mem for subsequent calls 00097 size_t size = (megs>1?megs:1) * 1024L * 1024L; 00098 CAVESetOption(CAVE_SHMEM_SIZE, size); 00099 #endif 00100 } 00101 00102 00103 // set up the graphics, called from CAVEInitApplication 00104 void cave_gl_init_fn(void) { 00105 // nothing to do 00106 } 00107 00108 // XXX globals to keep track of the display and scene data structures 00109 static Scene *cavescene; 00110 static DisplayDevice *cavedisplay; 00111 00112 void set_cave_pointers(Scene *scene, DisplayDevice *display) { 00113 cavescene = scene; 00114 cavedisplay = display; 00115 } 00116 00117 // call the child display renderer, and wait until they are done 00118 void cave_renderer(void) { 00119 cavescene->draw(cavedisplay); 00120 } 00121