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: G4OpenGLStoredXmViewer.cc,v 1.26 2010/04/30 13:18:32 lgarnier Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
29 | // |
---|
30 | // |
---|
31 | // Andrew Walkden 10th February 1997 |
---|
32 | // Class G4OpenGLStoredXmViewer : a class derived from G4OpenGLXmViewer |
---|
33 | // and G4OpenGLStoredViewer. |
---|
34 | |
---|
35 | #ifdef G4VIS_BUILD_OPENGLXM_DRIVER |
---|
36 | |
---|
37 | #include "G4OpenGLStoredXmViewer.hh" |
---|
38 | |
---|
39 | #include "G4ios.hh" |
---|
40 | |
---|
41 | G4OpenGLStoredXmViewer:: |
---|
42 | G4OpenGLStoredXmViewer (G4OpenGLStoredSceneHandler& sceneHandler, |
---|
43 | const G4String& name) |
---|
44 | : G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name), |
---|
45 | G4OpenGLViewer (sceneHandler), |
---|
46 | G4OpenGLXmViewer (sceneHandler), |
---|
47 | G4OpenGLStoredViewer (sceneHandler) |
---|
48 | { |
---|
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 << "G4OpenGLStoredXmViewer::G4OpenGLStoredXmViewer -" |
---|
55 | " G4OpenGLXmViewer couldn't get a visual." << G4endl; |
---|
56 | return; |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | G4OpenGLStoredXmViewer::~G4OpenGLStoredXmViewer () { |
---|
61 | GetSceneHandler()->RemoveViewerFromList(this); |
---|
62 | } |
---|
63 | |
---|
64 | void G4OpenGLStoredXmViewer::Initialise () { |
---|
65 | |
---|
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 | glEnable (GL_BLEND); |
---|
80 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
---|
81 | |
---|
82 | glDrawBuffer (GL_BACK); |
---|
83 | } |
---|
84 | |
---|
85 | void G4OpenGLStoredXmViewer::DrawView () { |
---|
86 | #ifdef G4DEBUG_VIS_OGL |
---|
87 | printf("G4OpenGLStoredXmViewer::DrawView \n"); |
---|
88 | #endif |
---|
89 | |
---|
90 | //Make sure current viewer is attached and clean... |
---|
91 | glXMakeCurrent (dpy, win, cx); |
---|
92 | |
---|
93 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); |
---|
94 | |
---|
95 | //See if things have changed from last time and remake if necessary... |
---|
96 | // /vis/viewer/rebuild, but if not, make decision and set flag only |
---|
97 | // if necessary... |
---|
98 | if (!fNeedKernelVisit) KernelVisitDecision (); |
---|
99 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets). |
---|
100 | ProcessView (); |
---|
101 | |
---|
102 | if(style!=G4ViewParameters::hlr && |
---|
103 | haloing_enabled) { |
---|
104 | |
---|
105 | HaloingFirstPass (); |
---|
106 | DrawDisplayLists (); |
---|
107 | #ifdef G4DEBUG_VIS_OGL |
---|
108 | printf("G4OpenGLStoredXmViewer::DrawView () flush\n"); |
---|
109 | #endif |
---|
110 | glFlush (); |
---|
111 | |
---|
112 | HaloingSecondPass (); |
---|
113 | |
---|
114 | DrawDisplayLists (); |
---|
115 | FinishView (); |
---|
116 | |
---|
117 | } else { |
---|
118 | |
---|
119 | #ifdef G4DEBUG_VIS_OGL |
---|
120 | printf("G4OpenGLStoredXmViewer::DrawView not hlr \n"); |
---|
121 | #endif |
---|
122 | // If kernel visit was needed, drawing and FinishView will already |
---|
123 | // have been done, so... |
---|
124 | if (!kernelVisitWasNeeded) { |
---|
125 | #ifdef G4DEBUG_VIS_OGL |
---|
126 | printf("G4OpenGLStoredXmViewer::ComputeView Don't need kernel Visit \n"); |
---|
127 | #endif |
---|
128 | DrawDisplayLists (); |
---|
129 | FinishView (); |
---|
130 | } else { |
---|
131 | #ifdef G4DEBUG_VIS_OGL |
---|
132 | printf("G4OpenGLStoredXmViewer::ComputeView Need kernel Visit \n"); |
---|
133 | #endif |
---|
134 | // However, union cutaways are implemented in DrawDisplayLists, so make |
---|
135 | // an extra pass... |
---|
136 | if (fVP.IsCutaway() && |
---|
137 | fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) { |
---|
138 | ClearView(); |
---|
139 | DrawDisplayLists (); |
---|
140 | FinishView (); |
---|
141 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display |
---|
142 | DrawDisplayLists (); |
---|
143 | FinishView (); |
---|
144 | } |
---|
145 | } |
---|
146 | } |
---|
147 | #ifdef G4DEBUG_VIS_OGL |
---|
148 | printf("G4OpenGLStoredXmViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n"); |
---|
149 | #endif |
---|
150 | } |
---|
151 | |
---|
152 | void G4OpenGLStoredXmViewer::FinishView () { |
---|
153 | glXWaitGL (); //Wait for effects of all previous OpenGL commands to |
---|
154 | //be propogated before progressing. |
---|
155 | |
---|
156 | #ifdef G4DEBUG_VIS_OGL |
---|
157 | printf("G4OpenGLStoredXmViewer::FinishView () flush \n"); |
---|
158 | #endif |
---|
159 | glFlush (); //FIXME |
---|
160 | |
---|
161 | GLint renderMode; |
---|
162 | glGetIntegerv(GL_RENDER_MODE, &renderMode); |
---|
163 | if (renderMode == GL_RENDER) glXSwapBuffers (dpy, win); |
---|
164 | } |
---|
165 | |
---|
166 | #endif |
---|