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: G4OpenGLImmediateSceneHandler.cc,v 1.27 2007/04/04 16:50:26 allison Exp $ |
---|
28 | // GEANT4 tag $Name: $ |
---|
29 | // |
---|
30 | // |
---|
31 | // Andrew Walkden 10th February 1997 |
---|
32 | // OpenGL immediate scene - draws immediately to buffer |
---|
33 | // (saving space on server). |
---|
34 | |
---|
35 | #ifdef G4VIS_BUILD_OPENGL_DRIVER |
---|
36 | |
---|
37 | // Included here - problems with HP compiler if not before other includes? |
---|
38 | #include "G4NURBS.hh" |
---|
39 | |
---|
40 | // Here follows a special for Mesa, the OpenGL emulator. Does not affect |
---|
41 | // other OpenGL's, as far as I'm aware. John Allison 18/9/96. |
---|
42 | #define CENTERLINE_CLPP /* CenterLine C++ workaround: */ |
---|
43 | // Also seems to be required for HP's CC and AIX xlC, at least. |
---|
44 | |
---|
45 | #include "G4OpenGLImmediateSceneHandler.hh" |
---|
46 | |
---|
47 | #include "G4OpenGLTransform3D.hh" |
---|
48 | #include "G4Polyline.hh" |
---|
49 | #include "G4Polymarker.hh" |
---|
50 | #include "G4Text.hh" |
---|
51 | #include "G4Circle.hh" |
---|
52 | #include "G4Square.hh" |
---|
53 | #include "G4Scale.hh" |
---|
54 | #include "G4Polyhedron.hh" |
---|
55 | |
---|
56 | G4OpenGLImmediateSceneHandler::G4OpenGLImmediateSceneHandler |
---|
57 | (G4VGraphicsSystem& system,const G4String& name): |
---|
58 | G4OpenGLSceneHandler (system, fSceneIdCount++, name) |
---|
59 | {} |
---|
60 | |
---|
61 | G4OpenGLImmediateSceneHandler::~G4OpenGLImmediateSceneHandler () |
---|
62 | {} |
---|
63 | |
---|
64 | #include <iomanip> |
---|
65 | |
---|
66 | void G4OpenGLImmediateSceneHandler::AddPrimitivePreamble(const G4Visible& visible) |
---|
67 | { |
---|
68 | if (fpViewer->GetViewParameters().IsPicking()) { |
---|
69 | glLoadName(++fPickName); |
---|
70 | fPickMap[fPickName] = 0; |
---|
71 | } |
---|
72 | |
---|
73 | const G4Colour& c = GetColour (visible); |
---|
74 | glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ()); |
---|
75 | } |
---|
76 | |
---|
77 | void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Polyline& polyline) |
---|
78 | { |
---|
79 | AddPrimitivePreamble(polyline); |
---|
80 | G4OpenGLSceneHandler::AddPrimitive(polyline); |
---|
81 | } |
---|
82 | |
---|
83 | void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Polymarker& polymarker) |
---|
84 | { |
---|
85 | AddPrimitivePreamble(polymarker); |
---|
86 | G4OpenGLSceneHandler::AddPrimitive(polymarker); |
---|
87 | } |
---|
88 | |
---|
89 | void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Text& text) |
---|
90 | { |
---|
91 | // Note: colour is still handled in |
---|
92 | // G4OpenGLSceneHandler::AddPrimitive(const G4Text&). |
---|
93 | AddPrimitivePreamble(text); |
---|
94 | G4OpenGLSceneHandler::AddPrimitive(text); |
---|
95 | } |
---|
96 | |
---|
97 | void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Circle& circle) |
---|
98 | { |
---|
99 | AddPrimitivePreamble(circle); |
---|
100 | G4OpenGLSceneHandler::AddPrimitive(circle); |
---|
101 | } |
---|
102 | |
---|
103 | void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Square& square) |
---|
104 | { |
---|
105 | AddPrimitivePreamble(square); |
---|
106 | G4OpenGLSceneHandler::AddPrimitive(square); |
---|
107 | } |
---|
108 | |
---|
109 | void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Scale& scale) |
---|
110 | { |
---|
111 | AddPrimitivePreamble(scale); |
---|
112 | G4OpenGLSceneHandler::AddPrimitive(scale); |
---|
113 | } |
---|
114 | |
---|
115 | void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) |
---|
116 | { |
---|
117 | // Note: colour is still handled in |
---|
118 | // G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&). |
---|
119 | AddPrimitivePreamble(polyhedron); |
---|
120 | G4OpenGLSceneHandler::AddPrimitive(polyhedron); |
---|
121 | } |
---|
122 | |
---|
123 | void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4NURBS& nurbs) |
---|
124 | { |
---|
125 | // Note: colour is still handled in |
---|
126 | // G4OpenGLSceneHandler::AddPrimitive(const G4NURBS&). |
---|
127 | AddPrimitivePreamble(nurbs); |
---|
128 | G4OpenGLSceneHandler::AddPrimitive(nurbs); |
---|
129 | } |
---|
130 | |
---|
131 | void G4OpenGLImmediateSceneHandler::BeginPrimitives |
---|
132 | (const G4Transform3D& objectTransformation) { |
---|
133 | G4OpenGLSceneHandler::BeginPrimitives (objectTransformation); |
---|
134 | glPushMatrix(); |
---|
135 | G4OpenGLTransform3D oglt (objectTransformation); |
---|
136 | |
---|
137 | /*************************** Check matrix. |
---|
138 | const GLdouble* m = oglt.GetGLMatrix (); |
---|
139 | G4cout << "G4OpenGLTransform3D matrix:"; |
---|
140 | for (int i = 0; i < 16; i++) { |
---|
141 | if ((i % 4) == 0) G4cout << '\n'; |
---|
142 | G4cout << std::setw (15) << m[i]; |
---|
143 | } |
---|
144 | G4cout << G4endl; |
---|
145 | *****************************************/ |
---|
146 | |
---|
147 | glMultMatrixd (oglt.GetGLMatrix ()); |
---|
148 | } |
---|
149 | |
---|
150 | void G4OpenGLImmediateSceneHandler::EndPrimitives () |
---|
151 | { |
---|
152 | glPopMatrix(); |
---|
153 | |
---|
154 | // See all primitives immediately... |
---|
155 | glFlush (); |
---|
156 | |
---|
157 | G4OpenGLSceneHandler::EndPrimitives (); |
---|
158 | } |
---|
159 | |
---|
160 | void G4OpenGLImmediateSceneHandler::BeginPrimitives2D() |
---|
161 | { |
---|
162 | G4OpenGLSceneHandler::BeginPrimitives2D(); |
---|
163 | |
---|
164 | // Push current 3D world matrices and load identity to define screen |
---|
165 | // coordinates... |
---|
166 | glMatrixMode (GL_PROJECTION); |
---|
167 | glPushMatrix(); |
---|
168 | glLoadIdentity(); |
---|
169 | glOrtho (-1., 1., -1., 1., -G4OPENGL_DBL_MAX, G4OPENGL_DBL_MAX); |
---|
170 | glMatrixMode (GL_MODELVIEW); |
---|
171 | glPushMatrix(); |
---|
172 | glLoadIdentity(); |
---|
173 | } |
---|
174 | |
---|
175 | void G4OpenGLImmediateSceneHandler::EndPrimitives2D() |
---|
176 | { |
---|
177 | // Pop current 3D world matrices back again... |
---|
178 | glMatrixMode (GL_PROJECTION); |
---|
179 | glPopMatrix(); |
---|
180 | glMatrixMode (GL_MODELVIEW); |
---|
181 | glPopMatrix(); |
---|
182 | |
---|
183 | // See all primitives immediately... |
---|
184 | glFlush (); |
---|
185 | |
---|
186 | G4OpenGLSceneHandler::EndPrimitives2D (); |
---|
187 | } |
---|
188 | |
---|
189 | void G4OpenGLImmediateSceneHandler::BeginModeling () { |
---|
190 | G4VSceneHandler::BeginModeling(); |
---|
191 | } |
---|
192 | |
---|
193 | void G4OpenGLImmediateSceneHandler::EndModeling () { |
---|
194 | G4VSceneHandler::EndModeling (); |
---|
195 | } |
---|
196 | |
---|
197 | void G4OpenGLImmediateSceneHandler::ClearTransientStore () { |
---|
198 | |
---|
199 | G4VSceneHandler::ClearTransientStore (); |
---|
200 | |
---|
201 | // Make sure screen corresponds to graphical database... |
---|
202 | if (fpViewer) { |
---|
203 | fpViewer -> SetView (); |
---|
204 | fpViewer -> ClearView (); |
---|
205 | fpViewer -> DrawView (); |
---|
206 | } |
---|
207 | } |
---|
208 | |
---|
209 | void G4OpenGLImmediateSceneHandler::RequestPrimitives (const G4VSolid& solid) |
---|
210 | { |
---|
211 | if (fReadyForTransients) { |
---|
212 | // Always draw transient solids, e.g., hits represented as solids. |
---|
213 | // (As we have no control over the order of drawing of transient |
---|
214 | // objects, we cannot do anything about transparent ones, as |
---|
215 | // below, so always draw them.) |
---|
216 | G4VSceneHandler::RequestPrimitives (solid); |
---|
217 | return; |
---|
218 | } |
---|
219 | |
---|
220 | // For non-transient (run-duration) objects, ensure transparent |
---|
221 | // objects are drawn last. The problem of |
---|
222 | // blending/transparency/alpha is quite a tricky one - see History |
---|
223 | // of opengl-V07-01-01/2/3. |
---|
224 | // Get vis attributes - pick up defaults if none. |
---|
225 | const G4VisAttributes* pVA = |
---|
226 | fpViewer -> GetApplicableVisAttributes(fpVisAttribs); |
---|
227 | const G4Colour& c = pVA -> GetColour (); |
---|
228 | G4double opacity = c.GetAlpha (); |
---|
229 | |
---|
230 | if (!fSecondPass) { |
---|
231 | G4bool transparency_enabled = true; |
---|
232 | G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer); |
---|
233 | if (pViewer) transparency_enabled = pViewer->transparency_enabled; |
---|
234 | if (transparency_enabled && opacity < 1.) { |
---|
235 | // On first pass, transparent objects are not drawn, but flag is set... |
---|
236 | fSecondPassRequested = true; |
---|
237 | return; |
---|
238 | } |
---|
239 | } |
---|
240 | |
---|
241 | // On second pass, opaque objects are not drwan... |
---|
242 | if (fSecondPass && opacity >= 1.) return; |
---|
243 | |
---|
244 | // Else invoke base class method... |
---|
245 | G4VSceneHandler::RequestPrimitives (solid); |
---|
246 | } |
---|
247 | |
---|
248 | G4int G4OpenGLImmediateSceneHandler::fSceneIdCount = 0; |
---|
249 | |
---|
250 | #endif |
---|