33 #ifdef G4VIS_BUILD_OPENGL_DRIVER
54 G4int G4OpenGLStoredSceneHandler::fSceneIdCount = 0;
56 G4int G4OpenGLStoredSceneHandler::fDisplayListId = 0;
57 G4bool G4OpenGLStoredSceneHandler::fMemoryForDisplayLists =
true;
58 G4int G4OpenGLStoredSceneHandler::fDisplayListLimit = 50000;
60 G4OpenGLStoredSceneHandler::PO::PO():
64 fMarkerOrPolyline(false)
67 G4OpenGLStoredSceneHandler::PO::PO(
const G4OpenGLStoredSceneHandler::PO& po):
68 fDisplayListId(po.fDisplayListId),
69 fTransform(po.fTransform),
70 fPickName(po.fPickName),
72 fpG4TextPlus(po.fpG4TextPlus? new G4TextPlus(*po.fpG4TextPlus): 0),
73 fMarkerOrPolyline(po.fMarkerOrPolyline)
81 fMarkerOrPolyline(false)
84 G4OpenGLStoredSceneHandler::PO::~PO()
89 G4OpenGLStoredSceneHandler::PO& G4OpenGLStoredSceneHandler::PO::operator=
90 (
const G4OpenGLStoredSceneHandler::PO& rhs)
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;
102 G4OpenGLStoredSceneHandler::TO::TO():
108 fMarkerOrPolyline(false)
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),
118 fpG4TextPlus(to.fpG4TextPlus? new G4TextPlus(*to.fpG4TextPlus): 0),
119 fMarkerOrPolyline(to.fMarkerOrPolyline)
129 fMarkerOrPolyline(false)
132 G4OpenGLStoredSceneHandler::TO::~TO()
137 G4OpenGLStoredSceneHandler::TO& G4OpenGLStoredSceneHandler::TO::operator=
138 (
const G4OpenGLStoredSceneHandler::TO& rhs)
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;
152 G4OpenGLStoredSceneHandler::G4OpenGLStoredSceneHandler
155 G4OpenGLSceneHandler (system, fSceneIdCount++, name),
159 G4OpenGLStoredSceneHandler::~G4OpenGLStoredSceneHandler ()
162 void G4OpenGLStoredSceneHandler::BeginPrimitives
165 G4OpenGLSceneHandler::BeginPrimitives (objectTransformation);
166 if (fReadyForTransients) glDrawBuffer (GL_FRONT);
170 void G4OpenGLStoredSceneHandler::EndPrimitives ()
174 glDrawBuffer (GL_BACK);
175 G4OpenGLSceneHandler::EndPrimitives ();
178 void G4OpenGLStoredSceneHandler::BeginPrimitives2D
181 G4OpenGLSceneHandler::BeginPrimitives2D(objectTransformation);
182 if (fReadyForTransients) glDrawBuffer (GL_FRONT);
185 void G4OpenGLStoredSceneHandler::EndPrimitives2D ()
189 glDrawBuffer (GL_BACK);
190 G4OpenGLSceneHandler::EndPrimitives2D ();
193 G4bool G4OpenGLStoredSceneHandler::AddPrimitivePreamble(
const G4VMarker& visible)
195 return AddPrimitivePreambleInternal(visible,
true,
false);
197 G4bool G4OpenGLStoredSceneHandler::AddPrimitivePreamble(
const G4Polyline& visible)
199 return AddPrimitivePreambleInternal(visible,
false,
true);
203 return AddPrimitivePreambleInternal(visible,
false,
false);
206 G4bool G4OpenGLStoredSceneHandler::AddPrimitivePreambleInternal
207 (
const G4Visible& visible,
bool isMarker,
bool isPolyline)
210 fpVisAttribs = fpViewer->GetApplicableVisAttributes(visible.
GetVisAttributes());
214 G4bool transparency_enabled =
true;
215 G4bool isMarkerNotHidden =
true;
216 G4OpenGLViewer* pOGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
218 transparency_enabled = pOGLViewer->transparency_enabled;
219 isMarkerNotHidden = pOGLViewer->fVP.IsMarkerNotHidden();
222 G4bool isTransparent = opacity < 1.;
223 G4bool isMarkerOrPolyline = isMarker || isPolyline;
224 G4bool treatAsTransparent = transparency_enabled && isTransparent;
225 G4bool treatAsNotHidden = isMarkerNotHidden && isMarkerOrPolyline;
227 if (fProcessing2D) glDisable (GL_DEPTH_TEST);
229 if (isMarkerOrPolyline && isMarkerNotHidden)
230 glDisable (GL_DEPTH_TEST);
231 else {glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);}
234 if (fThreePassCapable) {
239 if (!(fSecondPassForTransparency || fThirdPassForNonHiddenMarkers)) {
241 if (treatAsTransparent) {
242 fSecondPassForTransparencyRequested =
true;
244 if (treatAsNotHidden) {
245 fThirdPassForNonHiddenMarkersRequested =
true;
248 if (treatAsTransparent || treatAsNotHidden) {
254 if (fSecondPassForTransparency) {
255 if (!treatAsTransparent) {
261 if (fThirdPassForNonHiddenMarkers) {
262 if (!treatAsNotHidden) {
270 if (fpViewer->GetViewParameters().IsPicking()) {
272 glLoadName(++fPickName);
274 LoadAtts(visible, holder);
275 fPickMap[fPickName] = holder;
282 if (fpViewer->GetViewParameters().GetVisAttributesModifiers().size())
284 goto end_of_display_list_reuse_test;
292 goto end_of_display_list_reuse_test;
301 goto end_of_display_list_reuse_test;
305 goto end_of_display_list_reuse_test;
309 if (pCurrentPV -> IsReplicated ()) {
318 if (!(pCurrentPV -> IsParameterised ()) &&
321 !(pCurrentPV -> IsReplicated () && axis ==
kRho) &&
323 (fSolidMap.find (pSolid) != fSolidMap.end ())) {
324 fDisplayListId = fSolidMap [pSolid];
325 PO po(fDisplayListId,fObjectTransformation);
326 if (isPicking) po.fPickName = fPickName;
328 po.fMarkerOrPolyline = isMarkerOrPolyline;
329 fPOList.push_back(po);
338 end_of_display_list_reuse_test:
344 if (fMemoryForDisplayLists) {
345 fDisplayListId = glGenLists (1);
346 if (glGetError() == GL_OUT_OF_MEMORY ||
347 fDisplayListId > fDisplayListLimit) {
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***************************************************"
356 fMemoryForDisplayLists =
false;
360 if (pSolid) fSolidMap [pSolid] = fDisplayListId;
362 if (fMemoryForDisplayLists) {
363 if (fReadyForTransients) {
364 TO to(fDisplayListId, fObjectTransformation);
365 if (isPicking) to.fPickName = fPickName;
367 to.fStartTime = fpVisAttribs->GetStartTime();
368 to.fEndTime = fpVisAttribs->GetEndTime();
369 to.fMarkerOrPolyline = isMarkerOrPolyline;
370 fTOList.push_back(to);
377 G4OpenGLTransform3D oglt (fObjectTransformation);
378 glMultMatrixd (oglt.GetGLMatrix ());
379 if (transparency_enabled) {
384 (
void) ExtraTOProcessing(visible, fTOList.size() - 1);
388 glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE);
390 PO po(fDisplayListId, fObjectTransformation);
391 if (isPicking) po.fPickName = fPickName;
393 po.fMarkerOrPolyline = isMarkerOrPolyline;
394 fPOList.push_back(po);
400 if (transparency_enabled) {
405 G4bool usesGLCommands = ExtraPOProcessing(visible, fPOList.size() - 1);
415 if (!usesGLCommands)
return false;
416 glNewList (fDisplayListId, GL_COMPILE);
420 G4OpenGLTransform3D oglt (fObjectTransformation);
421 glMultMatrixd (oglt.GetGLMatrix ());
422 if (transparency_enabled) {
432 glMatrixMode (GL_PROJECTION);
436 pOGLViewer->g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
438 glMatrixMode (GL_MODELVIEW);
441 G4OpenGLTransform3D oglt (fObjectTransformation);
442 glMultMatrixd (oglt.GetGLMatrix ());
443 glDisable (GL_LIGHTING);
445 glEnable (GL_LIGHTING);
451 void G4OpenGLStoredSceneHandler::AddPrimitivePostamble()
455 glMatrixMode (GL_PROJECTION);
457 glMatrixMode (GL_MODELVIEW);
462 if (glGetError() == GL_OUT_OF_MEMORY) {
464 "ERROR: G4OpenGLStoredSceneHandler::AddPrimitivePostamble: Failure"
465 " to allocate display List for fTopPODL - try OpenGL Immediated mode."
468 if (fMemoryForDisplayLists) {
470 if (glGetError() == GL_OUT_OF_MEMORY) {
472 "ERROR: G4OpenGLStoredSceneHandler::AddPrimitivePostamble: Failure"
473 " to allocate display List for fTopPODL - try OpenGL Immediated mode."
477 if (fReadyForTransients || !fMemoryForDisplayLists) {
482 void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4Polyline& polyline)
484 G4bool furtherprocessing = AddPrimitivePreamble(polyline);
485 if (furtherprocessing) {
486 G4OpenGLSceneHandler::AddPrimitive(polyline);
487 AddPrimitivePostamble();
491 void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4Polymarker& polymarker)
493 G4bool furtherprocessing = AddPrimitivePreamble(polymarker);
494 if (furtherprocessing) {
495 G4OpenGLSceneHandler::AddPrimitive(polymarker);
496 AddPrimitivePostamble();
500 void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4Text& text)
505 G4bool furtherprocessing = AddPrimitivePreamble(text);
506 if (furtherprocessing) {
507 G4OpenGLSceneHandler::AddPrimitive(text);
508 AddPrimitivePostamble();
512 void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4Circle& circle)
514 G4bool furtherprocessing = AddPrimitivePreamble(circle);
515 if (furtherprocessing) {
516 G4OpenGLSceneHandler::AddPrimitive(circle);
517 AddPrimitivePostamble();
521 void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4Square& square)
523 G4bool furtherprocessing = AddPrimitivePreamble(square);
524 if (furtherprocessing) {
525 G4OpenGLSceneHandler::AddPrimitive(square);
526 AddPrimitivePostamble();
530 void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4Scale&
scale)
533 G4OpenGLSceneHandler::AddPrimitive(scale);
536 void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4Polyhedron& polyhedron)
541 G4bool furtherprocessing = AddPrimitivePreamble(polyhedron);
542 if (furtherprocessing) {
543 G4OpenGLSceneHandler::AddPrimitive(polyhedron);
544 AddPrimitivePostamble();
548 void G4OpenGLStoredSceneHandler::BeginModeling () {
556 void G4OpenGLStoredSceneHandler::EndModeling () {
558 fTopPODL = glGenLists (1);
559 if (glGetError() == GL_OUT_OF_MEMORY) {
561 "ERROR: G4OpenGLStoredSceneHandler::EndModeling: Failure to allocate"
562 " display List for fTopPODL - try OpenGL Immediated mode."
566 glNewList (fTopPODL, GL_COMPILE); {
567 for (
size_t i = 0; i < fPOList.size (); i++) {
569 G4OpenGLTransform3D oglt (fPOList[i].fTransform);
570 glMultMatrixd (oglt.GetGLMatrix ());
571 if (fpViewer->GetViewParameters().IsPicking())
572 glLoadName(fPOList[i].fPickName);
573 glCallList (fPOList[i].fDisplayListId);
579 if (glGetError() == GL_OUT_OF_MEMORY) {
581 "ERROR: G4OpenGLStoredSceneHandler::EndModeling: Failure to allocate"
582 " display List for fTopPODL - try OpenGL Immediated mode."
590 void G4OpenGLStoredSceneHandler::ClearStore () {
597 for (
size_t i = 0; i < fPOList.size (); i++)
598 glDeleteLists (fPOList[i].fDisplayListId, 1);
599 if (fTopPODL) glDeleteLists (fTopPODL, 1);
605 ClearAndDestroyAtts();
608 for (
size_t i = 0; i < fTOList.size (); i++)
609 glDeleteLists(fTOList[i].fDisplayListId, 1);
612 fMemoryForDisplayLists =
true;
615 void G4OpenGLStoredSceneHandler::ClearTransientStore ()
620 for (
size_t i = 0; i < fTOList.size (); i++)
621 glDeleteLists(fTOList[i].fDisplayListId, 1);
624 fMemoryForDisplayLists =
true;
628 fpViewer -> SetView ();
629 fpViewer -> ClearView ();
630 fpViewer -> DrawView ();
system("rm -rf microbeam.root")
G4LogicalVolume * GetLogicalVolume() const
virtual void ClearStore()
const G4VisAttributes * GetVisAttributes() const
virtual void BeginModeling()
virtual void EndModeling()
G4GLOB_DLL std::ostream G4cerr
G4VPhysicalVolume * GetCurrentPV() const
virtual void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const =0
G4double GetAlpha() const
G4GLOB_DLL std::ostream G4cout
G4VSolid * GetSolid() const
G4double GetGreen() const
typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData