Geant4  10.02.p01
G4OpenGLStoredXViewer.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4OpenGLStoredXViewer.cc 87695 2014-12-17 09:35:24Z gcosmo $
28 //
29 //
30 // Andrew Walkden 7th February 1997
31 // Class G4OpenGLStoredXViewer : a class derived from G4OpenGLXViewer and
32 // G4OpenGLStoredViewer.
33 
34 #ifdef G4VIS_BUILD_OPENGLX_DRIVER
35 
36 #include "G4OpenGLStoredXViewer.hh"
37 
39 #include "G4ios.hh"
40 #include "G4Threading.hh"
41 
42 G4OpenGLStoredXViewer::
43 G4OpenGLStoredXViewer (G4OpenGLStoredSceneHandler& sceneHandler,
44  const G4String& name)
45  : G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
46  G4OpenGLViewer (sceneHandler),
47  G4OpenGLXViewer (sceneHandler),
48  G4OpenGLStoredViewer (sceneHandler)
49 {
50  if (fViewId < 0) return; // In case error in base class instantiation.
51 
52  if (!vi_stored) {
53  fViewId = -1; // This flags an error.
54  G4cerr << "G4OpenGLStoredXViewer::G4OpenGLStoredXViewer -"
55  " G4OpenGLXViewer couldn't get a visual." << G4endl;
56  return;
57  }
58 }
59 
60 G4OpenGLStoredXViewer::~G4OpenGLStoredXViewer () {}
61 
62 void G4OpenGLStoredXViewer::Initialise () {
63 
64 #ifdef G4DEBUG_VIS_OGL
65  printf("G4OpenGLStoredXViewer::Initialise\n");
66 #endif
67  CreateGLXContext (vi_stored);
68  CreateMainWindow ();
69  CreateFontLists ();
70 
71  InitializeGLView ();
72 
73  glDrawBuffer (GL_BACK);
74 }
75 
76 void G4OpenGLStoredXViewer::DrawView () {
77 
78 #ifdef G4DEBUG_VIS_OGL
79  printf("G4OpenGLStoredXViewer::DrawView\n");
80 #endif
81 // //Make sure current viewer is attached and clean...
82 //#ifdef G4MULTITHREADED
83 // G4int thread_id = G4Threading::G4GetThreadId();
84 // G4cout << "G4OpenGLStoredXViewer::DrawView: thread " << thread_id << G4endl;
85 // if (thread_id < 0) {
86 // glXMakeCurrent (dpy, win, cxMaster);
87 // } else {
88 // glXMakeCurrent (dpy, win, cxVisSubThread);
89 // }
90 //#else
91 // glXMakeCurrent (dpy, win, cxMaster);
92 //#endif
93 
94  G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
95 
96  // See if things have changed from last time and remake if necessary...
97  // The fNeedKernelVisit flag might have been set by the user in
98  // /vis/viewer/rebuild, but if not, make decision and set flag only
99  // if necessary...
100  if (!fNeedKernelVisit) KernelVisitDecision ();
101  G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
102  ProcessView ();
103 
104  if(style!=G4ViewParameters::hlr && haloing_enabled) {
105 
106  HaloingFirstPass ();
107  DrawDisplayLists ();
108 #ifdef G4DEBUG_VIS_OGL
109  printf("G4OpenGLStoredXViewer::DrawView flush \n");
110 #endif
111  glFlush ();
112 
113  HaloingSecondPass ();
114 
115  DrawDisplayLists ();
116 
117  } else {
118 
119  if (!kernelVisitWasNeeded) {
120 #ifdef G4DEBUG_VIS_OGL
121  printf("G4OpenGLStoredXViewer::DrawView NO need kernel visit\n");
122 #endif
123  DrawDisplayLists ();
124 
125  } else {
126 
127 #ifdef G4DEBUG_VIS_OGL
128  printf("G4OpenGLStoredXViewer::DrawView NEED kernel visit\n");
129 #endif
130  // However, union cutaways are implemented in DrawDisplayLists, so make
131  // an extra pass...
132  if (fVP.IsCutaway() &&
133  fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
134  ClearView();
135  DrawDisplayLists ();
136  } else { // ADD TO AVOID KernelVisit=1 and nothing to display
137  DrawDisplayLists ();
138  }
139  }
140  }
141 
142  FinishView ();
143 
144 }
145 
146 void G4OpenGLStoredXViewer::FinishView () {
147 #ifdef G4DEBUG_VIS_OGL
148  printf("G4OpenGLStoredXViewer::FinishView\n");
149 #endif
150  glXWaitGL (); //Wait for effects of all previous OpenGL commands to
151  //be propogated before progressing.
152 
153 #ifdef G4DEBUG_VIS_OGL
154  printf("G4OpenGLStoredXViewer::FinishView flush \n");
155 #endif
156  glFlush (); //FIXME
157 
158  GLint renderMode;
159  glGetIntegerv(GL_RENDER_MODE, &renderMode);
160  if (renderMode == GL_RENDER) glXSwapBuffers (dpy, win);
161 }
162 
163 #endif
G4String name
Definition: TRTMaterials.hh:40
bool G4bool
Definition: G4Types.hh:79
#define G4endl
Definition: G4ios.hh:61
G4GLOB_DLL std::ostream G4cerr