Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: G4OpenGLXViewer.cc 103926 2017-05-03 13:43:27Z gcosmo $ 27 // 28 // 28 // 29 // 29 // Andrew Walkden 7th February 1997 30 // Andrew Walkden 7th February 1997 30 // G4OpenGLXViewer : Class to provide XWindows 31 // G4OpenGLXViewer : Class to provide XWindows specific 31 // functionality for OpenGL in 32 // functionality for OpenGL in GEANT4 32 33 >> 34 #ifdef G4VIS_BUILD_OPENGLX_DRIVER >> 35 33 #include "G4OpenGLXViewer.hh" 36 #include "G4OpenGLXViewer.hh" 34 37 35 #include "G4OpenGLSceneHandler.hh" 38 #include "G4OpenGLSceneHandler.hh" 36 #include "G4OpenGLFontBaseStore.hh" 39 #include "G4OpenGLFontBaseStore.hh" 37 40 38 #include "G4VisExtent.hh" 41 #include "G4VisExtent.hh" 39 #include "G4LogicalVolume.hh" 42 #include "G4LogicalVolume.hh" 40 #include "G4VSolid.hh" 43 #include "G4VSolid.hh" 41 #include "G4Point3D.hh" 44 #include "G4Point3D.hh" 42 #include "G4Normal3D.hh" 45 #include "G4Normal3D.hh" 43 #include "G4StateManager.hh" 46 #include "G4StateManager.hh" 44 #include "G4VisManager.hh" 47 #include "G4VisManager.hh" 45 #include "G4Text.hh" 48 #include "G4Text.hh" 46 #include "G4Threading.hh" 49 #include "G4Threading.hh" 47 50 48 #include <X11/Xatom.h> 51 #include <X11/Xatom.h> 49 #include <X11/Xutil.h> 52 #include <X11/Xutil.h> 50 #include <X11/Xmu/StdCmap.h> 53 #include <X11/Xmu/StdCmap.h> 51 54 52 #include <assert.h> 55 #include <assert.h> 53 #include <sstream> 56 #include <sstream> 54 #include <chrono> 57 #include <chrono> 55 #include <thread> 58 #include <thread> 56 59 57 int G4OpenGLXViewer::snglBuf_RGBA[12] = 60 int G4OpenGLXViewer::snglBuf_RGBA[12] = 58 { GLX_RGBA, 61 { GLX_RGBA, 59 GLX_RED_SIZE, 1, 62 GLX_RED_SIZE, 1, 60 GLX_GREEN_SIZE, 1, 63 GLX_GREEN_SIZE, 1, 61 GLX_BLUE_SIZE, 1, 64 GLX_BLUE_SIZE, 1, 62 GLX_DEPTH_SIZE, 1, 65 GLX_DEPTH_SIZE, 1, 63 GLX_STENCIL_SIZE, 1, 66 GLX_STENCIL_SIZE, 1, 64 None }; 67 None }; 65 68 66 int G4OpenGLXViewer::dblBuf_RGBA[13] = 69 int G4OpenGLXViewer::dblBuf_RGBA[13] = 67 { GLX_RGBA, 70 { GLX_RGBA, 68 GLX_RED_SIZE, 1, 71 GLX_RED_SIZE, 1, 69 GLX_GREEN_SIZE, 1, 72 GLX_GREEN_SIZE, 1, 70 GLX_BLUE_SIZE, 1, 73 GLX_BLUE_SIZE, 1, 71 GLX_DOUBLEBUFFER, 74 GLX_DOUBLEBUFFER, 72 GLX_DEPTH_SIZE, 1, 75 GLX_DEPTH_SIZE, 1, 73 GLX_STENCIL_SIZE, 1, 76 GLX_STENCIL_SIZE, 1, 74 None }; 77 None }; 75 78 76 #define NewString(str) \ 79 #define NewString(str) \ 77 ((str) != 0 ? (strncpy((char*)malloc((unsign 80 ((str) != 0 ? (strncpy((char*)malloc((unsigned)strlen(str) + 1), str, (unsigned)strlen(str) + 1)) : (char*)0) 78 81 79 #define USE_DEFAULT_COLORMAP 1 82 #define USE_DEFAULT_COLORMAP 1 80 #define USE_STANDARD_COLORMAP 0 83 #define USE_STANDARD_COLORMAP 0 81 84 82 XVisualInfo* G4OpenGLXViewer::vi_single_buffe 85 XVisualInfo* G4OpenGLXViewer::vi_single_buffer = 0; 83 XVisualInfo* G4OpenGLXViewer::vi_double_buffe 86 XVisualInfo* G4OpenGLXViewer::vi_double_buffer = 0; 84 87 85 extern "C" { 88 extern "C" { 86 static Bool G4OpenGLXViewerWaitForNotify (Di 89 static Bool G4OpenGLXViewerWaitForNotify (Display*, XEvent* e, char* arg) { 87 return (e->type == MapNotify) && (e->xmap. 90 return (e->type == MapNotify) && (e->xmap.window == (Window) arg); 88 } 91 } 89 } 92 } 90 93 91 void G4OpenGLXViewer::SetView () { 94 void G4OpenGLXViewer::SetView () { >> 95 #ifdef G4MULTITHREADED 92 if (G4Threading::IsMasterThread()) { 96 if (G4Threading::IsMasterThread()) { 93 glXMakeCurrent (dpy, win, cxMaster); 97 glXMakeCurrent (dpy, win, cxMaster); 94 } else { 98 } else { 95 glXMakeCurrent (dpy, win, cxVisSubThread); 99 glXMakeCurrent (dpy, win, cxVisSubThread); 96 } 100 } >> 101 #else >> 102 glXMakeCurrent (dpy, win, cxMaster); >> 103 #endif 97 G4OpenGLViewer::SetView (); 104 G4OpenGLViewer::SetView (); 98 } 105 } 99 106 100 void G4OpenGLXViewer::ShowView () { 107 void G4OpenGLXViewer::ShowView () { 101 // glXWaitGL (); //Wait for effects of all pr << 108 #ifdef G4MULTITHREADED >> 109 // G4int thread_id = G4Threading::G4GetThreadId(); >> 110 // G4cout << "G4OpenGLXViewer::ShowView: thread " << thread_id << G4endl; >> 111 #endif >> 112 glXWaitGL (); //Wait for effects of all previous OpenGL commands to 102 //be propagated before progres 113 //be propagated before progressing. 103 // JA: Commented out July 2021 - slows renderi << 104 // don't see any adverse effects. << 105 << 106 glFlush (); 114 glFlush (); 107 115 108 if (fVP.IsPicking()) { 116 if (fVP.IsPicking()) { 109 G4cout << 117 G4cout << 110 "Window activated for picking (left-mous 118 "Window activated for picking (left-mouse), exit (middle-mouse)." 111 << G4endl; 119 << G4endl; 112 while (true) { 120 while (true) { 113 if (XPending(dpy)) { 121 if (XPending(dpy)) { 114 XNextEvent(dpy, &event); 122 XNextEvent(dpy, &event); 115 if (event.type == ButtonPress && event.xbutt 123 if (event.type == ButtonPress && event.xbutton.button == 1) { 116 G4cout << Pick(event.xbutton.x, event.xbut 124 G4cout << Pick(event.xbutton.x, event.xbutton.y) << G4endl; 117 } 125 } 118 else if (event.type == ButtonPress && event. 126 else if (event.type == ButtonPress && event.xbutton.button == 2) break; 119 } 127 } 120 std::this_thread::sleep_for(std::chrono: 128 std::this_thread::sleep_for(std::chrono::milliseconds(100)); 121 } 129 } 122 } 130 } 123 } 131 } 124 132 >> 133 #ifdef G4MULTITHREADED >> 134 125 void G4OpenGLXViewer::SwitchToVisSubThread() 135 void G4OpenGLXViewer::SwitchToVisSubThread() 126 { 136 { 127 #ifdef G4MULTITHREADED << 137 // G4cout << "G4OpenGLXViewer::SwitchToVisSubThread" << G4endl; 128 cxVisSubThread = glXCreateContext (dpy, vi, 138 cxVisSubThread = glXCreateContext (dpy, vi, cxMaster, true); 129 glXMakeCurrent (dpy, win, cxVisSubThread); 139 glXMakeCurrent (dpy, win, cxVisSubThread); 130 #endif << 131 } 140 } 132 141 133 void G4OpenGLXViewer::SwitchToMasterThread() 142 void G4OpenGLXViewer::SwitchToMasterThread() 134 { 143 { 135 #ifdef G4MULTITHREADED << 144 // G4cout << "G4OpenGLXViewer::SwitchToMasterThread" << G4endl; 136 glXMakeCurrent (dpy, win, cxMaster); 145 glXMakeCurrent (dpy, win, cxMaster); 137 // and destroy sub-thread context 146 // and destroy sub-thread context 138 glXDestroyContext (dpy, cxVisSubThread); 147 glXDestroyContext (dpy, cxVisSubThread); 139 #endif << 140 } 148 } 141 149 >> 150 #endif >> 151 142 void G4OpenGLXViewer::GetXConnection () { 152 void G4OpenGLXViewer::GetXConnection () { 143 // get a connection. 153 // get a connection. 144 dpy = XOpenDisplay (0); // Uses DISPLAY env 154 dpy = XOpenDisplay (0); // Uses DISPLAY environment variable. 145 if (!dpy) { 155 if (!dpy) { 146 fViewId = -1; // This flags an error. 156 fViewId = -1; // This flags an error. 147 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe 157 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewer couldn't open display." << G4endl; 148 return; 158 return; 149 } 159 } 150 160 151 // make sure OpenGL is supported and installed 161 // make sure OpenGL is supported and installed properly. 152 if (!glXQueryExtension (dpy, &errorBase, &ev 162 if (!glXQueryExtension (dpy, &errorBase, &eventBase)) { 153 fViewId = -1; // This flags an error. 163 fViewId = -1; // This flags an error. 154 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe 164 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewer X Server has no GLX extension." 155 << G4endl; 165 << G4endl; 156 return; 166 return; 157 } 167 } 158 168 159 } 169 } 160 170 161 void G4OpenGLXViewer::CreateGLXContext (XVisua 171 void G4OpenGLXViewer::CreateGLXContext (XVisualInfo* v) { 162 172 163 vi = v; 173 vi = v; 164 // get window's attributes 174 // get window's attributes 165 if (!XGetWindowAttributes(dpy, XRootWindow ( 175 if (!XGetWindowAttributes(dpy, XRootWindow (dpy, vi -> screen), &xwa)) { 166 fViewId = -1; // This flags an error. 176 fViewId = -1; // This flags an error. 167 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe 177 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewer couldn't return window attributes" 168 << G4endl; 178 << G4endl; 169 return; 179 return; 170 } 180 } 171 181 172 // create the master GLX context 182 // create the master GLX context 173 cxMaster = glXCreateContext (dpy, vi, 0, tru 183 cxMaster = glXCreateContext (dpy, vi, 0, true); 174 if (!cxMaster) { 184 if (!cxMaster) { 175 fViewId = -1; // This flags an error. 185 fViewId = -1; // This flags an error. 176 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe 186 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewer couldn't create context." 177 << G4endl; 187 << G4endl; 178 return; 188 return; 179 } 189 } 180 190 181 // New stab at getting a colormap 191 // New stab at getting a colormap 182 192 183 Status status; 193 Status status; >> 194 XStandardColormap *standardCmaps = XAllocStandardColormap (); 184 int i, numCmaps; 195 int i, numCmaps; 185 196 186 status = XmuLookupStandardColormap (dpy, 197 status = XmuLookupStandardColormap (dpy, 187 vi -> screen, 198 vi -> screen, 188 vi -> visualid, 199 vi -> visualid, 189 vi -> depth, 200 vi -> depth, 190 XA_RGB_BEST_MAP, 201 XA_RGB_BEST_MAP, 191 False, 202 False, 192 True); 203 True); 193 204 194 if (status == 1) { 205 if (status == 1) { 195 cmap = 0; 206 cmap = 0; 196 XStandardColormap* standardCmaps = XAllocS << 197 status = XGetRGBColormaps (dpy, 207 status = XGetRGBColormaps (dpy, 198 XRootWindow (dpy, vi -> screen), 208 XRootWindow (dpy, vi -> screen), 199 &standardCmaps, 209 &standardCmaps, 200 &numCmaps, 210 &numCmaps, 201 XA_RGB_BEST_MAP); 211 XA_RGB_BEST_MAP); 202 if (status == 1) { << 212 if (status == 1) 203 for (i = 0; i < numCmaps; i++) { 213 for (i = 0; i < numCmaps; i++) { 204 if (standardCmaps[i].visualid == vi -> visua 214 if (standardCmaps[i].visualid == vi -> visualid) { 205 cmap = standardCmaps[i].colormap; 215 cmap = standardCmaps[i].colormap; >> 216 XFree (standardCmaps); 206 break; 217 break; 207 } 218 } 208 } 219 } >> 220 if (!cmap) { >> 221 fViewId = -1; // This flags an error. >> 222 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) >> 223 G4cerr << >> 224 "G4OpenGLXViewer::G4OpenGLXViewer failed to allocate a standard colormap." >> 225 << G4endl; >> 226 return; 209 } 227 } 210 XFree (standardCmaps); << 228 if (G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 211 if(cmap) { << 229 G4cout << "Got standard cmap" << G4endl; 212 if (G4VisManager::GetVerbosity() >= G4Vi << 213 G4cout << "Got standard cmap" << G4end << 214 } else { << 215 //if (G4VisManager::GetVerbosity() >= G4 << 216 // G4cerr << "G4OpenGLXViewer::G4OpenGL << 217 // << G4endl; << 218 cmap = XCreateColormap (dpy, << 219 XRootWindow(dpy, << 220 vi -> visual, << 221 AllocNone); << 222 if(cmap) { << 223 if (G4VisManager::GetVerbosity() >= G4 << 224 G4cout << "Created own cmap" << G4en << 225 } << 226 //G.Barrand : at end, we should do a XFr << 227 } << 228 } else { 230 } else { 229 cmap = XCreateColormap (dpy, 231 cmap = XCreateColormap (dpy, 230 XRootWindow(dpy, vi -> screen), 232 XRootWindow(dpy, vi -> screen), 231 vi -> visual, 233 vi -> visual, 232 AllocNone); 234 AllocNone); 233 if(cmap) { << 235 if (G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 234 if (G4VisManager::GetVerbosity() >= G4Vi << 236 G4cout << "Created own cmap" << G4endl; 235 G4cout << "Created own cmap" << G4endl << 236 } << 237 //G.Barrand : at end, we should do a XFree << 238 } 237 } 239 238 240 if (!cmap) { 239 if (!cmap) { 241 fViewId = -1; // This flags an error. 240 fViewId = -1; // This flags an error. 242 if (G4VisManager::GetVerbosity() >= G4VisM 241 if (G4VisManager::GetVerbosity() >= G4VisManager::errors) 243 G4cout << "G4OpenGLXViewer::G4OpenGLXVie 242 G4cout << "G4OpenGLXViewer::G4OpenGLXViewer failed to allocate a Colormap." 244 << G4endl; 243 << G4endl; 245 return; 244 return; 246 } 245 } 247 246 248 } 247 } 249 248 250 void G4OpenGLXViewer::CreateMainWindow () { 249 void G4OpenGLXViewer::CreateMainWindow () { 251 250 252 // create a window 251 // create a window 253 swa.colormap = cmap; 252 swa.colormap = cmap; 254 swa.border_pixel = 0; 253 swa.border_pixel = 0; 255 swa.event_mask = ExposureMask | ButtonPressM 254 swa.event_mask = ExposureMask | ButtonPressMask | StructureNotifyMask; 256 swa.backing_store = WhenMapped; 255 swa.backing_store = WhenMapped; 257 256 258 // Window size and position... 257 // Window size and position... 259 size_hints = XAllocSizeHints(); 258 size_hints = XAllocSizeHints(); 260 259 261 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.Ge 260 ResizeWindow(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY()); 262 261 263 G4int x_origin = fVP.GetWindowAbsoluteLocati 262 G4int x_origin = fVP.GetWindowAbsoluteLocationHintX(DisplayWidth(dpy, vi -> screen)); 264 263 265 // FIXME, screen size != window size on MAC 264 // FIXME, screen size != window size on MAC, but I don't know have to get the menuBar 266 // size on MAC. L.Garnier 01/2009 265 // size on MAC. L.Garnier 01/2009 267 G4int y_origin = fVP.GetWindowAbsoluteLocati 266 G4int y_origin = fVP.GetWindowAbsoluteLocationHintY(DisplayHeight(dpy, vi -> screen)); 268 267 269 size_hints->base_width = getWinWidth(); 268 size_hints->base_width = getWinWidth(); 270 size_hints->base_height = getWinHeight(); 269 size_hints->base_height = getWinHeight(); 271 size_hints->x = x_origin; 270 size_hints->x = x_origin; 272 size_hints->y = y_origin; 271 size_hints->y = y_origin; 273 if (fVP.IsWindowSizeHintX () && fVP.IsWindow 272 if (fVP.IsWindowSizeHintX () && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) { 274 size_hints->flags |= PSize | PPosition; 273 size_hints->flags |= PSize | PPosition; 275 } else if (fVP.IsWindowSizeHintX () && !(fVP 274 } else if (fVP.IsWindowSizeHintX () && !(fVP.IsWindowLocationHintX () || fVP.IsWindowLocationHintY ())) { 276 size_hints->flags |= PSize; 275 size_hints->flags |= PSize; 277 } else if ((!fVP.IsWindowSizeHintX ()) && fV 276 } else if ((!fVP.IsWindowSizeHintX ()) && fVP.IsWindowLocationHintX () && fVP.IsWindowLocationHintY ()) { 278 size_hints->flags |= PPosition; 277 size_hints->flags |= PPosition; 279 } 278 } 280 if (G4VisManager::GetVerbosity() >= G4VisMan 279 if (G4VisManager::GetVerbosity() >= G4VisManager::confirmations) 281 G4cout << "Window name: " << fName << G4en 280 G4cout << "Window name: " << fName << G4endl; 282 strncpy (charViewName, fName, 99); charViewN 281 strncpy (charViewName, fName, 99); charViewName[99] = '\0'; 283 char *window_name = charViewName; 282 char *window_name = charViewName; 284 char *icon_name = charViewName; 283 char *icon_name = charViewName; 285 //char tmpatom[] = "XA_WM_NORMAL_HINTS"; 284 //char tmpatom[] = "XA_WM_NORMAL_HINTS"; 286 wm_hints = XAllocWMHints(); 285 wm_hints = XAllocWMHints(); 287 class_hints = XAllocClassHint(); 286 class_hints = XAllocClassHint(); 288 287 289 XStringListToTextProperty (&window_name, 1, 288 XStringListToTextProperty (&window_name, 1, &windowName); 290 XStringListToTextProperty (&icon_name, 1, &i 289 XStringListToTextProperty (&icon_name, 1, &iconName); 291 290 292 wm_hints -> initial_state = NormalState; 291 wm_hints -> initial_state = NormalState; 293 wm_hints -> input = True; 292 wm_hints -> input = True; 294 wm_hints -> icon_pixmap = icon_pixmap; 293 wm_hints -> icon_pixmap = icon_pixmap; 295 wm_hints -> flags = StateHint | IconPixmapHi 294 wm_hints -> flags = StateHint | IconPixmapHint | InputHint; 296 295 297 class_hints -> res_name = NewString("G4Open 296 class_hints -> res_name = NewString("G4OpenGL"); 298 class_hints -> res_class = NewString("G4Open 297 class_hints -> res_class = NewString("G4OpenGL"); 299 298 300 win = XCreateWindow (dpy, XRootWindow (dpy, 299 win = XCreateWindow (dpy, XRootWindow (dpy, vi -> screen), x_origin, 301 y_origin, getWinWidth( 300 y_origin, getWinWidth(), getWinHeight(), 0, vi -> depth, 302 InputOutput, vi -> vis 301 InputOutput, vi -> visual, 303 CWBorderPixel | CWColo 302 CWBorderPixel | CWColormap | 304 CWEventMask | CWBackin 303 CWEventMask | CWBackingStore, 305 &swa); 304 &swa); 306 305 307 XSetWMProperties (dpy, win, &windowName, &i 306 XSetWMProperties (dpy, win, &windowName, &iconName, 0, 0, 308 size_hints, wm_hints, cla 307 size_hints, wm_hints, class_hints); 309 308 310 // request X to Draw window on screen. 309 // request X to Draw window on screen. 311 XMapWindow (dpy, win); 310 XMapWindow (dpy, win); 312 311 313 // Wait for window to appear (wait for an "exp 312 // Wait for window to appear (wait for an "expose" event). 314 XIfEvent (dpy, &event, G4OpenGLXViewerWaitFo 313 XIfEvent (dpy, &event, G4OpenGLXViewerWaitForNotify, (char*) win); 315 314 316 // connect the context to a window 315 // connect the context to a window 317 Bool success = glXMakeCurrent (dpy, win, cxM 316 Bool success = glXMakeCurrent (dpy, win, cxMaster); 318 if (!success) { 317 if (!success) { 319 fViewId = -1; // This flags an error. 318 fViewId = -1; // This flags an error. 320 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewe 319 G4cerr << "G4OpenGLXViewer::G4OpenGLXViewer failed to attach a GLX context." 321 << G4endl; 320 << G4endl; 322 GLint error = GL_NO_ERROR; 321 GLint error = GL_NO_ERROR; 323 while ((error = glGetError()) != GL_NO_ERR 322 while ((error = glGetError()) != GL_NO_ERROR) { 324 switch (error) { 323 switch (error) { 325 case GL_INVALID_ENUM : 324 case GL_INVALID_ENUM : 326 G4cout << "GL Error: GL_INVALID_ENUM" << G4e 325 G4cout << "GL Error: GL_INVALID_ENUM" << G4endl;break; 327 case GL_INVALID_VALUE : 326 case GL_INVALID_VALUE : 328 G4cout << "GL Error: GL_INVALID_VALUE" << G4 327 G4cout << "GL Error: GL_INVALID_VALUE" << G4endl;break; 329 case GL_INVALID_OPERATION : 328 case GL_INVALID_OPERATION : 330 G4cout << "GL Error: GL_INVALID_OPERATION" < 329 G4cout << "GL Error: GL_INVALID_OPERATION" << G4endl;break; 331 case GL_OUT_OF_MEMORY : 330 case GL_OUT_OF_MEMORY : 332 G4cout << "GL Error: GL_OUT_OF_MEMORY" << G4 331 G4cout << "GL Error: GL_OUT_OF_MEMORY" << G4endl;break; 333 case GL_STACK_UNDERFLOW : 332 case GL_STACK_UNDERFLOW : 334 G4cout << "GL Error: GL_STACK_UNDERFLOW" << 333 G4cout << "GL Error: GL_STACK_UNDERFLOW" << G4endl;break; 335 case GL_STACK_OVERFLOW : 334 case GL_STACK_OVERFLOW : 336 G4cout << "GL Error: GL_STACK_OVERFLOW" << G 335 G4cout << "GL Error: GL_STACK_OVERFLOW" << G4endl;break; 337 default : 336 default : 338 G4cout << "GL Error: " << error << G4endl;br 337 G4cout << "GL Error: " << error << G4endl;break; 339 } 338 } 340 } 339 } 341 return; 340 return; 342 } 341 } 343 } 342 } 344 343 345 void G4OpenGLXViewer::CreateFontLists() 344 void G4OpenGLXViewer::CreateFontLists() 346 { 345 { 347 std::map<G4double,G4String> fonts; // G4VMa 346 std::map<G4double,G4String> fonts; // G4VMarker screen size and font name. 348 fonts[10.] = "-adobe-courier-bold-r-normal-- 347 fonts[10.] = "-adobe-courier-bold-r-normal--10-100-75-75-m-60-iso8859-1"; 349 fonts[11.] = "-adobe-courier-bold-r-normal-- 348 fonts[11.] = "-adobe-courier-bold-r-normal--11-80-100-100-m-60-iso8859-1"; 350 fonts[12.] = "-adobe-courier-bold-r-normal-- 349 fonts[12.] = "-adobe-courier-bold-r-normal--12-120-75-75-m-70-iso8859-1"; 351 fonts[13.] = "fixed"; 350 fonts[13.] = "fixed"; 352 fonts[14.] = "-adobe-courier-bold-r-normal-- 351 fonts[14.] = "-adobe-courier-bold-r-normal--14-100-100-100-m-90-iso8859-1"; 353 fonts[17.] = "-adobe-courier-bold-r-normal-- 352 fonts[17.] = "-adobe-courier-bold-r-normal--17-120-100-100-m-100-iso8859-1"; 354 fonts[18.] = "-adobe-courier-bold-r-normal-- 353 fonts[18.] = "-adobe-courier-bold-r-normal--18-180-75-75-m-110-iso8859-1"; 355 fonts[20.] = "-adobe-courier-bold-r-normal-- 354 fonts[20.] = "-adobe-courier-bold-r-normal--20-140-100-100-m-110-iso8859-1"; 356 fonts[24.] = "-adobe-courier-bold-r-normal-- 355 fonts[24.] = "-adobe-courier-bold-r-normal--24-240-75-75-m-150-iso8859-1"; 357 fonts[25.] = "-adobe-courier-bold-r-normal-- 356 fonts[25.] = "-adobe-courier-bold-r-normal--25-180-100-100-m-150-iso8859-1"; 358 fonts[34.] = "-adobe-courier-bold-r-normal-- 357 fonts[34.] = "-adobe-courier-bold-r-normal--34-240-100-100-m-200-iso8859-1"; 359 std::map<G4double,G4String>::const_iterator 358 std::map<G4double,G4String>::const_iterator i; 360 for (i = fonts.begin(); i != fonts.end(); ++ 359 for (i = fonts.begin(); i != fonts.end(); ++i) { 361 XFontStruct* font_info = XLoadQueryFont(dp 360 XFontStruct* font_info = XLoadQueryFont(dpy, i->second); 362 if (!font_info) { 361 if (!font_info) { 363 G4cerr << 362 G4cerr << 364 "G4OpenGLXViewer::CreateFontLists XLoadQuery 363 "G4OpenGLXViewer::CreateFontLists XLoadQueryFont failed for font\n " 365 << i->second 364 << i->second 366 << G4endl; 365 << G4endl; 367 continue; 366 continue; 368 } 367 } 369 G4int font_base = glGenLists(256); 368 G4int font_base = glGenLists(256); 370 if (!font_base) { 369 if (!font_base) { 371 G4cerr << 370 G4cerr << 372 "G4OpenGLXViewer::CreateFontLists out of dis 371 "G4OpenGLXViewer::CreateFontLists out of display lists for fonts." 373 << G4endl; 372 << G4endl; 374 continue; 373 continue; 375 } 374 } 376 G4int first = font_info->min_char_or_byte2 375 G4int first = font_info->min_char_or_byte2; 377 G4int last = font_info->max_char_or_byte2 376 G4int last = font_info->max_char_or_byte2; 378 glXUseXFont(font_info->fid, first, last-fi 377 glXUseXFont(font_info->fid, first, last-first+1, font_base + first); 379 G4int width = font_info->max_bounds.width; 378 G4int width = font_info->max_bounds.width; 380 G4OpenGLFontBaseStore::AddFontBase 379 G4OpenGLFontBaseStore::AddFontBase 381 (this, font_base, i->first, i->second, w 380 (this, font_base, i->first, i->second, width); 382 } 381 } 383 } 382 } 384 383 385 void G4OpenGLXViewer::DrawText(const G4Text& g 384 void G4OpenGLXViewer::DrawText(const G4Text& g4text) 386 { 385 { 387 if (isGl2psWriting()) { 386 if (isGl2psWriting()) { 388 387 389 G4OpenGLViewer::DrawText(g4text); 388 G4OpenGLViewer::DrawText(g4text); 390 389 391 } else { 390 } else { 392 391 393 G4VSceneHandler::MarkerSizeType sizeType; 392 G4VSceneHandler::MarkerSizeType sizeType; 394 G4double size = fSceneHandler.GetMarkerSiz 393 G4double size = fSceneHandler.GetMarkerSize(g4text,sizeType); 395 394 396 const G4OpenGLFontBaseStore::FontInfo& fon 395 const G4OpenGLFontBaseStore::FontInfo& fontInfo = 397 G4OpenGLFontBaseStore::GetFontInfo(this, 396 G4OpenGLFontBaseStore::GetFontInfo(this,(int)size); 398 if (fontInfo.fFontBase < 0) { 397 if (fontInfo.fFontBase < 0) { 399 static G4int callCount = 0; 398 static G4int callCount = 0; 400 ++callCount; 399 ++callCount; 401 //if (callCount <= 10 || callCount%100 = 400 //if (callCount <= 10 || callCount%100 == 0) { 402 if (callCount <= 1) { 401 if (callCount <= 1) { 403 G4cout << 402 G4cout << 404 "G4OpenGLXViewer::DrawText: No fonts avail 403 "G4OpenGLXViewer::DrawText: No fonts available for \"" 405 << fName << 404 << fName << 406 "\"\n Called with " 405 "\"\n Called with " 407 << g4text 406 << g4text 408 << G4endl; 407 << G4endl; 409 } 408 } 410 return; 409 return; 411 } 410 } 412 411 413 const G4Colour& c = fSceneHandler.GetTextC 412 const G4Colour& c = fSceneHandler.GetTextColour(g4text); 414 glColor4d(c.GetRed(),c.GetGreen(),c.GetBlu 413 glColor4d(c.GetRed(),c.GetGreen(),c.GetBlue(),c.GetAlpha()); 415 414 416 G4Point3D position = g4text.GetPosition(); 415 G4Point3D position = g4text.GetPosition(); 417 416 418 G4String textString = g4text.GetText(); 417 G4String textString = g4text.GetText(); 419 const char* textCString = textString.c_str 418 const char* textCString = textString.c_str(); 420 419 421 // Set position for raster-style drawers ( 420 // Set position for raster-style drawers (X, Xm) 422 glRasterPos3d(position.x(),position.y(),po 421 glRasterPos3d(position.x(),position.y(),position.z()); 423 422 424 glPushAttrib(GL_LIST_BIT); 423 glPushAttrib(GL_LIST_BIT); 425 424 426 // Calculate move for centre and right adj 425 // Calculate move for centre and right adjustment 427 G4double span = textString.size() * fontIn 426 G4double span = textString.size() * fontInfo.fWidth; 428 G4double xmove = 0., ymove = 0.; 427 G4double xmove = 0., ymove = 0.; 429 switch (g4text.GetLayout()) { 428 switch (g4text.GetLayout()) { 430 case G4Text::left: break; 429 case G4Text::left: break; 431 case G4Text::centre: xmove -= span / 2.; b 430 case G4Text::centre: xmove -= span / 2.; break; 432 case G4Text::right: xmove -= span; 431 case G4Text::right: xmove -= span; 433 } 432 } 434 433 435 //Add offsets 434 //Add offsets 436 xmove += g4text.GetXOffset(); 435 xmove += g4text.GetXOffset(); 437 ymove += g4text.GetYOffset(); 436 ymove += g4text.GetYOffset(); 438 437 439 // Do move 438 // Do move 440 glBitmap(0,0,0,0,xmove,ymove,0); 439 glBitmap(0,0,0,0,xmove,ymove,0); 441 440 442 // Write characters 441 // Write characters 443 glListBase(fontInfo.fFontBase); 442 glListBase(fontInfo.fFontBase); 444 glCallLists((G4int)strlen(textCString),GL_ << 443 glCallLists(strlen(textCString),GL_UNSIGNED_BYTE,(GLubyte*)textCString); 445 glPopAttrib(); 444 glPopAttrib(); 446 } 445 } 447 } 446 } 448 447 449 448 450 G4OpenGLXViewer::G4OpenGLXViewer (G4OpenGLScen 449 G4OpenGLXViewer::G4OpenGLXViewer (G4OpenGLSceneHandler& scene): 451 G4VViewer (scene, -1), 450 G4VViewer (scene, -1), 452 G4OpenGLViewer (scene), 451 G4OpenGLViewer (scene), 453 vi_immediate (0), 452 vi_immediate (0), 454 vi_stored (0), 453 vi_stored (0), 455 vi (0), 454 vi (0), 456 cmap (0) 455 cmap (0) 457 { 456 { 458 // To satisfy Coverity 457 // To satisfy Coverity 459 xwa.visual = 0; 458 xwa.visual = 0; 460 iconName.value = 0; 459 iconName.value = 0; 461 xwa.screen = 0; 460 xwa.screen = 0; 462 windowName.value = 0; 461 windowName.value = 0; 463 462 464 GetXConnection (); 463 GetXConnection (); 465 if (fViewId < 0) return; 464 if (fViewId < 0) return; 466 465 467 // Try for a visual suitable for OpenGLImmed 466 // Try for a visual suitable for OpenGLImmediate.. 468 // first try for a single buffered RGB windo 467 // first try for a single buffered RGB window 469 if (!vi_single_buffer) { 468 if (!vi_single_buffer) { 470 vi_single_buffer = 469 vi_single_buffer = 471 glXChooseVisual (dpy, XDefaultScreen (dp 470 glXChooseVisual (dpy, XDefaultScreen (dpy), snglBuf_RGBA); 472 //G.Barrand : we should do a XFree(vi_sing << 473 } 471 } 474 if (!vi_double_buffer) { 472 if (!vi_double_buffer) { 475 vi_double_buffer = 473 vi_double_buffer = 476 glXChooseVisual (dpy, XDefaultScreen (dp 474 glXChooseVisual (dpy, XDefaultScreen (dpy), dblBuf_RGBA); 477 //G.Barrand : we should do a XFree(vi_doub << 478 } 475 } 479 476 480 if (vi_single_buffer || vi_double_buffer) { 477 if (vi_single_buffer || vi_double_buffer) { 481 if (!vi_double_buffer) { 478 if (!vi_double_buffer) { 482 G4cout << 479 G4cout << 483 "G4OpenGLXViewer::G4OpenGLXViewer: unable to 480 "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a double buffer visual." 484 "\n Working with a single buffer." 481 "\n Working with a single buffer." 485 << G4endl; 482 << G4endl; 486 } 483 } 487 } else { 484 } else { 488 if (!vi_single_buffer) { 485 if (!vi_single_buffer) { 489 G4cout << 486 G4cout << 490 "G4OpenGLXViewer::G4OpenGLXViewer: unable to 487 "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a single buffer visual." 491 << G4endl; 488 << G4endl; 492 } 489 } 493 if (!vi_double_buffer) { 490 if (!vi_double_buffer) { 494 G4cout << 491 G4cout << 495 "G4OpenGLXViewer::G4OpenGLXViewer: unable to 492 "G4OpenGLXViewer::G4OpenGLXViewer: unable to get a double buffer visual." 496 << G4endl; 493 << G4endl; 497 } 494 } 498 } 495 } 499 496 500 if (vi_single_buffer) { 497 if (vi_single_buffer) { 501 vi_immediate = vi_single_buffer; 498 vi_immediate = vi_single_buffer; 502 attributeList = snglBuf_RGBA; 499 attributeList = snglBuf_RGBA; 503 } 500 } 504 501 505 if (!vi_immediate){ 502 if (!vi_immediate){ 506 // next try for a double buffered RGB, but 503 // next try for a double buffered RGB, but Draw to top buffer 507 if (vi_double_buffer) { 504 if (vi_double_buffer) { 508 vi_immediate = vi_double_buffer; 505 vi_immediate = vi_double_buffer; 509 attributeList = dblBuf_RGBA; 506 attributeList = dblBuf_RGBA; 510 } 507 } 511 } 508 } 512 509 513 // Now try for a visual suitable for OpenGLS 510 // Now try for a visual suitable for OpenGLStored... 514 // Try for a double buffered RGB window 511 // Try for a double buffered RGB window 515 if (vi_double_buffer) { 512 if (vi_double_buffer) { 516 vi_stored = vi_double_buffer; 513 vi_stored = vi_double_buffer; 517 attributeList = dblBuf_RGBA; 514 attributeList = dblBuf_RGBA; 518 } 515 } 519 516 520 if (!vi_immediate || !vi_stored) { 517 if (!vi_immediate || !vi_stored) { 521 G4cout << 518 G4cout << 522 "G4OpenGLXViewer::G4OpenGLXViewer: unable 519 "G4OpenGLXViewer::G4OpenGLXViewer: unable to get required visuals." 523 << G4endl; 520 << G4endl; 524 fViewId = -1; // This flags an error. 521 fViewId = -1; // This flags an error. 525 } 522 } 526 523 527 // glClearColor (0., 0., 0., 0.); 524 // glClearColor (0., 0., 0., 0.); 528 // glClearDepth (1.); 525 // glClearDepth (1.); 529 } 526 } 530 527 531 G4OpenGLXViewer::~G4OpenGLXViewer () { 528 G4OpenGLXViewer::~G4OpenGLXViewer () { 532 if (fViewId >= 0) { 529 if (fViewId >= 0) { 533 //Close a window from here 530 //Close a window from here 534 glXMakeCurrent (dpy, None, NULL); 531 glXMakeCurrent (dpy, None, NULL); 535 glXDestroyContext (dpy, cxMaster); 532 glXDestroyContext (dpy, cxMaster); 536 if (win) XDestroyWindow (dpy, win); // ... 533 if (win) XDestroyWindow (dpy, win); // ...if already deleted in 537 // sub-class G4OpenGLXmViewer. 534 // sub-class G4OpenGLXmViewer. 538 // We should do a XFreeColormap(dpy,cmap); << 539 XFlush (dpy); 535 XFlush (dpy); 540 } 536 } 541 } 537 } 542 538 >> 539 >> 540 #endif 543 541