| 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.24 2006/09/04 12:03:25 allison Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-08-02-patch-01 $
|
|---|
| 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 "G4Circle.hh"
|
|---|
| 50 | #include "G4Square.hh"
|
|---|
| 51 |
|
|---|
| 52 | G4OpenGLImmediateSceneHandler::G4OpenGLImmediateSceneHandler (G4VGraphicsSystem& system,
|
|---|
| 53 | const G4String& name):
|
|---|
| 54 | G4OpenGLSceneHandler (system, fSceneIdCount++, name)
|
|---|
| 55 | {}
|
|---|
| 56 |
|
|---|
| 57 | G4OpenGLImmediateSceneHandler::~G4OpenGLImmediateSceneHandler ()
|
|---|
| 58 | {}
|
|---|
| 59 |
|
|---|
| 60 | #include <iomanip>
|
|---|
| 61 |
|
|---|
| 62 | void G4OpenGLImmediateSceneHandler::AddPrimitivePreamble(const G4Visible& visible)
|
|---|
| 63 | {
|
|---|
| 64 | const G4Colour& c = GetColour (visible);
|
|---|
| 65 | glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Polyline& polyline)
|
|---|
| 69 | {
|
|---|
| 70 | AddPrimitivePreamble(polyline);
|
|---|
| 71 | G4OpenGLSceneHandler::AddPrimitive(polyline);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Circle& circle)
|
|---|
| 75 | {
|
|---|
| 76 | AddPrimitivePreamble(circle);
|
|---|
| 77 | G4OpenGLSceneHandler::AddPrimitive(circle);
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Square& square)
|
|---|
| 81 | {
|
|---|
| 82 | AddPrimitivePreamble(square);
|
|---|
| 83 | G4OpenGLSceneHandler::AddPrimitive(square);
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | void G4OpenGLImmediateSceneHandler::BeginPrimitives
|
|---|
| 87 | (const G4Transform3D& objectTransformation) {
|
|---|
| 88 | G4VSceneHandler::BeginPrimitives (objectTransformation);
|
|---|
| 89 | glPushMatrix();
|
|---|
| 90 | G4OpenGLTransform3D oglt (objectTransformation);
|
|---|
| 91 |
|
|---|
| 92 | /*************************** Check matrix.
|
|---|
| 93 | const GLdouble* m = oglt.GetGLMatrix ();
|
|---|
| 94 | G4cout << "G4OpenGLTransform3D matrix:";
|
|---|
| 95 | for (int i = 0; i < 16; i++) {
|
|---|
| 96 | if ((i % 4) == 0) G4cout << '\n';
|
|---|
| 97 | G4cout << std::setw (15) << m[i];
|
|---|
| 98 | }
|
|---|
| 99 | G4cout << G4endl;
|
|---|
| 100 | *****************************************/
|
|---|
| 101 |
|
|---|
| 102 | glMultMatrixd (oglt.GetGLMatrix ());
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | void G4OpenGLImmediateSceneHandler::EndPrimitives ()
|
|---|
| 106 | {
|
|---|
| 107 | glPopMatrix();
|
|---|
| 108 |
|
|---|
| 109 | // See all primitives immediately...
|
|---|
| 110 | glFlush ();
|
|---|
| 111 |
|
|---|
| 112 | G4VSceneHandler::EndPrimitives ();
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | void G4OpenGLImmediateSceneHandler::BeginPrimitives2D()
|
|---|
| 116 | {
|
|---|
| 117 | G4VSceneHandler::BeginPrimitives2D();
|
|---|
| 118 |
|
|---|
| 119 | // Push current 3D world matrices and load identity to define screen
|
|---|
| 120 | // coordinates...
|
|---|
| 121 | glMatrixMode (GL_PROJECTION);
|
|---|
| 122 | glPushMatrix();
|
|---|
| 123 | glLoadIdentity();
|
|---|
| 124 | glOrtho (-1., 1., -1., 1., -DBL_MAX, DBL_MAX);
|
|---|
| 125 | glMatrixMode (GL_MODELVIEW);
|
|---|
| 126 | glPushMatrix();
|
|---|
| 127 | glLoadIdentity();
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | void G4OpenGLImmediateSceneHandler::EndPrimitives2D()
|
|---|
| 131 | {
|
|---|
| 132 | // Pop current 3D world matrices back again...
|
|---|
| 133 | glMatrixMode (GL_PROJECTION);
|
|---|
| 134 | glPopMatrix();
|
|---|
| 135 | glMatrixMode (GL_MODELVIEW);
|
|---|
| 136 | glPopMatrix();
|
|---|
| 137 |
|
|---|
| 138 | // See all primitives immediately...
|
|---|
| 139 | glFlush ();
|
|---|
| 140 |
|
|---|
| 141 | G4VSceneHandler::EndPrimitives2D ();
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | void G4OpenGLImmediateSceneHandler::BeginModeling () {
|
|---|
| 145 | G4VSceneHandler::BeginModeling();
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | void G4OpenGLImmediateSceneHandler::EndModeling () {
|
|---|
| 149 | G4VSceneHandler::EndModeling ();
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | void G4OpenGLImmediateSceneHandler::ClearTransientStore () {
|
|---|
| 153 | G4VSceneHandler::ClearTransientStore ();
|
|---|
| 154 | // Make sure screen corresponds to graphical database...
|
|---|
| 155 | if (fpViewer) {
|
|---|
| 156 | fpViewer -> SetView ();
|
|---|
| 157 | fpViewer -> ClearView ();
|
|---|
| 158 | fpViewer -> DrawView ();
|
|---|
| 159 | }
|
|---|
| 160 | }
|
|---|
| 161 |
|
|---|
| 162 | void G4OpenGLImmediateSceneHandler::RequestPrimitives (const G4VSolid& solid)
|
|---|
| 163 | {
|
|---|
| 164 | if (fReadyForTransients) {
|
|---|
| 165 | // Always draw transient solids, e.g., hits represented as solids.
|
|---|
| 166 | // (As we have no control over the order of drawing of transient
|
|---|
| 167 | // objects, we cannot do anything about transparent ones, as
|
|---|
| 168 | // below, so always draw them.)
|
|---|
| 169 | G4VSceneHandler::RequestPrimitives (solid);
|
|---|
| 170 | return;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | // For non-transient (run-duration) objects, ensure transparent
|
|---|
| 174 | // objects are drawn last. The problem of
|
|---|
| 175 | // blending/transparency/alpha is quite a tricky one - see History
|
|---|
| 176 | // of opengl-V07-01-01/2/3.
|
|---|
| 177 | // Get vis attributes - pick up defaults if none.
|
|---|
| 178 | const G4VisAttributes* pVA =
|
|---|
| 179 | fpViewer -> GetApplicableVisAttributes(fpVisAttribs);
|
|---|
| 180 | const G4Colour& c = pVA -> GetColour ();
|
|---|
| 181 | G4double opacity = c.GetAlpha ();
|
|---|
| 182 |
|
|---|
| 183 | if (!fSecondPass) {
|
|---|
| 184 | G4bool transparency_enabled = true;
|
|---|
| 185 | G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
|
|---|
| 186 | if (pViewer) transparency_enabled = pViewer->transparency_enabled;
|
|---|
| 187 | if (transparency_enabled && opacity < 1.) {
|
|---|
| 188 | // On first pass, transparent objects are not drawn, but flag is set...
|
|---|
| 189 | fSecondPassRequested = true;
|
|---|
| 190 | return;
|
|---|
| 191 | }
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | // On second pass, opaque objects are not drwan...
|
|---|
| 195 | if (fSecondPass && opacity >= 1.) return;
|
|---|
| 196 |
|
|---|
| 197 | // Else invoke base class method...
|
|---|
| 198 | G4VSceneHandler::RequestPrimitives (solid);
|
|---|
| 199 | }
|
|---|
| 200 |
|
|---|
| 201 | G4int G4OpenGLImmediateSceneHandler::fSceneIdCount = 0;
|
|---|
| 202 |
|
|---|
| 203 | #endif
|
|---|