- Timestamp:
- Nov 9, 2007, 3:32:25 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/geant4/visualization/OpenGL/src/G4OpenGLStoredSceneHandler.cc
r529 r593 25 25 // 26 26 // 27 // $Id: G4OpenGLStoredSceneHandler.cc,v 1.3 1 2006/08/30 11:43:57 allison Exp $28 // GEANT4 tag $Name: geant4-0 8-02-patch-01 $27 // $Id: G4OpenGLStoredSceneHandler.cc,v 1.34 2007/04/04 16:50:27 allison Exp $ 28 // GEANT4 tag $Name: geant4-09-00-ref-01 $ 29 29 // 30 30 // … … 46 46 #include "G4PhysicalVolumeModel.hh" 47 47 #include "G4VPhysicalVolume.hh" 48 #include "G4LogicalVolume.hh" 48 49 #include "G4Polyline.hh" 49 50 #include "G4Polymarker.hh" 51 #include "G4Text.hh" 50 52 #include "G4Circle.hh" 51 53 #include "G4Square.hh" 54 #include "G4Polyhedron.hh" 55 #include "G4AttHolder.hh" 52 56 53 57 G4OpenGLStoredSceneHandler::G4OpenGLStoredSceneHandler (G4VGraphicsSystem& system, … … 56 60 fMemoryForDisplayLists (true), 57 61 fAddPrimitivePreambleNestingDepth (0), 58 fTopPODL (0) 62 fTopPODL (0), 63 fProcessing2D (false) 59 64 {} 60 65 … … 69 74 if (fAddPrimitivePreambleNestingDepth > 1) return; 70 75 76 // Because of our need to control colour of transients (display by 77 // time fading), display lists may only cover a single primitive. 78 // So display list setup is here. 79 80 if (fpViewer->GetViewParameters().IsPicking()) { 81 fPickMap[++fPickName] = 0; 82 } 83 71 84 const G4Colour& c = GetColour (visible); 72 73 if (fMemoryForDisplayLists && fReadyForTransients) {74 75 TO& to = fTOList.back(); // Transient object information.76 77 // Get vis attributes - pick up defaults if none.78 const G4VisAttributes* pVA =79 fpViewer->GetApplicableVisAttributes(visible.GetVisAttributes());80 81 // Get time information from vis attributes.82 to.fStartTime = pVA->GetStartTime();83 to.fEndTime = pVA->GetEndTime();84 85 // Keep colour out of (already started) display list so that it86 // 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 {94 95 // Make sure colour is set in other cases.96 glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());97 }98 }99 100 void G4OpenGLStoredSceneHandler::AddPrimitivePostamble()101 {102 fAddPrimitivePreambleNestingDepth--;103 }104 105 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polyline& polyline)106 {107 AddPrimitivePreamble(polyline);108 G4OpenGLSceneHandler::AddPrimitive(polyline);109 AddPrimitivePostamble();110 }111 112 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Circle& circle)113 {114 AddPrimitivePreamble(circle);115 G4OpenGLSceneHandler::AddPrimitive(circle);116 AddPrimitivePostamble();117 }118 119 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Square& square)120 {121 AddPrimitivePreamble(square);122 G4OpenGLSceneHandler::AddPrimitive(square);123 AddPrimitivePostamble();124 }125 126 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polymarker& polymarker)127 {128 AddPrimitivePreamble(polymarker);129 G4OpenGLSceneHandler::AddPrimitive(polymarker);130 AddPrimitivePostamble();131 }132 133 void G4OpenGLStoredSceneHandler::BeginPrimitives134 (const G4Transform3D& objectTransformation) {135 136 G4VSceneHandler::BeginPrimitives (objectTransformation);137 85 138 86 if (fMemoryForDisplayLists) { 139 87 fDisplayListId = glGenLists (1); 140 88 if (!fDisplayListId) { // Could pre-allocate? 141 G4cout << "********************* WARNING! ********************\n" 142 <<"Unable to allocate any more display lists in OpenGL.\n " 143 << " Continuing drawing in IMMEDIATE MODE.\n" 144 << "***************************************************" << G4endl; 89 G4cout << 90 "********************* WARNING! ********************" 91 "\nUnable to allocate any more display lists in OpenGL." 92 "\n Continuing drawing in IMMEDIATE MODE." 93 "\n***************************************************" 94 << G4endl; 145 95 fMemoryForDisplayLists = false; 146 96 } … … 148 98 if (fMemoryForDisplayLists) { 149 99 if (fReadyForTransients) { 150 TO to(fDisplayListId, objectTransformation); 100 TO to(fDisplayListId, *fpObjectTransformation); 101 to.fPickName = fPickName; 102 to.fColour = c; 103 const G4VisAttributes* pVA = 104 fpViewer->GetApplicableVisAttributes(visible.GetVisAttributes()); 105 to.fStartTime = pVA->GetStartTime(); 106 to.fEndTime = pVA->GetEndTime(); 151 107 fTOList.push_back(to); 152 108 glDrawBuffer (GL_FRONT); 153 109 glPushMatrix(); 154 G4OpenGLTransform3D oglt ( objectTransformation);110 G4OpenGLTransform3D oglt (*fpObjectTransformation); 155 111 glMultMatrixd (oglt.GetGLMatrix ()); 112 glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ()); 156 113 glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE); 157 114 } 158 115 else { 159 fPOList.push_back(PO(fDisplayListId, objectTransformation)); 116 PO po(fDisplayListId, *fpObjectTransformation); 117 po.fPickName = fPickName; 118 fPOList.push_back(po); 160 119 glNewList (fDisplayListId, GL_COMPILE); 120 glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ()); 161 121 } 162 122 } else { 163 123 glDrawBuffer (GL_FRONT); 164 124 glPushMatrix(); 165 G4OpenGLTransform3D oglt ( objectTransformation);125 G4OpenGLTransform3D oglt (*fpObjectTransformation); 166 126 glMultMatrixd (oglt.GetGLMatrix ()); 167 } 168 } 169 170 void G4OpenGLStoredSceneHandler::EndPrimitives () { 127 glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ()); 128 } 129 130 if (fProcessing2D) { 131 // Push current 3D world matrices and load identity to define screen 132 // coordinates... 133 glMatrixMode (GL_PROJECTION); 134 glPushMatrix(); 135 glLoadIdentity(); 136 glOrtho (-1., 1., -1., 1., -G4OPENGL_DBL_MAX, G4OPENGL_DBL_MAX); 137 glMatrixMode (GL_MODELVIEW); 138 glPushMatrix(); 139 glLoadIdentity(); 140 } 141 } 142 143 void G4OpenGLStoredSceneHandler::AddPrimitivePostamble() 144 { 145 if (fProcessing2D) { 146 // Pop current 3D world matrices back again... 147 glMatrixMode (GL_PROJECTION); 148 glPopMatrix(); 149 glMatrixMode (GL_MODELVIEW); 150 glPopMatrix(); 151 } 152 171 153 if (fMemoryForDisplayLists) { 172 154 glEndList(); … … 177 159 glDrawBuffer (GL_BACK); 178 160 } 179 G4VSceneHandler::EndPrimitives (); 161 fAddPrimitivePreambleNestingDepth--; 162 } 163 164 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polyline& polyline) 165 { 166 AddPrimitivePreamble(polyline); 167 G4OpenGLSceneHandler::AddPrimitive(polyline); 168 AddPrimitivePostamble(); 169 } 170 171 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polymarker& polymarker) 172 { 173 AddPrimitivePreamble(polymarker); 174 G4OpenGLSceneHandler::AddPrimitive(polymarker); 175 AddPrimitivePostamble(); 176 } 177 178 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Text& text) 179 { 180 // Note: colour is still handled in 181 // G4OpenGLSceneHandler::AddPrimitive(const G4Text&), so it still 182 // gets into the display list 183 AddPrimitivePreamble(text); 184 G4OpenGLSceneHandler::AddPrimitive(text); 185 AddPrimitivePostamble(); 186 } 187 188 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Circle& circle) 189 { 190 AddPrimitivePreamble(circle); 191 G4OpenGLSceneHandler::AddPrimitive(circle); 192 AddPrimitivePostamble(); 193 } 194 195 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Square& square) 196 { 197 AddPrimitivePreamble(square); 198 G4OpenGLSceneHandler::AddPrimitive(square); 199 AddPrimitivePostamble(); 200 } 201 202 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Scale& scale) 203 { 204 // Let base class split into primitives. 205 G4OpenGLSceneHandler::AddPrimitive(scale); 206 } 207 208 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) 209 { 210 // Note: colour is still handled in 211 // G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&), so it still 212 // gets into the display list 213 AddPrimitivePreamble(polyhedron); 214 G4OpenGLSceneHandler::AddPrimitive(polyhedron); 215 AddPrimitivePostamble(); 216 } 217 218 void G4OpenGLStoredSceneHandler::AddPrimitive (const G4NURBS& nurbs) 219 { 220 // Note: colour is still handled in 221 // G4OpenGLSceneHandler::AddPrimitive(const G4NURBS&), so it still 222 // gets into the display list 223 AddPrimitivePreamble(nurbs); 224 G4OpenGLSceneHandler::AddPrimitive(nurbs); 225 AddPrimitivePostamble(); 226 } 227 228 void G4OpenGLStoredSceneHandler::BeginPrimitives 229 (const G4Transform3D& objectTransformation) 230 { 231 G4OpenGLSceneHandler::BeginPrimitives (objectTransformation); 232 233 // Display list setup moved to AddPrimitivePreamble. See notes there. 234 } 235 236 void G4OpenGLStoredSceneHandler::EndPrimitives () 237 { 238 G4OpenGLSceneHandler::EndPrimitives (); 180 239 } 181 240 182 241 void G4OpenGLStoredSceneHandler::BeginPrimitives2D() 183 242 { 184 G4VSceneHandler::BeginPrimitives2D(); 185 186 if (fMemoryForDisplayLists) { 187 fDisplayListId = glGenLists (1); 188 if (!fDisplayListId) { // Could pre-allocate? 189 G4cout << "********************* WARNING! ********************\n" 190 <<"Unable to allocate any more display lists in OpenGL.\n " 191 << " Continuing drawing in IMMEDIATE MODE.\n" 192 << "***************************************************" << G4endl; 193 fMemoryForDisplayLists = false; 194 } 195 } 196 if (fMemoryForDisplayLists) { 197 if (fReadyForTransients) { 198 fTOList.push_back(TO(fDisplayListId)); 199 glDrawBuffer (GL_FRONT); 200 glNewList (fDisplayListId, GL_COMPILE_AND_EXECUTE); 201 } 202 else { 203 fPOList.push_back(PO(fDisplayListId)); 204 glNewList (fDisplayListId, GL_COMPILE); 205 } 206 } else { 207 glDrawBuffer (GL_FRONT); 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(); 243 G4OpenGLSceneHandler::BeginPrimitives2D(); 244 fProcessing2D = true; 218 245 } 219 246 220 247 void G4OpenGLStoredSceneHandler::EndPrimitives2D () 221 248 { 222 // Pop current 3D world matrices back again... 223 glMatrixMode (GL_PROJECTION); 224 glPopMatrix(); 225 glMatrixMode (GL_MODELVIEW); 226 glPopMatrix(); 227 228 if (fMemoryForDisplayLists) { 229 glEndList(); 230 } 231 if (fReadyForTransients || !fMemoryForDisplayLists) { 232 glFlush (); 233 glDrawBuffer (GL_BACK); 234 } 235 G4VSceneHandler::EndPrimitives2D (); 249 fProcessing2D = false; 250 G4OpenGLSceneHandler::EndPrimitives2D (); 236 251 } 237 252 … … 253 268 " display List for fTopPODL - try OpenGL Immediated mode." 254 269 << G4endl; 255 } 256 else { 270 } else { 257 271 glNewList (fTopPODL, GL_COMPILE_AND_EXECUTE); { 258 272 for (size_t i = 0; i < fPOList.size (); i++) { … … 260 274 G4OpenGLTransform3D oglt (fPOList[i].fTransform); 261 275 glMultMatrixd (oglt.GetGLMatrix ()); 276 if (fpViewer->GetViewParameters().IsPicking()) 277 glLoadName(fPOList[i].fPickName); 262 278 glCallList (fPOList[i].fDisplayListId); 263 279 glPopMatrix(); … … 288 304 fPOList.clear (); 289 305 fSolidMap.clear (); 306 ClearAndDestroyAtts(); 290 307 291 308 // ...and clear transient store... … … 375 392 (fSolidMap.find (pSolid) != fSolidMap.end ())) { 376 393 fDisplayListId = fSolidMap [pSolid]; 377 fPOList.push_back(PO(fDisplayListId,*fpObjectTransformation)); 394 PO po(fDisplayListId,*fpObjectTransformation); 395 if (fpViewer->GetViewParameters().IsPicking()) { 396 G4AttHolder* holder = new G4AttHolder; 397 // Load G4Atts from G4VisAttributes, if any... 398 const G4VisAttributes* va = pPVModel->GetCurrentLV()->GetVisAttributes(); 399 if (va) { 400 const std::map<G4String,G4AttDef>* vaDefs = va->GetAttDefs(); 401 if (vaDefs) holder->AddAtts(va->CreateAttValues(), vaDefs); 402 } 403 // Load G4Atts from G4PhysicalVolumeModel... 404 const std::map<G4String,G4AttDef>* defs = pPVModel->GetAttDefs(); 405 if (defs) holder->AddAtts(pPVModel->CreateCurrentAttValues(), defs); 406 fPickMap[++fPickName] = holder; 407 po.fPickName = fPickName; 408 } 409 fPOList.push_back(po); 378 410 } 379 411 else {
Note: See TracChangeset
for help on using the changeset viewer.