| 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.25 2009/04/08 16:55:44 lgarnier Exp $
|
|---|
| 28 | // GEANT4 tag $Name: $
|
|---|
| 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 |
|
|---|
| 62 | void G4OpenGLStoredXmViewer::Initialise () {
|
|---|
| 63 |
|
|---|
| 64 | CreateGLXContext (vi_stored);
|
|---|
| 65 | CreateMainWindow ();
|
|---|
| 66 | CreateFontLists ();
|
|---|
| 67 |
|
|---|
| 68 | InitializeGLView ();
|
|---|
| 69 |
|
|---|
| 70 | // clear the buffers and window.
|
|---|
| 71 | ClearView ();
|
|---|
| 72 | FinishView ();
|
|---|
| 73 |
|
|---|
| 74 | glDepthFunc (GL_LEQUAL);
|
|---|
| 75 | glDepthMask (GL_TRUE);
|
|---|
| 76 |
|
|---|
| 77 | glEnable (GL_BLEND);
|
|---|
| 78 | glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|---|
| 79 |
|
|---|
| 80 | glDrawBuffer (GL_BACK);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | void G4OpenGLStoredXmViewer::DrawView () {
|
|---|
| 84 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 85 | printf("G4OpenGLStoredXmViewer::DrawView \n");
|
|---|
| 86 | #endif
|
|---|
| 87 |
|
|---|
| 88 | //Make sure current viewer is attached and clean...
|
|---|
| 89 | glXMakeCurrent (dpy, win, cx);
|
|---|
| 90 |
|
|---|
| 91 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
|
|---|
| 92 |
|
|---|
| 93 | //See if things have changed from last time and remake if necessary...
|
|---|
| 94 | // /vis/viewer/rebuild, but if not, make decision and set flag only
|
|---|
| 95 | // if necessary...
|
|---|
| 96 | if (!fNeedKernelVisit) KernelVisitDecision ();
|
|---|
| 97 | G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
|
|---|
| 98 | ProcessView ();
|
|---|
| 99 |
|
|---|
| 100 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 101 | haloing_enabled) {
|
|---|
| 102 |
|
|---|
| 103 | HaloingFirstPass ();
|
|---|
| 104 | DrawDisplayLists ();
|
|---|
| 105 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 106 | printf("G4OpenGLStoredXmViewer::DrawView () flush\n");
|
|---|
| 107 | #endif
|
|---|
| 108 | glFlush ();
|
|---|
| 109 |
|
|---|
| 110 | HaloingSecondPass ();
|
|---|
| 111 |
|
|---|
| 112 | DrawDisplayLists ();
|
|---|
| 113 | FinishView ();
|
|---|
| 114 |
|
|---|
| 115 | } else {
|
|---|
| 116 |
|
|---|
| 117 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 118 | printf("G4OpenGLStoredXmViewer::DrawView not hlr \n");
|
|---|
| 119 | #endif
|
|---|
| 120 | // If kernel visit was needed, drawing and FinishView will already
|
|---|
| 121 | // have been done, so...
|
|---|
| 122 | if (!kernelVisitWasNeeded) {
|
|---|
| 123 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 124 | printf("G4OpenGLStoredXmViewer::ComputeView Don't need kernel Visit \n");
|
|---|
| 125 | #endif
|
|---|
| 126 | DrawDisplayLists ();
|
|---|
| 127 | FinishView ();
|
|---|
| 128 | } else {
|
|---|
| 129 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 130 | printf("G4OpenGLStoredXmViewer::ComputeView Need kernel Visit \n");
|
|---|
| 131 | #endif
|
|---|
| 132 | // However, union cutaways are implemented in DrawDisplayLists, so make
|
|---|
| 133 | // an extra pass...
|
|---|
| 134 | if (fVP.IsCutaway() &&
|
|---|
| 135 | fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
|
|---|
| 136 | ClearView();
|
|---|
| 137 | DrawDisplayLists ();
|
|---|
| 138 | FinishView ();
|
|---|
| 139 | } else { // ADD TO AVOID KernelVisit=1 and nothing to display
|
|---|
| 140 | DrawDisplayLists ();
|
|---|
| 141 | FinishView ();
|
|---|
| 142 | }
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 146 | printf("G4OpenGLStoredXmViewer::DrawView ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
|
|---|
| 147 | #endif
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | void G4OpenGLStoredXmViewer::FinishView () {
|
|---|
| 151 | glXWaitGL (); //Wait for effects of all previous OpenGL commands to
|
|---|
| 152 | //be propogated before progressing.
|
|---|
| 153 |
|
|---|
| 154 | #ifdef G4DEBUG_VIS_OGL
|
|---|
| 155 | printf("G4OpenGLStoredXmViewer::FinishView () flush \n");
|
|---|
| 156 | #endif
|
|---|
| 157 | glFlush (); //FIXME
|
|---|
| 158 |
|
|---|
| 159 | GLint renderMode;
|
|---|
| 160 | glGetIntegerv(GL_RENDER_MODE, &renderMode);
|
|---|
| 161 | if (renderMode == GL_RENDER) glXSwapBuffers (dpy, win);
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | #endif
|
|---|