G4OpenGLStoredXViewer.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  7th February 1997
00031 // Class G4OpenGLStoredXViewer : a class derived from G4OpenGLXViewer and
00032 //                             G4OpenGLStoredViewer.
00033 
00034 #ifdef G4VIS_BUILD_OPENGLX_DRIVER
00035 
00036 #include "G4OpenGLStoredXViewer.hh"
00037 
00038 #include "G4OpenGLStoredSceneHandler.hh"
00039 #include "G4ios.hh"
00040 
00041 G4OpenGLStoredXViewer::
00042 G4OpenGLStoredXViewer (G4OpenGLStoredSceneHandler& sceneHandler,
00043                  const G4String& name)
00044  : G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
00045    G4OpenGLViewer (sceneHandler),
00046    G4OpenGLXViewer (sceneHandler),
00047    G4OpenGLStoredViewer (sceneHandler)
00048 {
00049   if (fViewId < 0) return;  // In case error in base class instantiation.
00050 
00051   if (!vi_stored) {
00052     fViewId = -1;  // This flags an error.
00053     G4cerr << "G4OpenGLStoredXViewer::G4OpenGLStoredXViewer -"
00054       " G4OpenGLXViewer couldn't get a visual." << G4endl;
00055     return;
00056   }
00057 }
00058 
00059 G4OpenGLStoredXViewer::~G4OpenGLStoredXViewer () {}
00060 
00061 void G4OpenGLStoredXViewer::Initialise () {
00062 
00063 #ifdef G4DEBUG_VIS_OGL
00064   printf("G4OpenGLStoredXViewer::Initialise\n");
00065 #endif
00066   CreateGLXContext (vi_stored);
00067   CreateMainWindow ();
00068   CreateFontLists ();
00069 
00070   InitializeGLView ();
00071 
00072   glDrawBuffer (GL_BACK);
00073 }
00074 
00075 void G4OpenGLStoredXViewer::DrawView () {
00076 
00077 #ifdef G4DEBUG_VIS_OGL
00078   printf("G4OpenGLStoredXViewer::DrawView\n");
00079 #endif
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   // The fNeedKernelVisit flag might have been set by the user in
00087   // /vis/viewer/rebuild, but if not, make decision and set flag only
00088   // if necessary...
00089   if (!fNeedKernelVisit) KernelVisitDecision ();
00090   G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
00091   ProcessView ();
00092 
00093   if(style!=G4ViewParameters::hlr && haloing_enabled) {
00094 
00095     HaloingFirstPass ();
00096     DrawDisplayLists ();
00097 #ifdef G4DEBUG_VIS_OGL
00098   printf("G4OpenGLStoredXViewer::DrawView flush \n");
00099 #endif
00100     glFlush ();
00101 
00102     HaloingSecondPass ();
00103 
00104     DrawDisplayLists ();
00105 
00106   } else {
00107 
00108     if (!kernelVisitWasNeeded) {
00109 #ifdef G4DEBUG_VIS_OGL
00110       printf("G4OpenGLStoredXViewer::DrawView NO need kernel visit\n");
00111 #endif
00112       DrawDisplayLists ();
00113 
00114     } else {
00115 
00116 #ifdef G4DEBUG_VIS_OGL
00117       printf("G4OpenGLStoredXViewer::DrawView NEED kernel visit\n");
00118 #endif
00119     // However, union cutaways are implemented in DrawDisplayLists, so make
00120     // an extra pass...
00121       if (fVP.IsCutaway() &&
00122           fVP.GetCutawayMode() == G4ViewParameters::cutawayUnion) {
00123         ClearView();
00124         DrawDisplayLists ();
00125       } else { // ADD TO AVOID KernelVisit=1 and nothing to display
00126         DrawDisplayLists ();
00127       }
00128     }
00129   }
00130 
00131   FinishView ();
00132 
00133 }
00134 
00135 void G4OpenGLStoredXViewer::FinishView () {
00136 #ifdef G4DEBUG_VIS_OGL
00137   printf("G4OpenGLStoredXViewer::FinishView\n");
00138 #endif
00139   glXWaitGL (); //Wait for effects of all previous OpenGL commands to
00140                 //be propogated before progressing.
00141 
00142 #ifdef G4DEBUG_VIS_OGL
00143   printf("G4OpenGLStoredXViewer::FinishView flush \n");
00144 #endif
00145   glFlush (); //FIXME
00146 
00147   GLint renderMode;
00148   glGetIntegerv(GL_RENDER_MODE, &renderMode);
00149   if (renderMode == GL_RENDER) glXSwapBuffers (dpy, win);  
00150 }
00151 
00152 #endif

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