G4OpenGLStoredXmViewer.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // Andrew Walkden  10th February 1997
00031 // Class G4OpenGLStoredXmViewer : a class derived from G4OpenGLXmViewer 
00032 //                              and G4OpenGLStoredViewer.
00033 
00034 #ifdef G4VIS_BUILD_OPENGLXM_DRIVER
00035 
00036 #include "G4OpenGLStoredXmViewer.hh"
00037 
00038 #include "G4OpenGLStoredSceneHandler.hh"
00039 #include "G4ios.hh"
00040 
00041 G4OpenGLStoredXmViewer::
00042 G4OpenGLStoredXmViewer (G4OpenGLStoredSceneHandler& sceneHandler,
00043                         const G4String& name)
00044  : G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
00045    G4OpenGLViewer (sceneHandler),
00046    G4OpenGLXmViewer (sceneHandler),
00047    G4OpenGLStoredViewer (sceneHandler)
00048 {
00049 
00050   if (fViewId < 0) return;  // In case error in base class instantiation.
00051 
00052   if (!vi_stored) {
00053     fViewId = -1;  // This flags an error.
00054     G4cerr << "G4OpenGLStoredXmViewer::G4OpenGLStoredXmViewer -"
00055       " G4OpenGLXmViewer couldn't get a visual." << G4endl;
00056     return;
00057   }
00058 }
00059 
00060 G4OpenGLStoredXmViewer::~G4OpenGLStoredXmViewer () {
00061   GetSceneHandler()->RemoveViewerFromList(this);
00062 }
00063 
00064 void G4OpenGLStoredXmViewer::Initialise () {
00065 
00066   CreateGLXContext (vi_stored);
00067   CreateMainWindow ();
00068   CreateFontLists ();
00069 
00070   InitializeGLView ();
00071 
00072   glDrawBuffer (GL_BACK);
00073 }
00074 
00075 void G4OpenGLStoredXmViewer::DrawView () {
00076 #ifdef G4DEBUG_VIS_OGL
00077   printf("G4OpenGLStoredXmViewer::DrawView \n");
00078 #endif
00079 
00080   //Make sure current viewer is attached and clean...
00081   glXMakeCurrent (dpy, win, cx);
00082 
00083   G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
00084 
00085   //See if things have changed from last time and remake if necessary...
00086   // /vis/viewer/rebuild, but if not, make decision and set flag only
00087   // if necessary...
00088   if (!fNeedKernelVisit) KernelVisitDecision ();
00089   G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
00090   ProcessView ();
00091 
00092   if(style!=G4ViewParameters::hlr &&
00093      haloing_enabled) {
00094 
00095     HaloingFirstPass ();
00096     DrawDisplayLists ();
00097 #ifdef G4DEBUG_VIS_OGL
00098     printf("G4OpenGLStoredXmViewer::DrawView () flush\n");
00099 #endif
00100     glFlush ();
00101 
00102     HaloingSecondPass ();
00103 
00104     DrawDisplayLists ();
00105     FinishView ();
00106 
00107   } else {
00108 
00109 #ifdef G4DEBUG_VIS_OGL
00110     printf("G4OpenGLStoredXmViewer::DrawView not hlr \n");
00111 #endif
00112     // If kernel visit was needed, drawing and FinishView will already
00113     // have been done, so...
00114     if (!kernelVisitWasNeeded) {
00115 #ifdef G4DEBUG_VIS_OGL
00116       printf("G4OpenGLStoredXmViewer::ComputeView Don't need kernel Visit \n");
00117 #endif
00118       DrawDisplayLists ();
00119       FinishView ();
00120     } else {
00121 #ifdef G4DEBUG_VIS_OGL
00122       printf("G4OpenGLStoredXmViewer::ComputeView Need kernel Visit \n");
00123 #endif
00124     // However, union cutaways are implemented in DrawDisplayLists, so make
00125     // an extra pass...
00126       if (fVP.IsCutaway() &&
00127           fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
00128         ClearView();
00129         DrawDisplayLists ();
00130         FinishView ();
00131       } else { // ADD TO AVOID KernelVisit=1 and nothing to display
00132         DrawDisplayLists ();
00133         FinishView ();
00134       }
00135     }
00136   }
00137 #ifdef G4DEBUG_VIS_OGL
00138   printf("G4OpenGLStoredXmViewer::DrawView  ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n");
00139 #endif
00140 }
00141 
00142 void G4OpenGLStoredXmViewer::FinishView () {
00143   glXWaitGL (); //Wait for effects of all previous OpenGL commands to
00144                 //be propogated before progressing.
00145 
00146 #ifdef G4DEBUG_VIS_OGL
00147   printf("G4OpenGLStoredXmViewer::FinishView () flush \n");
00148 #endif
00149   glFlush (); //FIXME
00150 
00151   GLint renderMode;
00152   glGetIntegerv(GL_RENDER_MODE, &renderMode);
00153   if (renderMode == GL_RENDER) glXSwapBuffers (dpy, win);  
00154 }
00155 
00156 #endif

Generated on Mon May 27 17:49:10 2013 for Geant4 by  doxygen 1.4.7