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