33#ifdef G4VIS_BUILD_OPENGL_DRIVER
40#define CENTERLINE_CLPP
62G4OpenGLStoredSceneHandler::PO::PO():
66 fMarkerOrPolyline(false)
69G4OpenGLStoredSceneHandler::PO::PO(
const G4OpenGLStoredSceneHandler::PO& po):
70 fDisplayListId(po.fDisplayListId),
71 fTransform(po.fTransform),
72 fPickName(po.fPickName),
74 fpG4TextPlus(po.fpG4TextPlus? new G4TextPlus(*po.fpG4TextPlus): 0),
75 fMarkerOrPolyline(po.fMarkerOrPolyline)
83 fMarkerOrPolyline(false)
86G4OpenGLStoredSceneHandler::PO::~PO()
91G4OpenGLStoredSceneHandler::PO& G4OpenGLStoredSceneHandler::PO::operator=
92 (
const G4OpenGLStoredSceneHandler::PO& rhs)
94 if (&rhs ==
this)
return *
this;
95 fDisplayListId = rhs.fDisplayListId;
96 fTransform = rhs.fTransform;
97 fPickName = rhs.fPickName;
98 fColour = rhs.fColour;
99 fpG4TextPlus = rhs.fpG4TextPlus?
new G4TextPlus(*rhs.fpG4TextPlus): 0;
100 fMarkerOrPolyline = rhs.fMarkerOrPolyline;
104G4OpenGLStoredSceneHandler::TO::TO():
110 fMarkerOrPolyline(false)
113G4OpenGLStoredSceneHandler::TO::TO(
const G4OpenGLStoredSceneHandler::TO& to):
114 fDisplayListId(to.fDisplayListId),
115 fTransform(to.fTransform),
116 fPickName(to.fPickName),
117 fStartTime(to.fStartTime),
118 fEndTime(to.fEndTime),
120 fpG4TextPlus(to.fpG4TextPlus? new G4TextPlus(*to.fpG4TextPlus): 0),
121 fMarkerOrPolyline(to.fMarkerOrPolyline)
131 fMarkerOrPolyline(false)
134G4OpenGLStoredSceneHandler::TO::~TO()
139G4OpenGLStoredSceneHandler::TO& G4OpenGLStoredSceneHandler::TO::operator=
140 (
const G4OpenGLStoredSceneHandler::TO& rhs)
142 if (&rhs ==
this)
return *
this;
143 fDisplayListId = rhs.fDisplayListId;
144 fTransform = rhs.fTransform;
145 fPickName = rhs.fPickName;
146 fStartTime = rhs.fStartTime;
147 fEndTime = rhs.fEndTime;
148 fColour = rhs.fColour;
149 fpG4TextPlus = rhs.fpG4TextPlus?
new G4TextPlus(*rhs.fpG4TextPlus): 0;
150 fMarkerOrPolyline = rhs.fMarkerOrPolyline;
154G4OpenGLStoredSceneHandler::G4OpenGLStoredSceneHandler
157G4OpenGLSceneHandler (system, fSceneIdCount++, name),
161G4OpenGLStoredSceneHandler::~G4OpenGLStoredSceneHandler ()
164void G4OpenGLStoredSceneHandler::BeginPrimitives
167 G4OpenGLSceneHandler::BeginPrimitives (objectTransformation);
168 if (fReadyForTransients) glDrawBuffer (GL_FRONT);
172void G4OpenGLStoredSceneHandler::EndPrimitives ()
176 glDrawBuffer (GL_BACK);
177 G4OpenGLSceneHandler::EndPrimitives ();
180void G4OpenGLStoredSceneHandler::BeginPrimitives2D
183 G4OpenGLSceneHandler::BeginPrimitives2D(objectTransformation);
184 if (fReadyForTransients) glDrawBuffer (GL_FRONT);
187void G4OpenGLStoredSceneHandler::EndPrimitives2D ()
191 glDrawBuffer (GL_BACK);
192 G4OpenGLSceneHandler::EndPrimitives2D ();
195G4bool G4OpenGLStoredSceneHandler::AddPrimitivePreamble(
const G4Visible& visible)
197 const G4Colour& c = GetColour (visible);
200 G4bool transparency_enabled =
true;
201 G4bool isMarkerNotHidden =
true;
202 G4OpenGLViewer* pViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
204 transparency_enabled = pViewer->transparency_enabled;
205 isMarkerNotHidden = pViewer->fVP.IsMarkerNotHidden();
210 (void)
dynamic_cast<const G4VMarker&
>(visible);
213 catch (std::bad_cast) {}
215 G4bool isPolyline =
false;
217 (void)
dynamic_cast<const G4Polyline&
>(visible);
220 catch (std::bad_cast) {}
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) {
271 if (fpViewer->GetViewParameters().IsPicking()) {
273 glLoadName(++fPickName);
275 LoadAtts(visible, holder);
276 fPickMap[fPickName] = holder;
283 if (fpViewer->GetViewParameters().GetVisAttributesModifiers().size())
285 goto end_of_display_list_reuse_test;
293 goto end_of_display_list_reuse_test;
302 if (pCurrentPV -> IsReplicated ()) {
311 if (!(pCurrentPV -> IsParameterised ()) &&
314 !(pCurrentPV -> IsReplicated () && axis ==
kRho) &&
316 (fSolidMap.find (pSolid) != fSolidMap.end ())) {
317 fDisplayListId = fSolidMap [pSolid];
318 PO po(fDisplayListId,fObjectTransformation);
319 if (isPicking) po.fPickName = fPickName;
321 po.fMarkerOrPolyline = isMarkerOrPolyline;
322 fPOList.push_back(po);
327 (void) ExtraPOProcessing(
G4Visible(), fPOList.size() - 1);
331end_of_display_list_reuse_test:
337 if (fMemoryForDisplayLists) {
338 fDisplayListId = glGenLists (1);
339 if (glGetError() == GL_OUT_OF_MEMORY ||
340 fDisplayListId > fDisplayListLimit) {
342 "********************* WARNING! ********************"
343 "\n* Display list limit reached in OpenGL."
344 "\n* Continuing drawing WITHOUT STORING. Scene only partially refreshable."
345 "\n* Current limit: " << fDisplayListLimit <<
346 ". Change with \"/vis/ogl/set/displayListLimit\"."
347 "\n***************************************************"
349 fMemoryForDisplayLists =
false;
353 if (pSolid) fSolidMap [pSolid] = fDisplayListId;
355 if (fMemoryForDisplayLists) {
356 if (fReadyForTransients) {
357 TO to(fDisplayListId, fObjectTransformation);
358 if (isPicking) to.fPickName = fPickName;
364 to.fMarkerOrPolyline = isMarkerOrPolyline;
365 fTOList.push_back(to);
372 G4OpenGLTransform3D oglt (fObjectTransformation);
373 glMultMatrixd (oglt.GetGLMatrix ());
374 if (transparency_enabled) {
379 (void) ExtraTOProcessing(visible, fTOList.size() - 1);
383 glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE);
385 PO po(fDisplayListId, fObjectTransformation);
386 if (isPicking) po.fPickName = fPickName;
388 po.fMarkerOrPolyline = isMarkerOrPolyline;
389 fPOList.push_back(po);
395 if (transparency_enabled) {
400 G4bool usesGLCommands = ExtraPOProcessing(visible, fPOList.size() - 1);
410 if (!usesGLCommands)
return false;
411 glNewList (fDisplayListId, GL_COMPILE);
414 glDrawBuffer (GL_FRONT);
416 G4OpenGLTransform3D oglt (fObjectTransformation);
417 glMultMatrixd (oglt.GetGLMatrix ());
418 if (transparency_enabled) {
428 glMatrixMode (GL_PROJECTION);
431 glOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
432 glMatrixMode (GL_MODELVIEW);
435 G4OpenGLTransform3D oglt (fObjectTransformation);
436 glMultMatrixd (oglt.GetGLMatrix ());
437 glDisable(GL_DEPTH_TEST);
438 glDisable (GL_LIGHTING);
444void G4OpenGLStoredSceneHandler::AddPrimitivePostamble()
448 glMatrixMode (GL_PROJECTION);
450 glMatrixMode (GL_MODELVIEW);
455 if (glGetError() == GL_OUT_OF_MEMORY) {
457 "ERROR: G4OpenGLStoredSceneHandler::AddPrimitivePostamble: Failure"
458 " to allocate display List for fTopPODL - try OpenGL Immediated mode."
461 if (fMemoryForDisplayLists) {
463 if (glGetError() == GL_OUT_OF_MEMORY) {
465 "ERROR: G4OpenGLStoredSceneHandler::AddPrimitivePostamble: Failure"
466 " to allocate display List for fTopPODL - try OpenGL Immediated mode."
470 if (fReadyForTransients || !fMemoryForDisplayLists) {
475void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4Polyline& polyline)
477 G4bool furtherprocessing = AddPrimitivePreamble(polyline);
478 if (furtherprocessing) {
479 G4OpenGLSceneHandler::AddPrimitive(polyline);
480 AddPrimitivePostamble();
484void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4Polymarker& polymarker)
486 G4bool furtherprocessing = AddPrimitivePreamble(polymarker);
487 if (furtherprocessing) {
488 G4OpenGLSceneHandler::AddPrimitive(polymarker);
489 AddPrimitivePostamble();
493void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4Text& text)
498 G4bool furtherprocessing = AddPrimitivePreamble(text);
499 if (furtherprocessing) {
500 G4OpenGLSceneHandler::AddPrimitive(text);
501 AddPrimitivePostamble();
505void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4Circle& circle)
507 G4bool furtherprocessing = AddPrimitivePreamble(circle);
508 if (furtherprocessing) {
509 G4OpenGLSceneHandler::AddPrimitive(circle);
510 AddPrimitivePostamble();
514void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4Square& square)
516 G4bool furtherprocessing = AddPrimitivePreamble(square);
517 if (furtherprocessing) {
518 G4OpenGLSceneHandler::AddPrimitive(square);
519 AddPrimitivePostamble();
523void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4Scale& scale)
526 G4OpenGLSceneHandler::AddPrimitive(scale);
529void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4Polyhedron& polyhedron)
534 G4bool furtherprocessing = AddPrimitivePreamble(polyhedron);
535 if (furtherprocessing) {
536 G4OpenGLSceneHandler::AddPrimitive(polyhedron);
537 AddPrimitivePostamble();
541void G4OpenGLStoredSceneHandler::AddPrimitive (
const G4NURBS& nurbs)
546 G4bool furtherprocessing = AddPrimitivePreamble(nurbs);
547 if (furtherprocessing) {
548 G4OpenGLSceneHandler::AddPrimitive(nurbs);
549 AddPrimitivePostamble();
553void G4OpenGLStoredSceneHandler::BeginModeling () {
561void G4OpenGLStoredSceneHandler::EndModeling () {
563 fTopPODL = glGenLists (1);
564 if (glGetError() == GL_OUT_OF_MEMORY) {
566 "ERROR: G4OpenGLStoredSceneHandler::EndModeling: Failure to allocate"
567 " display List for fTopPODL - try OpenGL Immediated mode."
571 glNewList (fTopPODL, GL_COMPILE); {
572 for (
size_t i = 0; i < fPOList.size (); i++) {
574 G4OpenGLTransform3D oglt (fPOList[i].fTransform);
575 glMultMatrixd (oglt.GetGLMatrix ());
576 if (fpViewer->GetViewParameters().IsPicking())
577 glLoadName(fPOList[i].fPickName);
578 glCallList (fPOList[i].fDisplayListId);
584 if (glGetError() == GL_OUT_OF_MEMORY) {
586 "ERROR: G4OpenGLStoredSceneHandler::EndModeling: Failure to allocate"
587 " display List for fTopPODL - try OpenGL Immediated mode."
595void G4OpenGLStoredSceneHandler::ClearStore () {
602 for (
size_t i = 0; i < fPOList.size (); i++)
603 glDeleteLists (fPOList[i].fDisplayListId, 1);
604 if (fTopPODL) glDeleteLists (fTopPODL, 1);
610 ClearAndDestroyAtts();
613 for (
size_t i = 0; i < fTOList.size (); i++)
614 glDeleteLists(fTOList[i].fDisplayListId, 1);
617 fMemoryForDisplayLists =
true;
620void G4OpenGLStoredSceneHandler::ClearTransientStore ()
625 for (
size_t i = 0; i < fTOList.size (); i++)
626 glDeleteLists(fTOList[i].fDisplayListId, 1);
629 fMemoryForDisplayLists =
true;
633 fpViewer -> SetView ();
634 fpViewer -> ClearView ();
635 fpViewer -> DrawView ();
639G4int G4OpenGLStoredSceneHandler::fSceneIdCount = 0;
641G4int G4OpenGLStoredSceneHandler::fDisplayListId = 0;
642G4bool G4OpenGLStoredSceneHandler::fMemoryForDisplayLists =
true;
643G4int G4OpenGLStoredSceneHandler::fDisplayListLimit = 50000;
G4DLLIMPORT std::ostream G4cout
G4double GetAlpha() const
G4double GetGreen() const
G4VSolid * GetSolid() const
G4VPhysicalVolume * GetCurrentPV() const
G4LogicalVolume * GetLogicalVolume() const
virtual void GetReplicationData(EAxis &axis, G4int &nReplicas, G4double &width, G4double &offset, G4bool &consuming) const =0
virtual void BeginModeling()
virtual void EndModeling()
virtual void ClearStore()
G4double GetStartTime() const
G4double GetEndTime() const
const G4VisAttributes * GetVisAttributes() const