Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // >> 27 // $Id: G4OpenGLStoredSceneHandler.cc,v 1.31 2006/08/30 11:43:57 allison Exp $ >> 28 // GEANT4 tag $Name: geant4-08-02-patch-01 $ 27 // 29 // 28 // 30 // 29 // Andrew Walkden 10th February 1997 31 // Andrew Walkden 10th February 1997 30 // OpenGL stored scene - creates OpenGL displa 32 // OpenGL stored scene - creates OpenGL display lists. 31 33 >> 34 #ifdef G4VIS_BUILD_OPENGL_DRIVER >> 35 >> 36 // Included here - problems with HP compiler if not before other includes? >> 37 #include "G4NURBS.hh" >> 38 >> 39 // Here follows a special for Mesa, the OpenGL emulator. Does not affect >> 40 // other OpenGL's, as far as I'm aware. John Allison 18/9/96. >> 41 #define CENTERLINE_CLPP /* CenterLine C++ workaround: */ >> 42 // Also seems to be required for HP's CC and AIX xlC, at least. >> 43 32 #include "G4OpenGLStoredSceneHandler.hh" 44 #include "G4OpenGLStoredSceneHandler.hh" 33 45 34 #include "G4PhysicalVolumeModel.hh" 46 #include "G4PhysicalVolumeModel.hh" 35 #include "G4LogicalVolumeModel.hh" << 36 #include "G4VPhysicalVolume.hh" 47 #include "G4VPhysicalVolume.hh" 37 #include "G4LogicalVolume.hh" << 38 #include "G4Polyline.hh" 48 #include "G4Polyline.hh" 39 #include "G4Polymarker.hh" 49 #include "G4Polymarker.hh" 40 #include "G4Text.hh" << 41 #include "G4Circle.hh" 50 #include "G4Circle.hh" 42 #include "G4Square.hh" 51 #include "G4Square.hh" 43 #include "G4Polyhedron.hh" << 44 #include "G4AttHolder.hh" << 45 #include "G4OpenGLTransform3D.hh" << 46 #include "G4OpenGLViewer.hh" << 47 #include "G4AttHolder.hh" << 48 << 49 #include <typeinfo> << 50 << 51 G4int G4OpenGLStoredSceneHandler::fSceneIdCoun << 52 << 53 G4int G4OpenGLStoredSceneHandler::fDisplayLis << 54 << 55 G4OpenGLStoredSceneHandler::PO::PO(): << 56 fDisplayListId(0), << 57 fPickName(0), << 58 fpG4TextPlus(0), << 59 fMarkerOrPolyline(false) << 60 {} << 61 52 62 G4OpenGLStoredSceneHandler::PO::PO(const G4Ope << 53 G4OpenGLStoredSceneHandler::G4OpenGLStoredSceneHandler (G4VGraphicsSystem& system, 63 fDisplayListId(po.fDisplayListId), << 54 const G4String& name): 64 fTransform(po.fTransform), << 55 G4OpenGLSceneHandler (system, fSceneIdCount++, name), 65 fPickName(po.fPickName), << 56 fMemoryForDisplayLists (true), 66 fColour(po.fColour), << 57 fAddPrimitivePreambleNestingDepth (0), 67 fpG4TextPlus(po.fpG4TextPlus? new G4TextPlus << 58 fTopPODL (0) 68 fMarkerOrPolyline(po.fMarkerOrPolyline) << 69 {} 59 {} 70 60 71 G4OpenGLStoredSceneHandler::PO::PO(G4int id, c << 61 G4OpenGLStoredSceneHandler::~G4OpenGLStoredSceneHandler () 72 fDisplayListId(id), << 73 fTransform(tr), << 74 fPickName(0), << 75 fpG4TextPlus(0), << 76 fMarkerOrPolyline(false) << 77 {} 62 {} 78 63 79 G4OpenGLStoredSceneHandler::PO::~PO() << 64 void G4OpenGLStoredSceneHandler::AddPrimitivePreamble(const G4Visible& visible) 80 { 65 { 81 delete fpG4TextPlus; << 66 // Track nesting depth to avoid recursive calls, for example, from a 82 } << 67 // G4Polymarker that invokes a G4Circle... >> 68 fAddPrimitivePreambleNestingDepth++; >> 69 if (fAddPrimitivePreambleNestingDepth > 1) return; 83 70 84 G4OpenGLStoredSceneHandler::PO& G4OpenGLStored << 71 const G4Colour& c = GetColour (visible); 85 (const G4OpenGLStoredSceneHandler::PO& rhs) << 86 { << 87 if (&rhs == this) return *this; << 88 fDisplayListId = rhs.fDisplayListId; << 89 fTransform = rhs.fTransform; << 90 fPickName = rhs.fPickName; << 91 fColour = rhs.fColour; << 92 fpG4TextPlus = rhs.fpG4TextPlus? new G4TextP << 93 fMarkerOrPolyline = rhs.fMarkerOrPolyline; << 94 return *this; << 95 } << 96 << 97 G4OpenGLStoredSceneHandler::TO::TO(): << 98 fDisplayListId(0), << 99 fPickName(0), << 100 fStartTime(-G4VisAttributes::fVeryLongTime), << 101 fEndTime(G4VisAttributes::fVeryLongTime), << 102 fpG4TextPlus(0), << 103 fMarkerOrPolyline(false) << 104 {} << 105 << 106 G4OpenGLStoredSceneHandler::TO::TO(const G4Ope << 107 fDisplayListId(to.fDisplayListId), << 108 fTransform(to.fTransform), << 109 fPickName(to.fPickName), << 110 fStartTime(to.fStartTime), << 111 fEndTime(to.fEndTime), << 112 fColour(to.fColour), << 113 fpG4TextPlus(to.fpG4TextPlus? new G4TextPlus << 114 fMarkerOrPolyline(to.fMarkerOrPolyline) << 115 {} << 116 72 117 G4OpenGLStoredSceneHandler::TO::TO(G4int id, c << 73 if (fMemoryForDisplayLists && fReadyForTransients) { 118 fDisplayListId(id), << 119 fTransform(tr), << 120 fPickName(0), << 121 fStartTime(-G4VisAttributes::fVeryLongTime), << 122 fEndTime(G4VisAttributes::fVeryLongTime), << 123 fpG4TextPlus(0), << 124 fMarkerOrPolyline(false) << 125 {} << 126 74 127 G4OpenGLStoredSceneHandler::TO::~TO() << 75 TO& to = fTOList.back(); // Transient object information. 128 { << 129 delete fpG4TextPlus; << 130 } << 131 76 132 G4OpenGLStoredSceneHandler::TO& G4OpenGLStored << 77 // Get vis attributes - pick up defaults if none. 133 (const G4OpenGLStoredSceneHandler::TO& rhs) << 78 const G4VisAttributes* pVA = 134 { << 79 fpViewer->GetApplicableVisAttributes(visible.GetVisAttributes()); 135 if (&rhs == this) return *this; << 136 fDisplayListId = rhs.fDisplayListId; << 137 fTransform = rhs.fTransform; << 138 fPickName = rhs.fPickName; << 139 fStartTime = rhs.fStartTime; << 140 fEndTime = rhs.fEndTime; << 141 fColour = rhs.fColour; << 142 fpG4TextPlus = rhs.fpG4TextPlus? new G4TextP << 143 fMarkerOrPolyline = rhs.fMarkerOrPolyline; << 144 return *this; << 145 } << 146 80 147 G4OpenGLStoredSceneHandler::G4OpenGLStoredScen << 81 // Get time information from vis attributes. 148 (G4VGraphicsSystem& system, << 82 to.fStartTime = pVA->GetStartTime(); 149 const G4String& name): << 83 to.fEndTime = pVA->GetEndTime(); 150 G4OpenGLSceneHandler (system, fSceneIdCount++, << 151 fDoNotUseDisplayList(false), << 152 fTopPODL (0) << 153 {} << 154 84 155 G4OpenGLStoredSceneHandler::~G4OpenGLStoredSce << 85 // Keep colour out of (already started) display list so that it 156 {} << 86 // can be applied independently. >> 87 glEndList(); >> 88 glDeleteLists(fDisplayListId, 1); >> 89 to.fColour = c; >> 90 glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ()); >> 91 glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE); >> 92 >> 93 } else { 157 94 158 void G4OpenGLStoredSceneHandler::BeginPrimitiv << 95 // Make sure colour is set in other cases. 159 (const G4Transform3D& objectTransformation) << 96 glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ()); 160 { << 97 } 161 G4OpenGLSceneHandler::BeginPrimitives (objec << 162 if (fReadyForTransients) glDrawBuffer (GL_FR << 163 // Display list setup moved to AddPrimitiveP << 164 } 98 } 165 99 166 void G4OpenGLStoredSceneHandler::EndPrimitives << 100 void G4OpenGLStoredSceneHandler::AddPrimitivePostamble() 167 { 101 { 168 // See all primitives immediately... At lea << 102 fAddPrimitivePreambleNestingDepth--; 169 ScaledFlush(); << 170 glDrawBuffer (GL_BACK); << 171 G4OpenGLSceneHandler::EndPrimitives (); << 172 } 103 } 173 104 174 void G4OpenGLStoredSceneHandler::BeginPrimitiv << 105 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polyline& polyline) 175 (const G4Transform3D& objectTransformation) << 176 { 106 { 177 G4OpenGLSceneHandler::BeginPrimitives2D(obje << 107 AddPrimitivePreamble(polyline); 178 if (fReadyForTransients) glDrawBuffer (GL_FR << 108 G4OpenGLSceneHandler::AddPrimitive(polyline); >> 109 AddPrimitivePostamble(); 179 } 110 } 180 111 181 void G4OpenGLStoredSceneHandler::EndPrimitives << 112 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Circle& circle) 182 { 113 { 183 // See all primitives immediately... At lea << 114 AddPrimitivePreamble(circle); 184 ScaledFlush(); << 115 G4OpenGLSceneHandler::AddPrimitive(circle); 185 glDrawBuffer (GL_BACK); << 116 AddPrimitivePostamble(); 186 G4OpenGLSceneHandler::EndPrimitives2D (); << 187 } 117 } 188 118 189 G4bool G4OpenGLStoredSceneHandler::AddPrimitiv << 119 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Square& square) 190 { << 191 return AddPrimitivePreambleInternal(visible, << 192 } << 193 G4bool G4OpenGLStoredSceneHandler::AddPrimitiv << 194 { << 195 return AddPrimitivePreambleInternal(visible, << 196 } << 197 G4bool G4OpenGLStoredSceneHandler::AddPrimitiv << 198 { 120 { 199 return AddPrimitivePreambleInternal(visible, << 121 AddPrimitivePreamble(square); >> 122 G4OpenGLSceneHandler::AddPrimitive(square); >> 123 AddPrimitivePostamble(); 200 } 124 } 201 125 202 G4bool G4OpenGLStoredSceneHandler::AddPrimitiv << 126 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polymarker& polymarker) 203 (const G4Visible& visible, bool isMarker, bool << 204 { 127 { 205 // Get applicable vis attributes for all primi << 128 AddPrimitivePreamble(polymarker); 206 fpVisAttribs = fpViewer->GetApplicableVisAtt << 129 G4OpenGLSceneHandler::AddPrimitive(polymarker); 207 const G4Colour& c = GetColour (); << 130 AddPrimitivePostamble(); 208 G4double opacity = c.GetAlpha (); << 131 } 209 << 210 G4bool transparency_enabled = true; << 211 G4bool isMarkerNotHidden = true; << 212 G4OpenGLViewer* pOGLViewer = dynamic_cast<G4 << 213 if (pOGLViewer) { << 214 transparency_enabled = pOGLViewer->transpa << 215 isMarkerNotHidden = pOGLViewer->fVP.IsMark << 216 } << 217 << 218 G4bool isTransparent = opacity < 1.; << 219 G4bool isMarkerOrPolyline = isMarker || isPo << 220 G4bool treatAsTransparent = transparency_ena << 221 G4bool treatAsNotHidden = isMarkerNotHidden << 222 << 223 if (fProcessing2D) glDisable (GL_DEPTH_TEST) << 224 else { << 225 if (isMarkerOrPolyline && isMarkerNotHidde << 226 glDisable (GL_DEPTH_TEST); << 227 else {glEnable (GL_DEPTH_TEST); glDepthFun << 228 } << 229 132 230 if (fThreePassCapable) { << 133 void G4OpenGLStoredSceneHandler::BeginPrimitives 231 << 134 (const G4Transform3D& objectTransformation) { 232 // Ensure transparent objects are drawn *a << 233 // non-hidden markers. The problem of ble << 234 // is quite a tricky one - see History of << 235 if (!(fSecondPassForTransparency || fThird << 236 // First pass... << 237 if (treatAsTransparent) { // Request pa << 238 fSecondPassForTransparencyRequested = << 239 } << 240 if (treatAsNotHidden) { // Request pa << 241 fThirdPassForNonHiddenMarkersRequested << 242 } << 243 // On first pass, transparent objects an << 244 if (treatAsTransparent || treatAsNotHidd << 245 return false; // No further processin << 246 } << 247 } << 248 << 249 // On second pass, only transparent object << 250 if (fSecondPassForTransparency) { << 251 if (!treatAsTransparent) { << 252 return false; // No further processin << 253 } << 254 } << 255 << 256 // On third pass, only non-hidden markers << 257 if (fThirdPassForNonHiddenMarkers) { << 258 if (!treatAsNotHidden) { << 259 return false; // No further processin << 260 } << 261 } << 262 } // fThreePassCapable << 263 135 264 // Loads G4Atts for picking... << 136 G4VSceneHandler::BeginPrimitives (objectTransformation); 265 G4bool isPicking = false; << 266 if (fpViewer->GetViewParameters().IsPicking( << 267 isPicking = true; << 268 glLoadName(++fPickName); << 269 G4AttHolder* holder = new G4AttHolder; << 270 LoadAtts(visible, holder); << 271 fPickMap[fPickName] = holder; << 272 } << 273 << 274 // Because of our need to control colour of << 275 // time fading), display lists may only cove << 276 // So display list setup is here. << 277 << 278 if (fDoNotUseDisplayList) { << 279 << 280 glPushMatrix(); << 281 G4OpenGLTransform3D oglt (fObjectTransform << 282 glMultMatrixd (oglt.GetGLMatrix ()); << 283 if (transparency_enabled) { << 284 glColor4d(c.GetRed(),c.GetGreen(),c.GetB << 285 } else { << 286 glColor3d(c.GetRed(),c.GetGreen(),c.GetB << 287 } << 288 << 289 } else { << 290 137 >> 138 if (fMemoryForDisplayLists) { 291 fDisplayListId = glGenLists (1); 139 fDisplayListId = glGenLists (1); 292 if (glGetError() == GL_OUT_OF_MEMORY) { << 140 if (!fDisplayListId) { // Could pre-allocate? 293 static G4int errorCount = 0; << 141 G4cout << "********************* WARNING! ********************\n" 294 if (errorCount < 5) { << 142 <<"Unable to allocate any more display lists in OpenGL.\n " 295 errorCount++; << 143 << " Continuing drawing in IMMEDIATE MODE.\n" 296 G4ExceptionDescription ed; << 144 << "***************************************************" << G4endl; 297 ed << << 145 fMemoryForDisplayLists = false; 298 "Error attempting to create an OpenGL << 299 "\nCurrent display list id: " << fDisp << 300 "\nMaybe out of memory?"; << 301 G4Exception << 302 ("G4OpenGLStoredSceneHandler::AddPrimi << 303 JustWarning,ed); << 304 } << 305 return false; << 306 } 146 } >> 147 } >> 148 if (fMemoryForDisplayLists) { 307 if (fReadyForTransients) { 149 if (fReadyForTransients) { 308 TO to(fDisplayListId, fObjectTransformat << 150 TO to(fDisplayListId, objectTransformation); 309 if (isPicking) to.fPickName = fPickName; << 310 to.fColour = c; << 311 to.fStartTime = fpVisAttribs->GetStartTi << 312 to.fEndTime = fpVisAttribs->GetEndTime() << 313 to.fMarkerOrPolyline = isMarkerOrPolylin << 314 fTOList.push_back(to); 151 fTOList.push_back(to); 315 // For transient objects, colour, transf << 152 glDrawBuffer (GL_FRONT); 316 // the TO, so should *not* be in the dis << 317 // above, in some cases (display-by-time << 318 // independent control of colour. But f << 319 // colour for immediate display. << 320 glPushMatrix(); 153 glPushMatrix(); 321 G4OpenGLTransform3D oglt (fObjectTransfo << 154 G4OpenGLTransform3D oglt (objectTransformation); 322 glMultMatrixd (oglt.GetGLMatrix ()); 155 glMultMatrixd (oglt.GetGLMatrix ()); 323 if (transparency_enabled) { << 324 glColor4d(c.GetRed(),c.GetGreen(),c.Ge << 325 } else { << 326 glColor3d(c.GetRed(),c.GetGreen(),c.Ge << 327 } << 328 (void) ExtraTOProcessing(visible, fTOLis << 329 // Ignore return value of the above. If << 330 // gl commands, a display list is create << 331 // used. << 332 glNewList (fDisplayListId, GL_COMPILE_AN 156 glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE); 333 } else { << 334 PO po(fDisplayListId, fObjectTransformat << 335 if (isPicking) po.fPickName = fPickName; << 336 po.fColour = c; << 337 po.fMarkerOrPolyline = isMarkerOrPolylin << 338 fPOList.push_back(po); << 339 // For permanent objects, colour is kept << 340 // *not* be in the display list. This i << 341 // may implement colour modifications ac << 342 // criteria, e.g., scene tree slider in << 343 // colour for immediate display. << 344 if (transparency_enabled) { << 345 glColor4d(c.GetRed(),c.GetGreen(),c.Ge << 346 } else { << 347 glColor3d(c.GetRed(),c.GetGreen(),c.Ge << 348 } << 349 G4bool usesGLCommands = ExtraPOProcessin << 350 // Transients are displayed as they come << 351 // above) but persistents are compiled i << 352 // (GL_COMPILE only) and then drawn from << 353 // their fObjectTransformation as stored << 354 // there is no need to do glMultMatrixd << 355 // ExtraPOProcessing says the visible ob << 356 // commands, simply return and abandon f << 357 // is assumed that all relevant informat << 358 // POList. << 359 if (!usesGLCommands) return false; << 360 glNewList (fDisplayListId, GL_COMPILE); << 361 } 157 } 362 } << 158 else { 363 << 159 fPOList.push_back(PO(fDisplayListId, objectTransformation)); 364 if (fProcessing2D) { << 160 glNewList (fDisplayListId, GL_COMPILE); 365 // Push current 3D world matrices and load << 366 // coordinates... << 367 glMatrixMode (GL_PROJECTION); << 368 glPushMatrix(); << 369 glLoadIdentity(); << 370 if (pOGLViewer) { << 371 pOGLViewer->g4GlOrtho (-1., 1., -1., 1., << 372 } 161 } 373 glMatrixMode (GL_MODELVIEW); << 162 } else { >> 163 glDrawBuffer (GL_FRONT); 374 glPushMatrix(); 164 glPushMatrix(); 375 glLoadIdentity(); << 165 G4OpenGLTransform3D oglt (objectTransformation); 376 G4OpenGLTransform3D oglt (fObjectTransform << 377 glMultMatrixd (oglt.GetGLMatrix ()); 166 glMultMatrixd (oglt.GetGLMatrix ()); 378 glDisable (GL_LIGHTING); << 379 } else { << 380 if (isMarker) { << 381 glDisable (GL_LIGHTING); << 382 } else { << 383 glEnable (GL_LIGHTING); << 384 } << 385 } 167 } 386 << 387 return true; << 388 } 168 } 389 169 390 void G4OpenGLStoredSceneHandler::AddPrimitiveP << 170 void G4OpenGLStoredSceneHandler::EndPrimitives () { 391 { << 171 if (fMemoryForDisplayLists) { 392 if (fProcessing2D) { << 393 // Pop current 3D world matrices back agai << 394 glMatrixMode (GL_PROJECTION); << 395 glPopMatrix(); << 396 glMatrixMode (GL_MODELVIEW); << 397 glPopMatrix(); << 398 } << 399 << 400 // if ((glGetError() == GL_TABLE_TOO_LARGE) << 401 if (glGetError() == GL_OUT_OF_MEMORY) { // << 402 G4cerr << << 403 "ERROR: G4OpenGLStoredSceneHandler::AddP << 404 " to allocate display List for fTopPODL << 405 << G4endl; << 406 } << 407 if (!fDoNotUseDisplayList) { << 408 glEndList(); 172 glEndList(); 409 if (glGetError() == GL_OUT_OF_MEMORY) { / << 410 G4cerr << << 411 "ERROR: G4OpenGLStoredSceneHandler::Ad << 412 " to allocate display List for fTopPODL - t << 413 << G4endl; << 414 } << 415 } 173 } 416 if (fReadyForTransients || fDoNotUseDisplayL << 174 if (fReadyForTransients || !fMemoryForDisplayLists) { 417 glPopMatrix(); 175 glPopMatrix(); >> 176 glFlush (); >> 177 glDrawBuffer (GL_BACK); 418 } 178 } >> 179 G4VSceneHandler::EndPrimitives (); 419 } 180 } 420 181 421 void G4OpenGLStoredSceneHandler::AddPrimitive << 182 void G4OpenGLStoredSceneHandler::BeginPrimitives2D() 422 { 183 { 423 G4bool furtherprocessing = AddPrimitivePream << 184 G4VSceneHandler::BeginPrimitives2D(); 424 if (furtherprocessing) { << 425 G4OpenGLSceneHandler::AddPrimitive(polylin << 426 AddPrimitivePostamble(); << 427 } << 428 } << 429 185 430 void G4OpenGLStoredSceneHandler::AddPrimitive << 186 if (fMemoryForDisplayLists) { 431 { << 187 fDisplayListId = glGenLists (1); 432 G4bool furtherprocessing = AddPrimitivePream << 188 if (!fDisplayListId) { // Could pre-allocate? 433 if (furtherprocessing) { << 189 G4cout << "********************* WARNING! ********************\n" 434 G4OpenGLSceneHandler::AddPrimitive(polymar << 190 <<"Unable to allocate any more display lists in OpenGL.\n " 435 AddPrimitivePostamble(); << 191 << " Continuing drawing in IMMEDIATE MODE.\n" >> 192 << "***************************************************" << G4endl; >> 193 fMemoryForDisplayLists = false; >> 194 } 436 } 195 } 437 } << 196 if (fMemoryForDisplayLists) { 438 << 197 if (fReadyForTransients) { 439 void G4OpenGLStoredSceneHandler::AddPrimitive << 198 fTOList.push_back(TO(fDisplayListId)); 440 { << 199 glDrawBuffer (GL_FRONT); 441 // Note: colour is still handled in << 200 glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE); 442 // G4OpenGLSceneHandler::AddPrimitive(const << 201 } 443 // gets into the display list << 202 else { 444 G4bool furtherprocessing = AddPrimitivePream << 203 fPOList.push_back(PO(fDisplayListId)); 445 if (furtherprocessing) { << 204 glNewList (fDisplayListId, GL_COMPILE); 446 G4OpenGLSceneHandler::AddPrimitive(text); << 205 } 447 AddPrimitivePostamble(); << 206 } else { >> 207 glDrawBuffer (GL_FRONT); 448 } 208 } >> 209 // Push current 3D world matrices and load identity to define screen >> 210 // coordinates... >> 211 glMatrixMode (GL_PROJECTION); >> 212 glPushMatrix(); >> 213 glLoadIdentity(); >> 214 glOrtho (-1., 1., -1., 1., -DBL_MAX, DBL_MAX); >> 215 glMatrixMode (GL_MODELVIEW); >> 216 glPushMatrix(); >> 217 glLoadIdentity(); 449 } 218 } 450 219 451 void G4OpenGLStoredSceneHandler::AddPrimitive << 220 void G4OpenGLStoredSceneHandler::EndPrimitives2D () 452 { 221 { 453 G4bool furtherprocessing = AddPrimitivePream << 222 // Pop current 3D world matrices back again... 454 if (furtherprocessing) { << 223 glMatrixMode (GL_PROJECTION); 455 G4OpenGLSceneHandler::AddPrimitive(circle) << 224 glPopMatrix(); 456 AddPrimitivePostamble(); << 225 glMatrixMode (GL_MODELVIEW); 457 } << 226 glPopMatrix(); 458 } << 459 227 460 void G4OpenGLStoredSceneHandler::AddPrimitive << 228 if (fMemoryForDisplayLists) { 461 { << 229 glEndList(); 462 G4bool furtherprocessing = AddPrimitivePream << 463 if (furtherprocessing) { << 464 G4OpenGLSceneHandler::AddPrimitive(square) << 465 AddPrimitivePostamble(); << 466 } 230 } 467 } << 231 if (fReadyForTransients || !fMemoryForDisplayLists) { 468 << 232 glFlush (); 469 void G4OpenGLStoredSceneHandler::AddPrimitive << 233 glDrawBuffer (GL_BACK); 470 { << 471 // Note: colour is still handled in << 472 // G4OpenGLSceneHandler::AddPrimitive(const << 473 // gets into the display list << 474 G4bool furtherprocessing = AddPrimitivePream << 475 if (furtherprocessing) { << 476 G4OpenGLSceneHandler::AddPrimitive(polyhed << 477 AddPrimitivePostamble(); << 478 } 234 } >> 235 G4VSceneHandler::EndPrimitives2D (); 479 } 236 } 480 237 481 void G4OpenGLStoredSceneHandler::BeginModeling 238 void G4OpenGLStoredSceneHandler::BeginModeling () { 482 G4VSceneHandler::BeginModeling(); 239 G4VSceneHandler::BeginModeling(); >> 240 ClearStore(); // ...and all that goes with it. 483 /* Debug... 241 /* Debug... 484 fDisplayListId = glGenLists (1); 242 fDisplayListId = glGenLists (1); 485 G4cout << "OGL::fDisplayListId (start): " << 243 G4cout << "OGL::fDisplayListId (start): " << fDisplayListId << G4endl; 486 */ 244 */ 487 } 245 } 488 246 489 void G4OpenGLStoredSceneHandler::EndModeling ( 247 void G4OpenGLStoredSceneHandler::EndModeling () { 490 // Make a List which calls the other lists. 248 // Make a List which calls the other lists. 491 fTopPODL = glGenLists (1); 249 fTopPODL = glGenLists (1); 492 if (glGetError() == GL_OUT_OF_MEMORY) { // << 250 if (!fTopPODL) { 493 G4cerr << << 251 G4cout << 494 "ERROR: G4OpenGLStoredSceneHandler::EndM 252 "ERROR: G4OpenGLStoredSceneHandler::EndModeling: Failure to allocate" 495 " display List for fTopPODL - try OpenG 253 " display List for fTopPODL - try OpenGL Immediated mode." 496 << G4endl; 254 << G4endl; 497 } else { << 255 } 498 << 256 else { 499 glNewList (fTopPODL, GL_COMPILE); { << 257 glNewList (fTopPODL, GL_COMPILE_AND_EXECUTE); { 500 for (size_t i = 0; i < fPOList.size (); 258 for (size_t i = 0; i < fPOList.size (); i++) { 501 glPushMatrix(); 259 glPushMatrix(); 502 G4OpenGLTransform3D oglt (fPOList[i].fTransf 260 G4OpenGLTransform3D oglt (fPOList[i].fTransform); 503 glMultMatrixd (oglt.GetGLMatrix ()); 261 glMultMatrixd (oglt.GetGLMatrix ()); 504 if (fpViewer->GetViewParameters().IsPicking( << 505 glLoadName(fPOList[i].fPickName); << 506 glCallList (fPOList[i].fDisplayListId); 262 glCallList (fPOList[i].fDisplayListId); 507 glPopMatrix(); 263 glPopMatrix(); 508 } 264 } 509 } 265 } 510 glEndList (); 266 glEndList (); 511 << 512 if (glGetError() == GL_OUT_OF_MEMORY) { / << 513 G4cerr << << 514 "ERROR: G4OpenGLStoredSceneHandler::En << 515 " display List for fTopPODL - try Ope << 516 << G4endl; << 517 } << 518 } 267 } 519 268 520 G4VSceneHandler::EndModeling (); 269 G4VSceneHandler::EndModeling (); >> 270 >> 271 /* Debug... >> 272 fDisplayListId = glGenLists (1); >> 273 G4cout << "OGL::fDisplayListId (end): " << fDisplayListId << G4endl; >> 274 */ 521 } 275 } 522 276 523 void G4OpenGLStoredSceneHandler::ClearStore () 277 void G4OpenGLStoredSceneHandler::ClearStore () { 524 278 525 //G4cout << "G4OpenGLStoredSceneHandler::Cle << 526 << 527 G4VSceneHandler::ClearStore (); // Sets nee 279 G4VSceneHandler::ClearStore (); // Sets need kernel visit, etc. 528 280 529 // Delete OpenGL permanent display lists. 281 // Delete OpenGL permanent display lists. 530 for (size_t i = 0; i < fPOList.size (); i++) 282 for (size_t i = 0; i < fPOList.size (); i++) 531 glDeleteLists (fPOList[i].fDisplayListId, 283 glDeleteLists (fPOList[i].fDisplayListId, 1); 532 if (fTopPODL) glDeleteLists (fTopPODL, 1); 284 if (fTopPODL) glDeleteLists (fTopPODL, 1); 533 fTopPODL = 0; 285 fTopPODL = 0; 534 286 535 // Clear other lists, dictionary, etc. 287 // Clear other lists, dictionary, etc. 536 fPOList.clear (); 288 fPOList.clear (); 537 fSolidMap.clear (); 289 fSolidMap.clear (); 538 ClearAndDestroyAtts(); << 539 290 540 // ...and clear transient store... 291 // ...and clear transient store... 541 for (size_t i = 0; i < fTOList.size (); i++) 292 for (size_t i = 0; i < fTOList.size (); i++) 542 glDeleteLists(fTOList[i].fDisplayListId, 1 293 glDeleteLists(fTOList[i].fDisplayListId, 1); 543 fTOList.clear (); 294 fTOList.clear (); 544 } 295 } 545 296 546 void G4OpenGLStoredSceneHandler::ClearTransien << 297 void G4OpenGLStoredSceneHandler::ClearTransientStore () { 547 { << 298 548 //G4cout << "G4OpenGLStoredSceneHandler::Cle << 299 G4VSceneHandler::ClearTransientStore (); 549 300 550 // Delete OpenGL transient display lists and 301 // Delete OpenGL transient display lists and Transient Objects themselves. 551 for (size_t i = 0; i < fTOList.size (); i++) 302 for (size_t i = 0; i < fTOList.size (); i++) 552 glDeleteLists(fTOList[i].fDisplayListId, 1 303 glDeleteLists(fTOList[i].fDisplayListId, 1); 553 fTOList.clear (); 304 fTOList.clear (); 554 305 555 // Redraw the scene ready for the next event << 306 // Make sure screen corresponds to graphical database... 556 if (fpViewer) { 307 if (fpViewer) { 557 fpViewer -> SetView (); 308 fpViewer -> SetView (); 558 fpViewer -> ClearView (); 309 fpViewer -> ClearView (); 559 fpViewer -> DrawView (); 310 fpViewer -> DrawView (); 560 } 311 } 561 } 312 } >> 313 >> 314 void G4OpenGLStoredSceneHandler::RequestPrimitives (const G4VSolid& solid) >> 315 { >> 316 if (fReadyForTransients) { >> 317 // Always draw transient solids, e.g., hits represented as solids. >> 318 // (As we have no control over the order of drawing of transient >> 319 // objects, we cannot do anything about transparent ones, as >> 320 // below, so always draw them.) >> 321 G4VSceneHandler::RequestPrimitives (solid); >> 322 return; >> 323 } >> 324 >> 325 // For non-transient (run-duration) objects, ensure transparent >> 326 // objects are drawn last. The problem of >> 327 // blending/transparency/alpha is quite a tricky one - see History >> 328 // of opengl-V07-01-01/2/3. >> 329 // Get vis attributes - pick up defaults if none. >> 330 const G4VisAttributes* pVA = >> 331 fpViewer -> GetApplicableVisAttributes(fpVisAttribs); >> 332 const G4Colour& c = pVA -> GetColour (); >> 333 G4double opacity = c.GetAlpha (); >> 334 >> 335 if (!fSecondPass) { >> 336 G4bool transparency_enabled = true; >> 337 G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer); >> 338 if (pViewer) transparency_enabled = pViewer->transparency_enabled; >> 339 if (transparency_enabled && opacity < 1.) { >> 340 // On first pass, transparent objects are not drawn, but flag is set... >> 341 fSecondPassRequested = true; >> 342 return; >> 343 } >> 344 } >> 345 >> 346 // On second pass, opaque objects are not drwan... >> 347 if (fSecondPass && opacity >= 1.) return; >> 348 >> 349 G4PhysicalVolumeModel* pPVModel = >> 350 dynamic_cast<G4PhysicalVolumeModel*>(fpModel); >> 351 >> 352 if (pPVModel) { >> 353 // If part of the geometry hierarchy, i.e., from a >> 354 // G4PhysicalVolumeModel, check if a display list already exists for >> 355 // this solid, re-use it if possible. We could be smarter, and >> 356 // recognise repeated branches of the geometry hierarchy, for >> 357 // example. But this algorithm should be secure, I think... >> 358 const G4VSolid* pSolid = &solid; >> 359 EAxis axis = kRho; >> 360 G4VPhysicalVolume* pCurrentPV = pPVModel->GetCurrentPV(); >> 361 if (pCurrentPV -> IsReplicated ()) { >> 362 G4int nReplicas; >> 363 G4double width; >> 364 G4double offset; >> 365 G4bool consuming; >> 366 pCurrentPV->GetReplicationData(axis,nReplicas,width,offset,consuming); >> 367 } >> 368 // Provided it is not parametrised (because if so, the >> 369 // solid's parameters might have been changed)... >> 370 if (!(pCurrentPV -> IsParameterised ()) && >> 371 // Provided it is not replicated radially (because if so, the >> 372 // solid's parameters will have been changed)... >> 373 !(pCurrentPV -> IsReplicated () && axis == kRho) && >> 374 // ...and if the solid has already been rendered... >> 375 (fSolidMap.find (pSolid) != fSolidMap.end ())) { >> 376 fDisplayListId = fSolidMap [pSolid]; >> 377 fPOList.push_back(PO(fDisplayListId,*fpObjectTransformation)); >> 378 } >> 379 else { >> 380 G4VSceneHandler::RequestPrimitives (solid); >> 381 fSolidMap [pSolid] = fDisplayListId; >> 382 } >> 383 return; >> 384 } >> 385 >> 386 // Otherwise invoke base class method... >> 387 G4VSceneHandler::RequestPrimitives (solid); >> 388 } >> 389 >> 390 G4int G4OpenGLStoredSceneHandler::fSceneIdCount = 0; >> 391 >> 392 #endif 562 393