Geant4  10.02.p01
G4OpenGLStoredSceneHandler.cc
Go to the documentation of this file.
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: G4OpenGLStoredSceneHandler.cc 87695 2014-12-17 09:35:24Z gcosmo $
28 //
29 //
30 // Andrew Walkden 10th February 1997
31 // OpenGL stored scene - creates OpenGL display lists.
32 
33 #ifdef G4VIS_BUILD_OPENGL_DRIVER
34 
36 
37 #include "G4PhysicalVolumeModel.hh"
38 #include "G4LogicalVolumeModel.hh"
39 #include "G4VPhysicalVolume.hh"
40 #include "G4LogicalVolume.hh"
41 #include "G4Polyline.hh"
42 #include "G4Polymarker.hh"
43 #include "G4Text.hh"
44 #include "G4Circle.hh"
45 #include "G4Square.hh"
46 #include "G4Polyhedron.hh"
47 #include "G4AttHolder.hh"
48 #include "G4OpenGLTransform3D.hh"
49 #include "G4OpenGLViewer.hh"
50 #include "G4AttHolder.hh"
51 
52 #include <typeinfo>
53 
54 G4OpenGLStoredSceneHandler::PO::PO():
55  fDisplayListId(0),
56  fPickName(0),
57  fpG4TextPlus(0),
58  fMarkerOrPolyline(false)
59 {}
60 
61 G4OpenGLStoredSceneHandler::PO::PO(const G4OpenGLStoredSceneHandler::PO& po):
62  fDisplayListId(po.fDisplayListId),
63  fTransform(po.fTransform),
64  fPickName(po.fPickName),
65  fColour(po.fColour),
66  fpG4TextPlus(po.fpG4TextPlus? new G4TextPlus(*po.fpG4TextPlus): 0),
67  fMarkerOrPolyline(po.fMarkerOrPolyline)
68 {}
69 
70 G4OpenGLStoredSceneHandler::PO::PO(G4int id, const G4Transform3D& tr):
71  fDisplayListId(id),
72  fTransform(tr),
73  fPickName(0),
74  fpG4TextPlus(0),
75  fMarkerOrPolyline(false)
76 {}
77 
78 G4OpenGLStoredSceneHandler::PO::~PO()
79 {
80  delete fpG4TextPlus;
81 }
82 
83 G4OpenGLStoredSceneHandler::PO& G4OpenGLStoredSceneHandler::PO::operator=
84  (const G4OpenGLStoredSceneHandler::PO& rhs)
85 {
86  if (&rhs == this) return *this;
87  fDisplayListId = rhs.fDisplayListId;
88  fTransform = rhs.fTransform;
89  fPickName = rhs.fPickName;
90  fColour = rhs.fColour;
91  fpG4TextPlus = rhs.fpG4TextPlus? new G4TextPlus(*rhs.fpG4TextPlus): 0;
92  fMarkerOrPolyline = rhs.fMarkerOrPolyline;
93  return *this;
94 }
95 
96 G4OpenGLStoredSceneHandler::TO::TO():
97  fDisplayListId(0),
98  fPickName(0),
99  fStartTime(-DBL_MAX),
100  fEndTime(DBL_MAX),
101  fpG4TextPlus(0),
102  fMarkerOrPolyline(false)
103 {}
104 
105 G4OpenGLStoredSceneHandler::TO::TO(const G4OpenGLStoredSceneHandler::TO& to):
106  fDisplayListId(to.fDisplayListId),
107  fTransform(to.fTransform),
108  fPickName(to.fPickName),
109  fStartTime(to.fStartTime),
110  fEndTime(to.fEndTime),
111  fColour(to.fColour),
112  fpG4TextPlus(to.fpG4TextPlus? new G4TextPlus(*to.fpG4TextPlus): 0),
113  fMarkerOrPolyline(to.fMarkerOrPolyline)
114 {}
115 
116 G4OpenGLStoredSceneHandler::TO::TO(G4int id, const G4Transform3D& tr):
117  fDisplayListId(id),
118  fTransform(tr),
119  fPickName(0),
120  fStartTime(-DBL_MAX),
121  fEndTime(DBL_MAX),
122  fpG4TextPlus(0),
123  fMarkerOrPolyline(false)
124 {}
125 
126 G4OpenGLStoredSceneHandler::TO::~TO()
127 {
128  delete fpG4TextPlus;
129 }
130 
131 G4OpenGLStoredSceneHandler::TO& G4OpenGLStoredSceneHandler::TO::operator=
132  (const G4OpenGLStoredSceneHandler::TO& rhs)
133 {
134  if (&rhs == this) return *this;
135  fDisplayListId = rhs.fDisplayListId;
136  fTransform = rhs.fTransform;
137  fPickName = rhs.fPickName;
138  fStartTime = rhs.fStartTime;
139  fEndTime = rhs.fEndTime;
140  fColour = rhs.fColour;
141  fpG4TextPlus = rhs.fpG4TextPlus? new G4TextPlus(*rhs.fpG4TextPlus): 0;
142  fMarkerOrPolyline = rhs.fMarkerOrPolyline;
143  return *this;
144 }
145 
146 G4OpenGLStoredSceneHandler::G4OpenGLStoredSceneHandler
147 (G4VGraphicsSystem& system,
148  const G4String& name):
149 G4OpenGLSceneHandler (system, fSceneIdCount++, name),
150 fTopPODL (0)
151 {}
152 
153 G4OpenGLStoredSceneHandler::~G4OpenGLStoredSceneHandler ()
154 {}
155 
156 void G4OpenGLStoredSceneHandler::BeginPrimitives
157 (const G4Transform3D& objectTransformation)
158 {
159  G4OpenGLSceneHandler::BeginPrimitives (objectTransformation);
160  if (fReadyForTransients) glDrawBuffer (GL_FRONT);
161  // Display list setup moved to AddPrimitivePreamble. See notes there.
162 }
163 
164 void G4OpenGLStoredSceneHandler::EndPrimitives ()
165 {
166  // See all primitives immediately... At least soon...
167  ScaledFlush();
168  glDrawBuffer (GL_BACK);
169  G4OpenGLSceneHandler::EndPrimitives ();
170 }
171 
172 void G4OpenGLStoredSceneHandler::BeginPrimitives2D
173 (const G4Transform3D& objectTransformation)
174 {
175  G4OpenGLSceneHandler::BeginPrimitives2D(objectTransformation);
176  if (fReadyForTransients) glDrawBuffer (GL_FRONT);
177 }
178 
179 void G4OpenGLStoredSceneHandler::EndPrimitives2D ()
180 {
181  // See all primitives immediately... At least soon...
182  ScaledFlush();
183  glDrawBuffer (GL_BACK);
184  G4OpenGLSceneHandler::EndPrimitives2D ();
185 }
186 
187 G4bool G4OpenGLStoredSceneHandler::AddPrimitivePreamble(const G4VMarker& visible)
188 {
189  return AddPrimitivePreambleInternal(visible, true, false);
190 }
191 G4bool G4OpenGLStoredSceneHandler::AddPrimitivePreamble(const G4Polyline& visible)
192 {
193  return AddPrimitivePreambleInternal(visible, false, true);
194 }
195 G4bool G4OpenGLStoredSceneHandler::AddPrimitivePreamble(const G4Polyhedron& visible)
196 {
197  return AddPrimitivePreambleInternal(visible, false, false);
198 }
199 
200 G4bool G4OpenGLStoredSceneHandler::AddPrimitivePreambleInternal(const G4Visible& visible, bool isMarker, bool isPolyline)
201 {
202  const G4Colour& c = GetColour (visible);
203  G4double opacity = c.GetAlpha ();
204 
205  G4bool transparency_enabled = true;
206  G4bool isMarkerNotHidden = true;
207  G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
208  if (pViewer) {
209  transparency_enabled = pViewer->transparency_enabled;
210  isMarkerNotHidden = pViewer->fVP.IsMarkerNotHidden();
211  }
212 
213  G4bool isTransparent = opacity < 1.;
214  G4bool isMarkerOrPolyline = isMarker || isPolyline;
215  G4bool treatAsTransparent = transparency_enabled && isTransparent;
216  G4bool treatAsNotHidden = isMarkerNotHidden && isMarkerOrPolyline;
217 
218  if (fProcessing2D) glDisable (GL_DEPTH_TEST);
219  else {
220  if (isMarkerOrPolyline && isMarkerNotHidden)
221  glDisable (GL_DEPTH_TEST);
222  else {glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);}
223  }
224 
225  if (fThreePassCapable) {
226 
227  // Ensure transparent objects are drawn opaque ones and before
228  // non-hidden markers. The problem of blending/transparency/alpha
229  // is quite a tricky one - see History of opengl-V07-01-01/2/3.
230  if (!(fSecondPassForTransparency || fThirdPassForNonHiddenMarkers)) {
231  // First pass...
232  if (treatAsTransparent) { // Request pass for transparent objects...
233  fSecondPassForTransparencyRequested = true;
234  }
235  if (treatAsNotHidden) { // Request pass for non-hidden markers...
236  fThirdPassForNonHiddenMarkersRequested = true;
237  }
238  // On first pass, transparent objects and non-hidden markers are not drawn...
239  if (treatAsTransparent || treatAsNotHidden) {
240  return false; // No further processing.
241  }
242  }
243 
244  // On second pass, only transparent objects are drawn...
245  if (fSecondPassForTransparency) {
246  if (!treatAsTransparent) {
247  return false; // No further processing.
248  }
249  }
250 
251  // On third pass, only non-hidden markers are drawn...
252  if (fThirdPassForNonHiddenMarkers) {
253  if (!treatAsNotHidden) {
254  return false; // No further processing.
255 
256  }
257  }
258  } // fThreePassCapable
259 
260  // Loads G4Atts for picking...
261  G4bool isPicking = false;
262  if (fpViewer->GetViewParameters().IsPicking()) {
263  isPicking = true;
264  glLoadName(++fPickName);
265  G4AttHolder* holder = new G4AttHolder;
266  LoadAtts(visible, holder);
267  fPickMap[fPickName] = holder;
268  }
269 
270  // Can we re-use a display list?
271  const G4VSolid* pSolid = 0;
272  G4PhysicalVolumeModel* pPVModel =
273  dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
274  if (fpViewer->GetViewParameters().GetVisAttributesModifiers().size())
275  // Touchables have been modified - don't risk re-using display list.
276  goto end_of_display_list_reuse_test;
277  if (pPVModel) {
278  // Check that it isn't a G4LogicalVolumeModel (which is a sub-class of
279  // G4PhysicalVolumeModel).
280  G4LogicalVolumeModel* pLVModel =
281  dynamic_cast<G4LogicalVolumeModel*>(pPVModel);
282  if (pLVModel)
283  // Logical volume model - don't re-use.
284  goto end_of_display_list_reuse_test;
285  // If part of the geometry hierarchy, i.e., from a
286  // G4PhysicalVolumeModel, check if a display list already exists for
287  // this solid, re-use it if possible. We could be smarter, and
288  // recognise repeated branches of the geometry hierarchy, for
289  // example. But this algorithm should be secure, I think...
290  G4VPhysicalVolume* pPV = pPVModel->GetCurrentPV();
291  if (!pPV)
292  // It's probably a dummy model, e.g., for a user-drawn hit?
293  goto end_of_display_list_reuse_test;
294  G4LogicalVolume* pLV = pPV->GetLogicalVolume();
295  if (!pLV)
296  // Dummy model again?
297  goto end_of_display_list_reuse_test;
298  pSolid = pLV->GetSolid();
299  EAxis axis = kRho;
300  G4VPhysicalVolume* pCurrentPV = pPVModel->GetCurrentPV();
301  if (pCurrentPV -> IsReplicated ()) {
302  G4int nReplicas;
303  G4double width;
304  G4double offset;
305  G4bool consuming;
306  pCurrentPV->GetReplicationData(axis,nReplicas,width,offset,consuming);
307  }
308  // Provided it is not parametrised (because if so, the
309  // solid's parameters might have been changed)...
310  if (!(pCurrentPV -> IsParameterised ()) &&
311  // Provided it is not replicated radially (because if so, the
312  // solid's parameters will have been changed)...
313  !(pCurrentPV -> IsReplicated () && axis == kRho) &&
314  // ...and if the solid has already been rendered...
315  (fSolidMap.find (pSolid) != fSolidMap.end ())) {
316  fDisplayListId = fSolidMap [pSolid];
317  PO po(fDisplayListId,fObjectTransformation);
318  if (isPicking) po.fPickName = fPickName;
319  po.fColour = c;
320  po.fMarkerOrPolyline = isMarkerOrPolyline;
321  fPOList.push_back(po);
322  // No need to test if gl commands are used (result of
323  // ExtraPOProcessing) because we have already decided they will
324  // not, at least not here. Also, pass a dummy G4Visible since
325  // not relevant for G4PhysicalVolumeModel.
326  (void) ExtraPOProcessing(G4Visible(), fPOList.size() - 1);
327  return false; // No further processing.
328  }
329  }
330 end_of_display_list_reuse_test:
331 
332  // Because of our need to control colour of transients (display by
333  // time fading), display lists may only cover a single primitive.
334  // So display list setup is here.
335 
336  if (fMemoryForDisplayLists) {
337  fDisplayListId = glGenLists (1);
338  if (glGetError() == GL_OUT_OF_MEMORY ||
339  fDisplayListId > fDisplayListLimit) {
340  G4cout <<
341  "********************* WARNING! ********************"
342  "\n* Display list limit reached in OpenGL."
343  "\n* Continuing drawing WITHOUT STORING. Scene only partially refreshable."
344  "\n* Current limit: " << fDisplayListLimit <<
345  ". Change with \"/vis/ogl/set/displayListLimit\"."
346  "\n***************************************************"
347  << G4endl;
348  fMemoryForDisplayLists = false;
349  }
350  }
351 
352  if (pSolid) fSolidMap [pSolid] = fDisplayListId;
353 
354  if (fMemoryForDisplayLists) {
355  if (fReadyForTransients) {
356  TO to(fDisplayListId, fObjectTransformation);
357  if (isPicking) to.fPickName = fPickName;
358  to.fColour = c;
359  const G4VisAttributes* pVA =
360  fpViewer->GetApplicableVisAttributes(visible.GetVisAttributes());
361  to.fStartTime = pVA->GetStartTime();
362  to.fEndTime = pVA->GetEndTime();
363  to.fMarkerOrPolyline = isMarkerOrPolyline;
364  fTOList.push_back(to);
365  // For transient objects, colour, transformation, are kept in
366  // the TO, so should *not* be in the display list. As mentioned
367  // above, in some cases (display-by-time fading) we need to have
368  // independent control of colour. But for now transform and set
369  // colour for immediate display.
370  glPushMatrix();
371  G4OpenGLTransform3D oglt (fObjectTransformation);
372  glMultMatrixd (oglt.GetGLMatrix ());
373  if (transparency_enabled) {
374  glColor4d(c.GetRed(),c.GetGreen(),c.GetBlue(),c.GetAlpha());
375  } else {
376  glColor3d(c.GetRed(),c.GetGreen(),c.GetBlue());
377  }
378  (void) ExtraTOProcessing(visible, fTOList.size() - 1);
379  // Ignore return value of the above. If this visible does not use
380  // gl commands, a display list is created that is empty and not
381  // used.
382  glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE);
383  } else {
384  PO po(fDisplayListId, fObjectTransformation);
385  if (isPicking) po.fPickName = fPickName;
386  po.fColour = c;
387  po.fMarkerOrPolyline = isMarkerOrPolyline;
388  fPOList.push_back(po);
389  // For permanent objects, colour is kept in the PO, so should
390  // *not* be in the display list. This is so that sub-classes
391  // may implement colour modifications according to their own
392  // criteria, e.g., scen tree slider in Qt. But for now set
393  // colour for immediate display.
394  if (transparency_enabled) {
395  glColor4d(c.GetRed(),c.GetGreen(),c.GetBlue(),c.GetAlpha());
396  } else {
397  glColor3d(c.GetRed(),c.GetGreen(),c.GetBlue());
398  }
399  G4bool usesGLCommands = ExtraPOProcessing(visible, fPOList.size() - 1);
400  // Transients are displayed as they come (GL_COMPILE_AND_EXECUTE
401  // above) but persistents are compiled into display lists
402  // (GL_COMPILE only) and then drawn from the display lists with
403  // their fObjectTransformation as stored in fPOList. Thus,
404  // there is no need to do glMultMatrixd here. If
405  // ExtraPOProcessing says the visible object does not use gl
406  // commands, simply return and abandon further processing. It
407  // is assumed that all relevant information is kept in the
408  // POList.
409  if (!usesGLCommands) return false;
410  glNewList (fDisplayListId, GL_COMPILE);
411  }
412  } else { // Out of memory (or being used when display lists not required).
413  glDrawBuffer (GL_FRONT);
414  glPushMatrix();
415  G4OpenGLTransform3D oglt (fObjectTransformation);
416  glMultMatrixd (oglt.GetGLMatrix ());
417  if (transparency_enabled) {
418  glColor4d(c.GetRed(),c.GetGreen(),c.GetBlue(),c.GetAlpha());
419  } else {
420  glColor3d(c.GetRed(),c.GetGreen(),c.GetBlue());
421  }
422  }
423 
424  if (fProcessing2D) {
425  // Push current 3D world matrices and load identity to define screen
426  // coordinates...
427  glMatrixMode (GL_PROJECTION);
428  glPushMatrix();
429  glLoadIdentity();
430  if (pViewer) {
431  pViewer->g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
432  }
433  glMatrixMode (GL_MODELVIEW);
434  glPushMatrix();
435  glLoadIdentity();
436  G4OpenGLTransform3D oglt (fObjectTransformation);
437  glMultMatrixd (oglt.GetGLMatrix ());
438  glDisable (GL_LIGHTING);
439  } else {
440  glEnable (GL_LIGHTING);
441  }
442 
443  return true;
444 }
445 
446 void G4OpenGLStoredSceneHandler::AddPrimitivePostamble()
447 {
448  if (fProcessing2D) {
449  // Pop current 3D world matrices back again...
450  glMatrixMode (GL_PROJECTION);
451  glPopMatrix();
452  glMatrixMode (GL_MODELVIEW);
453  glPopMatrix();
454  }
455 
456  // if ((glGetError() == GL_TABLE_TOO_LARGE) || (glGetError() == GL_OUT_OF_MEMORY)) { // Could close?
457  if (glGetError() == GL_OUT_OF_MEMORY) { // Could close?
458  G4cerr <<
459  "ERROR: G4OpenGLStoredSceneHandler::AddPrimitivePostamble: Failure"
460  " to allocate display List for fTopPODL - try OpenGL Immediated mode."
461  << G4endl;
462  }
463  if (fMemoryForDisplayLists) {
464  glEndList();
465  if (glGetError() == GL_OUT_OF_MEMORY) { // Could close?
466  G4cerr <<
467  "ERROR: G4OpenGLStoredSceneHandler::AddPrimitivePostamble: Failure"
468  " to allocate display List for fTopPODL - try OpenGL Immediated mode."
469  << G4endl;
470  }
471  }
472  if (fReadyForTransients || !fMemoryForDisplayLists) {
473  glPopMatrix();
474  }
475 }
476 
477 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polyline& polyline)
478 {
479  G4bool furtherprocessing = AddPrimitivePreamble(polyline);
480  if (furtherprocessing) {
481  G4OpenGLSceneHandler::AddPrimitive(polyline);
482  AddPrimitivePostamble();
483  }
484 }
485 
486 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
487 {
488  G4bool furtherprocessing = AddPrimitivePreamble(polymarker);
489  if (furtherprocessing) {
490  G4OpenGLSceneHandler::AddPrimitive(polymarker);
491  AddPrimitivePostamble();
492  }
493 }
494 
495 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Text& text)
496 {
497  // Note: colour is still handled in
498  // G4OpenGLSceneHandler::AddPrimitive(const G4Text&), so it still
499  // gets into the display list
500  G4bool furtherprocessing = AddPrimitivePreamble(text);
501  if (furtherprocessing) {
502  G4OpenGLSceneHandler::AddPrimitive(text);
503  AddPrimitivePostamble();
504  }
505 }
506 
507 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Circle& circle)
508 {
509  G4bool furtherprocessing = AddPrimitivePreamble(circle);
510  if (furtherprocessing) {
511  G4OpenGLSceneHandler::AddPrimitive(circle);
512  AddPrimitivePostamble();
513  }
514 }
515 
516 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Square& square)
517 {
518  G4bool furtherprocessing = AddPrimitivePreamble(square);
519  if (furtherprocessing) {
520  G4OpenGLSceneHandler::AddPrimitive(square);
521  AddPrimitivePostamble();
522  }
523 }
524 
525 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Scale& scale)
526 {
527  // Let base class split into primitives.
528  G4OpenGLSceneHandler::AddPrimitive(scale);
529 }
530 
531 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron)
532 {
533  // Note: colour is still handled in
534  // G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&), so it still
535  // gets into the display list
536  G4bool furtherprocessing = AddPrimitivePreamble(polyhedron);
537  if (furtherprocessing) {
538  G4OpenGLSceneHandler::AddPrimitive(polyhedron);
539  AddPrimitivePostamble();
540  }
541 }
542 
543 void G4OpenGLStoredSceneHandler::BeginModeling () {
545  /* Debug...
546  fDisplayListId = glGenLists (1);
547  G4cout << "OGL::fDisplayListId (start): " << fDisplayListId << G4endl;
548  */
549 }
550 
551 void G4OpenGLStoredSceneHandler::EndModeling () {
552  // Make a List which calls the other lists.
553  fTopPODL = glGenLists (1);
554  if (glGetError() == GL_OUT_OF_MEMORY) { // Could pre-allocate?
555  G4cerr <<
556  "ERROR: G4OpenGLStoredSceneHandler::EndModeling: Failure to allocate"
557  " display List for fTopPODL - try OpenGL Immediated mode."
558  << G4endl;
559  } else {
560 
561  glNewList (fTopPODL, GL_COMPILE); {
562  for (size_t i = 0; i < fPOList.size (); i++) {
563  glPushMatrix();
564  G4OpenGLTransform3D oglt (fPOList[i].fTransform);
565  glMultMatrixd (oglt.GetGLMatrix ());
566  if (fpViewer->GetViewParameters().IsPicking())
567  glLoadName(fPOList[i].fPickName);
568  glCallList (fPOList[i].fDisplayListId);
569  glPopMatrix();
570  }
571  }
572  glEndList ();
573 
574  if (glGetError() == GL_OUT_OF_MEMORY) { // Could close?
575  G4cerr <<
576  "ERROR: G4OpenGLStoredSceneHandler::EndModeling: Failure to allocate"
577  " display List for fTopPODL - try OpenGL Immediated mode."
578  << G4endl;
579  }
580  }
581 
583 }
584 
585 void G4OpenGLStoredSceneHandler::ClearStore () {
586 
587  //G4cout << "G4OpenGLStoredSceneHandler::ClearStore" << G4endl;
588 
589  G4VSceneHandler::ClearStore (); // Sets need kernel visit, etc.
590 
591  // Delete OpenGL permanent display lists.
592  for (size_t i = 0; i < fPOList.size (); i++)
593  glDeleteLists (fPOList[i].fDisplayListId, 1);
594  if (fTopPODL) glDeleteLists (fTopPODL, 1);
595  fTopPODL = 0;
596 
597  // Clear other lists, dictionary, etc.
598  fPOList.clear ();
599  fSolidMap.clear ();
600  ClearAndDestroyAtts();
601 
602  // ...and clear transient store...
603  for (size_t i = 0; i < fTOList.size (); i++)
604  glDeleteLists(fTOList[i].fDisplayListId, 1);
605  fTOList.clear ();
606 
607  fMemoryForDisplayLists = true;
608 }
609 
610 void G4OpenGLStoredSceneHandler::ClearTransientStore ()
611 {
612  //G4cout << "G4OpenGLStoredSceneHandler::ClearTransientStore" << G4endl;
613 
614  // Delete OpenGL transient display lists and Transient Objects themselves.
615  for (size_t i = 0; i < fTOList.size (); i++)
616  glDeleteLists(fTOList[i].fDisplayListId, 1);
617  fTOList.clear ();
618 
619  fMemoryForDisplayLists = true;
620 
621  // Redraw the scene ready for the next event.
622  if (fpViewer) {
623  fpViewer -> SetView ();
624  fpViewer -> ClearView ();
625  fpViewer -> DrawView ();
626  }
627 }
628 
629 G4int G4OpenGLStoredSceneHandler::fSceneIdCount = 0;
630 
631 G4int G4OpenGLStoredSceneHandler::fDisplayListId = 0;
632 G4bool G4OpenGLStoredSceneHandler::fMemoryForDisplayLists = true;
633 G4int G4OpenGLStoredSceneHandler::fDisplayListLimit = 50000;
634 
635 #endif
G4double GetStartTime() const
virtual void ClearStore()
Definition: G4Text.hh:73
G4double GetAlpha() const
Definition: G4Colour.hh:142
virtual void BeginModeling()
G4String name
Definition: TRTMaterials.hh:40
#define width
G4double GetBlue() const
Definition: G4Colour.hh:141
const G4VisAttributes * GetVisAttributes() const
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
G4double GetRed() const
Definition: G4Colour.hh:139
bool G4bool
Definition: G4Types.hh:79
G4double GetGreen() const
Definition: G4Colour.hh:140
virtual void EndModeling()
HepGeom::Transform3D G4Transform3D
G4LogicalVolume * GetLogicalVolume() const
EAxis
Definition: geomdefs.hh:54
G4double GetEndTime() const
virtual void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const =0
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
Definition: geomdefs.hh:54
G4VPhysicalVolume * GetCurrentPV() const
#define DBL_MAX
Definition: templates.hh:83
G4VSolid * GetSolid() const
G4GLOB_DLL std::ostream G4cerr