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