G4OpenGLStoredSceneHandler.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 // OpenGL stored scene - creates OpenGL display lists.
00032 
00033 #ifdef G4VIS_BUILD_OPENGL_DRIVER
00034 
00035 // Included here - problems with HP compiler if not before other includes?
00036 #include "G4NURBS.hh"
00037 
00038 // Here follows a special for Mesa, the OpenGL emulator.  Does not affect
00039 // other OpenGL's, as far as I'm aware.   John Allison 18/9/96.
00040 #define CENTERLINE_CLPP  /* CenterLine C++ workaround: */
00041 // Also seems to be required for HP's CC and AIX xlC, at least.
00042 
00043 #include "G4OpenGLStoredSceneHandler.hh"
00044 
00045 #include "G4PhysicalVolumeModel.hh"
00046 #include "G4LogicalVolumeModel.hh"
00047 #include "G4VPhysicalVolume.hh"
00048 #include "G4LogicalVolume.hh"
00049 #include "G4Polyline.hh"
00050 #include "G4Polymarker.hh"
00051 #include "G4Text.hh"
00052 #include "G4Circle.hh"
00053 #include "G4Square.hh"
00054 #include "G4Polyhedron.hh"
00055 #include "G4AttHolder.hh"
00056 #include "G4OpenGLTransform3D.hh"
00057 #include "G4OpenGLViewer.hh"
00058 #include "G4AttHolder.hh"
00059 
00060 #include <typeinfo>
00061 
00062 G4OpenGLStoredSceneHandler::PO::PO():
00063   fDisplayListId(0),
00064   fPickName(0),
00065   fpG4TextPlus(0),
00066   fMarkerOrPolyline(false)
00067 {}
00068 
00069 G4OpenGLStoredSceneHandler::PO::PO(const G4OpenGLStoredSceneHandler::PO& po):
00070   fDisplayListId(po.fDisplayListId),
00071   fTransform(po.fTransform),
00072   fPickName(po.fPickName),
00073   fColour(po.fColour),
00074   fpG4TextPlus(po.fpG4TextPlus? new G4TextPlus(*po.fpG4TextPlus): 0),
00075   fMarkerOrPolyline(po.fMarkerOrPolyline)
00076 {}
00077 
00078 G4OpenGLStoredSceneHandler::PO::PO(G4int id, const G4Transform3D& tr):
00079   fDisplayListId(id),
00080   fTransform(tr),
00081   fPickName(0),
00082   fpG4TextPlus(0),
00083   fMarkerOrPolyline(false)
00084 {}
00085 
00086 G4OpenGLStoredSceneHandler::PO::~PO()
00087 {
00088   delete fpG4TextPlus;
00089 }
00090 
00091 G4OpenGLStoredSceneHandler::PO& G4OpenGLStoredSceneHandler::PO::operator=
00092   (const G4OpenGLStoredSceneHandler::PO& rhs)
00093 {
00094   if (&rhs == this) return *this;
00095   fDisplayListId = rhs.fDisplayListId;
00096   fTransform = rhs.fTransform;
00097   fPickName = rhs.fPickName;
00098   fColour = rhs.fColour;
00099   fpG4TextPlus = rhs.fpG4TextPlus? new G4TextPlus(*rhs.fpG4TextPlus): 0;
00100   fMarkerOrPolyline = rhs.fMarkerOrPolyline;
00101   return *this;
00102 }
00103 
00104 G4OpenGLStoredSceneHandler::TO::TO():
00105   fDisplayListId(0),
00106   fPickName(0),
00107   fStartTime(-DBL_MAX),
00108   fEndTime(DBL_MAX),
00109   fpG4TextPlus(0),
00110   fMarkerOrPolyline(false)
00111 {}
00112 
00113 G4OpenGLStoredSceneHandler::TO::TO(const G4OpenGLStoredSceneHandler::TO& to):
00114   fDisplayListId(to.fDisplayListId),
00115   fTransform(to.fTransform),
00116   fPickName(to.fPickName),
00117   fStartTime(to.fStartTime),
00118   fEndTime(to.fEndTime),
00119   fColour(to.fColour),
00120   fpG4TextPlus(to.fpG4TextPlus? new G4TextPlus(*to.fpG4TextPlus): 0),
00121   fMarkerOrPolyline(to.fMarkerOrPolyline)
00122 {}
00123 
00124 G4OpenGLStoredSceneHandler::TO::TO(G4int id, const G4Transform3D& tr):
00125   fDisplayListId(id),
00126   fTransform(tr),
00127   fPickName(0),
00128   fStartTime(-DBL_MAX),
00129   fEndTime(DBL_MAX),
00130   fpG4TextPlus(0),
00131   fMarkerOrPolyline(false)
00132 {}
00133 
00134 G4OpenGLStoredSceneHandler::TO::~TO()
00135 {
00136   delete fpG4TextPlus;
00137 }
00138 
00139 G4OpenGLStoredSceneHandler::TO& G4OpenGLStoredSceneHandler::TO::operator=
00140   (const G4OpenGLStoredSceneHandler::TO& rhs)
00141 {
00142   if (&rhs == this) return *this;
00143   fDisplayListId = rhs.fDisplayListId;
00144   fTransform = rhs.fTransform;
00145   fPickName = rhs.fPickName;
00146   fStartTime = rhs.fStartTime;
00147   fEndTime = rhs.fEndTime;
00148   fColour = rhs.fColour;
00149   fpG4TextPlus = rhs.fpG4TextPlus? new G4TextPlus(*rhs.fpG4TextPlus): 0;
00150   fMarkerOrPolyline = rhs.fMarkerOrPolyline;
00151   return *this;
00152 }
00153 
00154 G4OpenGLStoredSceneHandler::G4OpenGLStoredSceneHandler
00155 (G4VGraphicsSystem& system,
00156  const G4String& name):
00157 G4OpenGLSceneHandler (system, fSceneIdCount++, name),
00158 fTopPODL (0)
00159 {}
00160 
00161 G4OpenGLStoredSceneHandler::~G4OpenGLStoredSceneHandler ()
00162 {}
00163 
00164 void G4OpenGLStoredSceneHandler::BeginPrimitives
00165 (const G4Transform3D& objectTransformation)
00166 {  
00167   G4OpenGLSceneHandler::BeginPrimitives (objectTransformation);
00168   if (fReadyForTransients) glDrawBuffer (GL_FRONT);
00169   // Display list setup moved to AddPrimitivePreamble.  See notes there.
00170 }
00171 
00172 void G4OpenGLStoredSceneHandler::EndPrimitives ()
00173 {
00174   // See all primitives immediately...  At least soon...
00175   ScaledFlush();
00176   glDrawBuffer (GL_BACK);
00177   G4OpenGLSceneHandler::EndPrimitives ();
00178 }
00179 
00180 void G4OpenGLStoredSceneHandler::BeginPrimitives2D
00181 (const G4Transform3D& objectTransformation)
00182 {
00183   G4OpenGLSceneHandler::BeginPrimitives2D(objectTransformation);
00184   if (fReadyForTransients) glDrawBuffer (GL_FRONT);
00185 }
00186 
00187 void G4OpenGLStoredSceneHandler::EndPrimitives2D ()
00188 {
00189   // See all primitives immediately...  At least soon...
00190   ScaledFlush();
00191   glDrawBuffer (GL_BACK);
00192   G4OpenGLSceneHandler::EndPrimitives2D ();
00193 }
00194 
00195 G4bool G4OpenGLStoredSceneHandler::AddPrimitivePreamble(const G4Visible& visible)
00196 {
00197   const G4Colour& c = GetColour (visible);
00198   G4double opacity = c.GetAlpha ();
00199 
00200   G4bool transparency_enabled = true;
00201   G4bool isMarkerNotHidden = true;
00202   G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
00203   if (pViewer) {
00204     transparency_enabled = pViewer->transparency_enabled;
00205     isMarkerNotHidden = pViewer->fVP.IsMarkerNotHidden();
00206   }
00207   
00208   G4bool isMarker = false;
00209   try {
00210     (void) dynamic_cast<const G4VMarker&>(visible);
00211     isMarker = true;
00212   }
00213   catch (std::bad_cast) {}
00214   
00215   G4bool isPolyline = false;
00216   try {
00217     (void) dynamic_cast<const G4Polyline&>(visible);
00218     isPolyline = true;
00219   }
00220   catch (std::bad_cast) {}
00221   
00222   G4bool isTransparent = opacity < 1.;
00223   G4bool isMarkerOrPolyline = isMarker || isPolyline;
00224   G4bool treatAsTransparent = transparency_enabled && isTransparent;
00225   G4bool treatAsNotHidden = isMarkerNotHidden && isMarkerOrPolyline;
00226   
00227   if (fProcessing2D) glDisable (GL_DEPTH_TEST);
00228   else {
00229     if (isMarkerOrPolyline && isMarkerNotHidden)
00230       glDisable (GL_DEPTH_TEST);
00231     else {glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);}
00232   }
00233 
00234   if (fThreePassCapable) {
00235     
00236     // Ensure transparent objects are drawn opaque ones and before
00237     // non-hidden markers.  The problem of blending/transparency/alpha
00238     // is quite a tricky one - see History of opengl-V07-01-01/2/3.
00239     if (!(fSecondPassForTransparency || fThirdPassForNonHiddenMarkers)) {
00240       // First pass...
00241       if (treatAsTransparent) {  // Request pass for transparent objects...
00242         fSecondPassForTransparencyRequested = true;
00243       }
00244       if (treatAsNotHidden) {    // Request pass for non-hidden markers...
00245         fThirdPassForNonHiddenMarkersRequested = true;
00246       }
00247       // On first pass, transparent objects and non-hidden markers are not drawn...
00248       if (treatAsTransparent || treatAsNotHidden) {
00249         return false;  // No further processing.
00250       }
00251     }
00252     
00253     // On second pass, only transparent objects are drawn...
00254     if (fSecondPassForTransparency) {
00255       if (!treatAsTransparent) {
00256         return false;  // No further processing.
00257       }
00258     }
00259     
00260     // On third pass, only non-hidden markers are drawn...
00261     if (fThirdPassForNonHiddenMarkers) {
00262       if (!treatAsNotHidden) {
00263         return false;  // No further processing.
00264         
00265       }
00266     }
00267   }  // fThreePassCapable
00268   
00269   // Loads G4Atts for picking...
00270   G4bool isPicking = false;
00271   if (fpViewer->GetViewParameters().IsPicking()) {
00272     isPicking = true;
00273     glLoadName(++fPickName);
00274     G4AttHolder* holder = new G4AttHolder;
00275     LoadAtts(visible, holder);
00276     fPickMap[fPickName] = holder;
00277   }
00278   
00279   // Can we re-use a display list?
00280   const G4VSolid* pSolid = 0;
00281   G4PhysicalVolumeModel* pPVModel =
00282   dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
00283   if (fpViewer->GetViewParameters().GetVisAttributesModifiers().size())
00284     // Touchables have been modified - don't risk re-using display list.
00285     goto end_of_display_list_reuse_test;
00286   if (pPVModel) {
00287     // Check that it isn't a G4LogicalVolumeModel (which is a sub-class of
00288     // G4PhysicalVolumeModel).
00289     G4LogicalVolumeModel* pLVModel =
00290     dynamic_cast<G4LogicalVolumeModel*>(pPVModel);
00291     if (pLVModel)
00292       // Logical volume model - don't re-use.
00293       goto end_of_display_list_reuse_test;
00294     // If part of the geometry hierarchy, i.e., from a
00295     // G4PhysicalVolumeModel, check if a display list already exists for
00296     // this solid, re-use it if possible.  We could be smarter, and
00297     // recognise repeated branches of the geometry hierarchy, for
00298     // example.  But this algorithm should be secure, I think...
00299     pSolid = pPVModel->GetCurrentPV()->GetLogicalVolume()->GetSolid();
00300     EAxis axis = kRho;
00301     G4VPhysicalVolume* pCurrentPV = pPVModel->GetCurrentPV();
00302     if (pCurrentPV -> IsReplicated ()) {
00303       G4int nReplicas;
00304       G4double width;
00305       G4double offset;
00306       G4bool consuming;
00307       pCurrentPV->GetReplicationData(axis,nReplicas,width,offset,consuming);
00308     }
00309     // Provided it is not parametrised (because if so, the
00310     // solid's parameters might have been changed)...
00311     if (!(pCurrentPV -> IsParameterised ()) &&
00312         // Provided it is not replicated radially (because if so, the
00313         // solid's parameters will have been changed)...
00314         !(pCurrentPV -> IsReplicated () && axis == kRho) &&
00315         // ...and if the solid has already been rendered...
00316         (fSolidMap.find (pSolid) != fSolidMap.end ())) {
00317       fDisplayListId = fSolidMap [pSolid];
00318       PO po(fDisplayListId,fObjectTransformation);
00319       if (isPicking) po.fPickName = fPickName;
00320       po.fColour = c;
00321       po.fMarkerOrPolyline = isMarkerOrPolyline;
00322       fPOList.push_back(po);
00323       // No need to test if gl commands are used (result of
00324       // ExtraPOProcessing) because we have already decided they will
00325       // not, at least not here.  Also, pass a dummy G4Visible since
00326       // not relevant for G4PhysicalVolumeModel.
00327       (void) ExtraPOProcessing(G4Visible(), fPOList.size() - 1);
00328       return false;  // No further processing.
00329     }
00330   }
00331 end_of_display_list_reuse_test:
00332 
00333   // Because of our need to control colour of transients (display by
00334   // time fading), display lists may only cover a single primitive.
00335   // So display list setup is here.
00336   
00337   if (fMemoryForDisplayLists) {
00338     fDisplayListId = glGenLists (1);
00339     if (glGetError() == GL_OUT_OF_MEMORY ||
00340         fDisplayListId > fDisplayListLimit) {
00341       G4cout <<
00342       "********************* WARNING! ********************"
00343       "\n*  Display list limit reached in OpenGL."
00344       "\n*  Continuing drawing WITHOUT STORING. Scene only partially refreshable."
00345       "\n*  Current limit: " << fDisplayListLimit <<
00346       ".  Change with \"/vis/ogl/set/displayListLimit\"."
00347       "\n***************************************************"
00348       << G4endl;
00349       fMemoryForDisplayLists = false;
00350     }
00351   }
00352   
00353   if (pSolid) fSolidMap [pSolid] = fDisplayListId;
00354 
00355   if (fMemoryForDisplayLists) {
00356     if (fReadyForTransients) {
00357       TO to(fDisplayListId, fObjectTransformation);
00358       if (isPicking) to.fPickName = fPickName;
00359       to.fColour = c;
00360       const G4VisAttributes* pVA =
00361         fpViewer->GetApplicableVisAttributes(visible.GetVisAttributes());
00362       to.fStartTime = pVA->GetStartTime();
00363       to.fEndTime = pVA->GetEndTime();
00364       to.fMarkerOrPolyline = isMarkerOrPolyline;
00365       fTOList.push_back(to);
00366       // For transient objects, colour, transformation, are kept in
00367       // the TO, so should *not* be in the display list.  As mentioned
00368       // above, in some cases (display-by-time fading) we need to have
00369       // independent control of colour.  But for now transform and set
00370       // colour for immediate display.
00371       glPushMatrix();
00372       G4OpenGLTransform3D oglt (fObjectTransformation);
00373       glMultMatrixd (oglt.GetGLMatrix ());
00374       if (transparency_enabled) {
00375         glColor4d(c.GetRed(),c.GetGreen(),c.GetBlue(),c.GetAlpha());
00376       } else {
00377         glColor3d(c.GetRed(),c.GetGreen(),c.GetBlue());
00378       }
00379       (void) ExtraTOProcessing(visible, fTOList.size() - 1);
00380       // Ignore return value of the above.  If this visible does not use
00381       // gl commands, a display list is created that is empty and not
00382       // used.
00383       glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE);
00384     } else {
00385       PO po(fDisplayListId, fObjectTransformation);
00386       if (isPicking) po.fPickName = fPickName;
00387       po.fColour = c;
00388       po.fMarkerOrPolyline = isMarkerOrPolyline;
00389       fPOList.push_back(po);
00390       // For permanent objects, colour is kept in the PO, so should
00391       // *not* be in the display list.  This is so that sub-classes
00392       // may implement colour modifications according to their own
00393       // criteria, e.g., scen tree slider in Qt.  But for now set
00394       // colour for immediate display.
00395       if (transparency_enabled) {
00396         glColor4d(c.GetRed(),c.GetGreen(),c.GetBlue(),c.GetAlpha());
00397       } else {
00398         glColor3d(c.GetRed(),c.GetGreen(),c.GetBlue());
00399       }
00400       G4bool usesGLCommands = ExtraPOProcessing(visible, fPOList.size() - 1);
00401       // Transients are displayed as they come (GL_COMPILE_AND_EXECUTE
00402       // above) but persistents are compiled into display lists
00403       // (GL_COMPILE only) and then drawn from the display lists with
00404       // their fObjectTransformation as stored in fPOList.  Thus,
00405       // there is no need to do glMultMatrixd here.  If
00406       // ExtraPOProcessing says the visible object does not use gl
00407       // commands, simply return and abandon further processing.  It
00408       // is assumed that all relevant information is kept in the
00409       // POList.
00410       if (!usesGLCommands) return false;
00411       glNewList (fDisplayListId, GL_COMPILE);
00412     }
00413   } else {  // Out of memory (or being used when display lists not required).
00414     glDrawBuffer (GL_FRONT);
00415     glPushMatrix();
00416     G4OpenGLTransform3D oglt (fObjectTransformation);
00417     glMultMatrixd (oglt.GetGLMatrix ());
00418     if (transparency_enabled) {
00419       glColor4d(c.GetRed(),c.GetGreen(),c.GetBlue(),c.GetAlpha());
00420     } else {
00421       glColor3d(c.GetRed(),c.GetGreen(),c.GetBlue());
00422     }
00423   }
00424 
00425   if (fProcessing2D) {
00426     // Push current 3D world matrices and load identity to define screen
00427     // coordinates...
00428     glMatrixMode (GL_PROJECTION);
00429     glPushMatrix();
00430     glLoadIdentity();
00431     glOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
00432     glMatrixMode (GL_MODELVIEW);
00433     glPushMatrix();
00434     glLoadIdentity();
00435     G4OpenGLTransform3D oglt (fObjectTransformation);
00436     glMultMatrixd (oglt.GetGLMatrix ());
00437     glDisable(GL_DEPTH_TEST);  // But see parent scene handler!!  In
00438     glDisable (GL_LIGHTING);   // some cases, we need to re-iterate this.
00439   }
00440 
00441   return true;
00442 }
00443 
00444 void G4OpenGLStoredSceneHandler::AddPrimitivePostamble()
00445 {
00446   if (fProcessing2D) {
00447     // Pop current 3D world matrices back again...
00448     glMatrixMode (GL_PROJECTION);
00449     glPopMatrix();
00450     glMatrixMode (GL_MODELVIEW);
00451     glPopMatrix();
00452   }
00453 
00454   //  if ((glGetError() == GL_TABLE_TOO_LARGE) || (glGetError() == GL_OUT_OF_MEMORY)) {  // Could close?
00455   if (glGetError() == GL_OUT_OF_MEMORY) {  // Could close?
00456     G4cout <<
00457       "ERROR: G4OpenGLStoredSceneHandler::AddPrimitivePostamble: Failure"
00458       "  to allocate display List for fTopPODL - try OpenGL Immediated mode."
00459            << G4endl;
00460   }
00461   if (fMemoryForDisplayLists) {
00462     glEndList();
00463     if (glGetError() == GL_OUT_OF_MEMORY) {  // Could close?
00464       G4cout <<
00465         "ERROR: G4OpenGLStoredSceneHandler::AddPrimitivePostamble: Failure"
00466         "  to allocate display List for fTopPODL - try OpenGL Immediated mode."
00467              << G4endl;
00468     }
00469   }
00470   if (fReadyForTransients || !fMemoryForDisplayLists) {
00471     glPopMatrix();
00472   }
00473 }
00474 
00475 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polyline& polyline)
00476 {
00477   G4bool furtherprocessing = AddPrimitivePreamble(polyline);
00478   if (furtherprocessing) {
00479     G4OpenGLSceneHandler::AddPrimitive(polyline);
00480     AddPrimitivePostamble();
00481   }
00482 }
00483 
00484 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
00485 {
00486   G4bool furtherprocessing = AddPrimitivePreamble(polymarker);
00487   if (furtherprocessing) {
00488     G4OpenGLSceneHandler::AddPrimitive(polymarker);
00489     AddPrimitivePostamble();
00490   }
00491 }
00492 
00493 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Text& text)
00494 {
00495   // Note: colour is still handled in
00496   // G4OpenGLSceneHandler::AddPrimitive(const G4Text&), so it still
00497   // gets into the display list
00498   G4bool furtherprocessing = AddPrimitivePreamble(text);
00499   if (furtherprocessing) {
00500     G4OpenGLSceneHandler::AddPrimitive(text);
00501     AddPrimitivePostamble();
00502   }
00503 }
00504 
00505 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Circle& circle)
00506 {
00507   G4bool furtherprocessing = AddPrimitivePreamble(circle);
00508   if (furtherprocessing) {
00509     G4OpenGLSceneHandler::AddPrimitive(circle);
00510     AddPrimitivePostamble();
00511   }
00512 }
00513 
00514 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Square& square)
00515 {
00516   G4bool furtherprocessing = AddPrimitivePreamble(square);
00517   if (furtherprocessing) {
00518     G4OpenGLSceneHandler::AddPrimitive(square);
00519     AddPrimitivePostamble();
00520   }
00521 }
00522 
00523 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Scale& scale)
00524 {
00525   // Let base class split into primitives.
00526   G4OpenGLSceneHandler::AddPrimitive(scale);
00527 }
00528 
00529 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron)
00530 {
00531   // Note: colour is still handled in
00532   // G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&), so it still
00533   // gets into the display list
00534   G4bool furtherprocessing = AddPrimitivePreamble(polyhedron);
00535   if (furtherprocessing) {
00536     G4OpenGLSceneHandler::AddPrimitive(polyhedron);
00537     AddPrimitivePostamble();
00538   }
00539 }
00540 
00541 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4NURBS& nurbs)
00542 {
00543   // Note: colour is still handled in
00544   // G4OpenGLSceneHandler::AddPrimitive(const G4NURBS&), so it still
00545   // gets into the display list
00546   G4bool furtherprocessing = AddPrimitivePreamble(nurbs);
00547   if (furtherprocessing) {
00548     G4OpenGLSceneHandler::AddPrimitive(nurbs);
00549     AddPrimitivePostamble();
00550   }
00551 }
00552 
00553 void G4OpenGLStoredSceneHandler::BeginModeling () {
00554   G4VSceneHandler::BeginModeling();
00555   /* Debug...
00556   fDisplayListId = glGenLists (1);
00557   G4cout << "OGL::fDisplayListId (start): " << fDisplayListId << G4endl;
00558   */
00559 }
00560 
00561 void G4OpenGLStoredSceneHandler::EndModeling () {
00562   // Make a List which calls the other lists.
00563   fTopPODL = glGenLists (1);
00564   if (glGetError() == GL_OUT_OF_MEMORY) {  // Could pre-allocate?
00565     G4cout <<
00566       "ERROR: G4OpenGLStoredSceneHandler::EndModeling: Failure to allocate"
00567       "  display List for fTopPODL - try OpenGL Immediated mode."
00568            << G4endl;
00569   } else {
00570 
00571     glNewList (fTopPODL, GL_COMPILE); {
00572       for (size_t i = 0; i < fPOList.size (); i++) {
00573         glPushMatrix();
00574         G4OpenGLTransform3D oglt (fPOList[i].fTransform);
00575         glMultMatrixd (oglt.GetGLMatrix ());
00576         if (fpViewer->GetViewParameters().IsPicking())
00577           glLoadName(fPOList[i].fPickName);
00578         glCallList (fPOList[i].fDisplayListId);
00579         glPopMatrix();
00580       }
00581     }
00582     glEndList ();
00583 
00584     if (glGetError() == GL_OUT_OF_MEMORY) {  // Could close?
00585       G4cout <<
00586         "ERROR: G4OpenGLStoredSceneHandler::EndModeling: Failure to allocate"
00587         "  display List for fTopPODL - try OpenGL Immediated mode."
00588              << G4endl;
00589     }
00590   }
00591 
00592   G4VSceneHandler::EndModeling ();
00593 }
00594 
00595 void G4OpenGLStoredSceneHandler::ClearStore () {
00596 
00597   //G4cout << "G4OpenGLStoredSceneHandler::ClearStore" << G4endl;
00598 
00599   G4VSceneHandler::ClearStore ();  // Sets need kernel visit, etc.
00600 
00601   // Delete OpenGL permanent display lists.
00602   for (size_t i = 0; i < fPOList.size (); i++)
00603     glDeleteLists (fPOList[i].fDisplayListId, 1);
00604   if (fTopPODL) glDeleteLists (fTopPODL, 1);
00605   fTopPODL = 0;
00606 
00607   // Clear other lists, dictionary, etc.
00608   fPOList.clear ();
00609   fSolidMap.clear ();
00610   ClearAndDestroyAtts();
00611 
00612   // ...and clear transient store...
00613   for (size_t i = 0; i < fTOList.size (); i++)
00614     glDeleteLists(fTOList[i].fDisplayListId, 1);
00615   fTOList.clear ();
00616 
00617   fMemoryForDisplayLists = true;
00618 }
00619 
00620 void G4OpenGLStoredSceneHandler::ClearTransientStore ()
00621 {
00622   //G4cout << "G4OpenGLStoredSceneHandler::ClearTransientStore" << G4endl;
00623 
00624   // Delete OpenGL transient display lists and Transient Objects themselves.
00625   for (size_t i = 0; i < fTOList.size (); i++)
00626     glDeleteLists(fTOList[i].fDisplayListId, 1);
00627   fTOList.clear ();
00628 
00629   fMemoryForDisplayLists = true;
00630 
00631   // Redraw the scene ready for the next event.
00632   if (fpViewer) {
00633     fpViewer -> SetView ();
00634     fpViewer -> ClearView ();
00635     fpViewer -> DrawView ();
00636   }
00637 }
00638 
00639 G4int G4OpenGLStoredSceneHandler::fSceneIdCount = 0;
00640 
00641 G4int  G4OpenGLStoredSceneHandler::fDisplayListId = 0;
00642 G4bool G4OpenGLStoredSceneHandler::fMemoryForDisplayLists = true;
00643 G4int  G4OpenGLStoredSceneHandler::fDisplayListLimit = 50000;
00644 
00645 #endif

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