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,v 1.25 2009/04/08 16:55:44 lgarnier Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // |
---|
31 | // Andrew Walkden 7th February 1997 |
---|
32 | // Class G4OpenGLStoredXViewer : a class derived from G4OpenGLXViewer and |
---|
33 | // G4OpenGLStoredViewer. |
---|
34 | |
---|
35 | #ifdef G4VIS_BUILD_OPENGLX_DRIVER |
---|
36 | |
---|
37 | #include "G4OpenGLStoredXViewer.hh" |
---|
38 | |
---|
39 | #include "G4ios.hh" |
---|
40 | |
---|
41 | G4OpenGLStoredXViewer:: |
---|
42 | G4OpenGLStoredXViewer (G4OpenGLStoredSceneHandler& sceneHandler, |
---|
43 | const G4String& name) |
---|
44 | : G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name), |
---|
45 | G4OpenGLViewer (sceneHandler), |
---|
46 | G4OpenGLXViewer (sceneHandler), |
---|
47 | G4OpenGLStoredViewer (sceneHandler) |
---|
48 | { |
---|
49 | if (fViewId < 0) return; // In case error in base class instantiation. |
---|
50 | |
---|
51 | if (!vi_stored) { |
---|
52 | fViewId = -1; // This flags an error. |
---|
53 | G4cerr << "G4OpenGLStoredXViewer::G4OpenGLStoredXViewer -" |
---|
54 | " G4OpenGLXViewer couldn't get a visual." << G4endl; |
---|
55 | return; |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | G4OpenGLStoredXViewer::~G4OpenGLStoredXViewer () {} |
---|
60 | |
---|
61 | void G4OpenGLStoredXViewer::Initialise () { |
---|
62 | |
---|
63 | #ifdef G4DEBUG_VIS_OGL |
---|
64 | printf("G4OpenGLStoredXViewer::Initialise\n"); |
---|
65 | #endif |
---|
66 | CreateGLXContext (vi_stored); |
---|
67 | CreateMainWindow (); |
---|
68 | CreateFontLists (); |
---|
69 | |
---|
70 | InitializeGLView (); |
---|
71 | |
---|
72 | // clear the buffers and window. |
---|
73 | ClearView (); |
---|
74 | FinishView (); |
---|
75 | |
---|
76 | glDepthFunc (GL_LEQUAL); |
---|
77 | glDepthMask (GL_TRUE); |
---|
78 | } |
---|
79 | |
---|
80 | void G4OpenGLStoredXViewer::DrawView () { |
---|
81 | |
---|
82 | #ifdef G4DEBUG_VIS_OGL |
---|
83 | printf("G4OpenGLStoredXViewer::DrawView\n"); |
---|
84 | #endif |
---|
85 | //Make sure current viewer is attached and clean... |
---|
86 | glXMakeCurrent (dpy, win, cx); |
---|
87 | |
---|
88 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); |
---|
89 | |
---|
90 | //See if things have changed from last time and remake if necessary... |
---|
91 | // The fNeedKernelVisit flag might have been set by the user in |
---|
92 | // /vis/viewer/rebuild, but if not, make decision and set flag only |
---|
93 | // if necessary... |
---|
94 | if (!fNeedKernelVisit) KernelVisitDecision (); |
---|
95 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets). |
---|
96 | ProcessView (); |
---|
97 | |
---|
98 | if(style!=G4ViewParameters::hlr && |
---|
99 | haloing_enabled) { |
---|
100 | |
---|
101 | HaloingFirstPass (); |
---|
102 | DrawDisplayLists (); |
---|
103 | #ifdef G4DEBUG_VIS_OGL |
---|
104 | printf("G4OpenGLStoredXViewer::DrawView flush \n"); |
---|
105 | #endif |
---|
106 | glFlush (); |
---|
107 | |
---|
108 | HaloingSecondPass (); |
---|
109 | |
---|
110 | DrawDisplayLists (); |
---|
111 | FinishView (); |
---|
112 | |
---|
113 | } else { |
---|
114 | |
---|
115 | // If kernel visit was needed, drawing and FinishView will already |
---|
116 | // have been done, so... |
---|
117 | if (!kernelVisitWasNeeded) { |
---|
118 | #ifdef G4DEBUG_VIS_OGL |
---|
119 | printf("G4OpenGLStoredXViewer::DrawView NO need kernel visit\n"); |
---|
120 | #endif |
---|
121 | DrawDisplayLists (); |
---|
122 | FinishView (); |
---|
123 | } else { |
---|
124 | #ifdef G4DEBUG_VIS_OGL |
---|
125 | printf("G4OpenGLStoredXViewer::DrawView NEED kernel visit\n"); |
---|
126 | #endif |
---|
127 | // However, union cutaways are implemented in DrawDisplayLists, so make |
---|
128 | // an extra pass... |
---|
129 | if (fVP.IsCutaway() && |
---|
130 | fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) { |
---|
131 | ClearView(); |
---|
132 | DrawDisplayLists (); |
---|
133 | FinishView (); |
---|
134 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display |
---|
135 | DrawDisplayLists (); |
---|
136 | FinishView (); |
---|
137 | } |
---|
138 | } |
---|
139 | } |
---|
140 | } |
---|
141 | |
---|
142 | void G4OpenGLStoredXViewer::FinishView () { |
---|
143 | #ifdef G4DEBUG_VIS_OGL |
---|
144 | printf("G4OpenGLStoredXViewer::FinishView\n"); |
---|
145 | #endif |
---|
146 | glXWaitGL (); //Wait for effects of all previous OpenGL commands to |
---|
147 | //be propogated before progressing. |
---|
148 | |
---|
149 | #ifdef G4DEBUG_VIS_OGL |
---|
150 | printf("G4OpenGLStoredXViewer::FinishView flush \n"); |
---|
151 | #endif |
---|
152 | glFlush (); //FIXME |
---|
153 | |
---|
154 | GLint renderMode; |
---|
155 | glGetIntegerv(GL_RENDER_MODE, &renderMode); |
---|
156 | if (renderMode == GL_RENDER) glXSwapBuffers (dpy, win); |
---|
157 | } |
---|
158 | |
---|
159 | #endif |
---|