| 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.31 2009/02/04 16:48:41 lgarnier 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 "G4OpenGLViewer.hh"
|
|---|
| 48 | #include "G4OpenGLTransform3D.hh"
|
|---|
| 49 | #include "G4Polyline.hh"
|
|---|
| 50 | #include "G4Polymarker.hh"
|
|---|
| 51 | #include "G4Text.hh"
|
|---|
| 52 | #include "G4Circle.hh"
|
|---|
| 53 | #include "G4Square.hh"
|
|---|
| 54 | #include "G4Scale.hh"
|
|---|
| 55 | #include "G4Polyhedron.hh"
|
|---|
| 56 |
|
|---|
| 57 | G4OpenGLImmediateSceneHandler::G4OpenGLImmediateSceneHandler
|
|---|
| 58 | (G4VGraphicsSystem& system,const G4String& name):
|
|---|
| 59 | G4OpenGLSceneHandler (system, fSceneIdCount++, name)
|
|---|
| 60 | {}
|
|---|
| 61 |
|
|---|
| 62 | G4OpenGLImmediateSceneHandler::~G4OpenGLImmediateSceneHandler ()
|
|---|
| 63 | {}
|
|---|
| 64 |
|
|---|
| 65 | #include <iomanip>
|
|---|
| 66 |
|
|---|
| 67 | void G4OpenGLImmediateSceneHandler::AddPrimitivePreamble(const G4Visible& visible)
|
|---|
| 68 | {
|
|---|
| 69 | if (fpViewer->GetViewParameters().IsPicking()) {
|
|---|
| 70 | glLoadName(++fPickName);
|
|---|
| 71 | fPickMap[fPickName] = 0;
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 132 | void G4OpenGLImmediateSceneHandler::BeginPrimitives
|
|---|
| 133 | (const G4Transform3D& objectTransformation)
|
|---|
| 134 | {
|
|---|
| 135 | G4OpenGLSceneHandler::BeginPrimitives (objectTransformation);
|
|---|
| 136 |
|
|---|
| 137 | G4OpenGLTransform3D oglt (objectTransformation);
|
|---|
| 138 |
|
|---|
| 139 | glPushMatrix();
|
|---|
| 140 |
|
|---|
| 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...
|
|---|
| 159 | glFlush ();
|
|---|
| 160 |
|
|---|
| 161 | G4OpenGLSceneHandler::EndPrimitives ();
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | void G4OpenGLImmediateSceneHandler::BeginPrimitives2D
|
|---|
| 165 | (const G4Transform3D& objectTransformation)
|
|---|
| 166 | {
|
|---|
| 167 | G4OpenGLSceneHandler::BeginPrimitives2D(objectTransformation);
|
|---|
| 168 |
|
|---|
| 169 | // Push current 3D world matrices and load identity to define screen
|
|---|
| 170 | // coordinates...
|
|---|
| 171 | glMatrixMode (GL_PROJECTION);
|
|---|
| 172 | glPushMatrix();
|
|---|
| 173 | glLoadIdentity();
|
|---|
| 174 | glOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
|
|---|
| 175 | glMatrixMode (GL_MODELVIEW);
|
|---|
| 176 | glPushMatrix();
|
|---|
| 177 | glLoadIdentity();
|
|---|
| 178 | G4OpenGLTransform3D oglt (objectTransformation);
|
|---|
| 179 | glMultMatrixd (oglt.GetGLMatrix ());
|
|---|
| 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 |
|
|---|
| 193 | G4OpenGLSceneHandler::EndPrimitives2D ();
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | void G4OpenGLImmediateSceneHandler::BeginModeling () {
|
|---|
| 197 | G4VSceneHandler::BeginModeling();
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | void G4OpenGLImmediateSceneHandler::EndModeling () {
|
|---|
| 201 | G4VSceneHandler::EndModeling ();
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 | void G4OpenGLImmediateSceneHandler::ClearTransientStore () {
|
|---|
| 205 |
|
|---|
| 206 | G4VSceneHandler::ClearTransientStore ();
|
|---|
| 207 |
|
|---|
| 208 | // Make sure screen corresponds to graphical database...
|
|---|
| 209 | if (fpViewer) {
|
|---|
| 210 | fpViewer -> SetView ();
|
|---|
| 211 | fpViewer -> ClearView ();
|
|---|
| 212 | fpViewer -> DrawView ();
|
|---|
| 213 | }
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | void G4OpenGLImmediateSceneHandler::RequestPrimitives (const G4VSolid& solid)
|
|---|
| 217 | {
|
|---|
| 218 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 219 | // printf("G4OpenGLImmediateSceneHandler::RequestPrimitives \n");
|
|---|
| 220 | #endif
|
|---|
| 221 | if (fReadyForTransients) {
|
|---|
| 222 | // Always draw transient solids, e.g., hits represented as solids.
|
|---|
| 223 | // (As we have no control over the order of drawing of transient
|
|---|
| 224 | // objects, we cannot do anything about transparent ones, as
|
|---|
| 225 | // below, so always draw them.)
|
|---|
| 226 | G4VSceneHandler::RequestPrimitives (solid);
|
|---|
| 227 | return;
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | // For non-transient (run-duration) objects, ensure transparent
|
|---|
| 231 | // objects are drawn last. The problem of
|
|---|
| 232 | // blending/transparency/alpha is quite a tricky one - see History
|
|---|
| 233 | // of opengl-V07-01-01/2/3.
|
|---|
| 234 | // Get vis attributes - pick up defaults if none.
|
|---|
| 235 | const G4VisAttributes* pVA =
|
|---|
| 236 | fpViewer -> GetApplicableVisAttributes(fpVisAttribs);
|
|---|
| 237 | const G4Colour& c = pVA -> GetColour ();
|
|---|
| 238 | G4double opacity = c.GetAlpha ();
|
|---|
| 239 |
|
|---|
| 240 | if (!fSecondPass) {
|
|---|
| 241 | G4bool transparency_enabled = true;
|
|---|
| 242 | G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
|
|---|
| 243 | if (pViewer) transparency_enabled = pViewer->transparency_enabled;
|
|---|
| 244 | if (transparency_enabled && opacity < 1.) {
|
|---|
| 245 | // On first pass, transparent objects are not drawn, but flag is set...
|
|---|
| 246 | fSecondPassRequested = true;
|
|---|
| 247 | return;
|
|---|
| 248 | }
|
|---|
| 249 | }
|
|---|
| 250 |
|
|---|
| 251 | // On second pass, opaque objects are not drwan...
|
|---|
| 252 | if (fSecondPass && opacity >= 1.) return;
|
|---|
| 253 |
|
|---|
| 254 | // Else invoke base class method...
|
|---|
| 255 | G4VSceneHandler::RequestPrimitives (solid);
|
|---|
| 256 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 257 | // printf("G4OpenGLImmediateSceneHandler::RequestPrimitives END\n");
|
|---|
| 258 | #endif
|
|---|
| 259 | }
|
|---|
| 260 |
|
|---|
| 261 | G4int G4OpenGLImmediateSceneHandler::fSceneIdCount = 0;
|
|---|
| 262 |
|
|---|
| 263 | #endif
|
|---|