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: G4OpenGLSceneHandler.cc 85263 2014-10-27 08:58:31Z gcosmo $ 27 // 28 // 28 // << 29 // 29 // Andrew Walkden 27th March 1996 30 // Andrew Walkden 27th March 1996 30 // OpenGL stored scene - creates OpenGL displa 31 // OpenGL stored scene - creates OpenGL display lists. 31 // OpenGL immediate scene - draws immediately 32 // OpenGL immediate scene - draws immediately to buffer 32 // (saving space on 33 // (saving space on server). 33 34 >> 35 #ifdef G4VIS_BUILD_OPENGL_DRIVER 34 36 35 # include "G4OpenGLSceneHandler.hh" << 37 #include "G4OpenGLSceneHandler.hh" 36 # include "G4OpenGLViewer.hh" << 38 #include "G4OpenGLViewer.hh" 37 # include "G4OpenGLTransform3D.hh" << 39 #include "G4OpenGLTransform3D.hh" 38 # include "G4Point3D.hh" << 40 #include "G4Point3D.hh" 39 # include "G4Normal3D.hh" << 41 #include "G4Normal3D.hh" 40 # include "G4Transform3D.hh" << 42 #include "G4Transform3D.hh" 41 # include "G4Polyline.hh" << 43 #include "G4Polyline.hh" 42 # include "G4Polymarker.hh" << 44 #include "G4Polymarker.hh" 43 # include "G4Text.hh" << 45 #include "G4Text.hh" 44 # include "G4Circle.hh" << 46 #include "G4Circle.hh" 45 # include "G4Square.hh" << 47 #include "G4Square.hh" 46 # include "G4VMarker.hh" << 48 #include "G4VMarker.hh" 47 # include "G4Polyhedron.hh" << 49 #include "G4Polyhedron.hh" 48 # include "G4VisAttributes.hh" << 50 #include "G4VisAttributes.hh" 49 # include "G4PhysicalVolumeModel.hh" << 51 #include "G4PhysicalVolumeModel.hh" 50 # include "G4VPhysicalVolume.hh" << 52 #include "G4VPhysicalVolume.hh" 51 # include "G4LogicalVolume.hh" << 53 #include "G4LogicalVolume.hh" 52 # include "G4VSolid.hh" << 54 #include "G4VSolid.hh" 53 # include "G4Scene.hh" << 55 #include "G4Scene.hh" 54 # include "G4VisExtent.hh" << 56 #include "G4VisExtent.hh" 55 # include "G4AttHolder.hh" << 57 #include "G4AttHolder.hh" 56 # include "G4PhysicalConstants.hh" << 58 #include "G4PhysicalConstants.hh" 57 # include "G4RunManager.hh" << 58 # include "G4Run.hh" << 59 # include "G4RunManagerFactory.hh" << 60 # include "G4Mesh.hh" << 61 # include "G4PseudoScene.hh" << 62 # include "G4VisManager.hh" << 63 << 64 const GLubyte G4OpenGLSceneHandler::fStippleMa << 65 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 66 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 67 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 68 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 69 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 70 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 71 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 72 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 73 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 74 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 75 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 76 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 77 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 78 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 79 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, << 80 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55 << 81 }; << 82 59 83 G4OpenGLSceneHandler::G4OpenGLSceneHandler (G4 60 G4OpenGLSceneHandler::G4OpenGLSceneHandler (G4VGraphicsSystem& system, 84 G4 61 G4int id, 85 co 62 const G4String& name): 86 G4VSceneHandler (system, id, name), 63 G4VSceneHandler (system, id, name), >> 64 #ifdef G4OPENGL_VERSION_2 >> 65 fEmulate_GL_QUADS(false), >> 66 #endif 87 fPickName(0), 67 fPickName(0), >> 68 // glFlush take about 90% time. Dividing glFlush number by 100 will >> 69 // change the first vis time from 100% to 10+90/100 = 10,9%. >> 70 fEventsDrawInterval(1), >> 71 fEventsWaitingToBeFlushed(0), 88 fThreePassCapable(false), 72 fThreePassCapable(false), 89 fSecondPassForTransparencyRequested(false), 73 fSecondPassForTransparencyRequested(false), 90 fSecondPassForTransparency(false), 74 fSecondPassForTransparency(false), 91 fThirdPassForNonHiddenMarkersRequested(false), 75 fThirdPassForNonHiddenMarkersRequested(false), 92 fThirdPassForNonHiddenMarkers(false), 76 fThirdPassForNonHiddenMarkers(false), 93 fEdgeFlag(true) 77 fEdgeFlag(true) 94 { 78 { 95 } 79 } 96 80 97 G4OpenGLSceneHandler::~G4OpenGLSceneHandler () 81 G4OpenGLSceneHandler::~G4OpenGLSceneHandler () 98 { 82 { 99 ClearStore (); 83 ClearStore (); 100 } 84 } 101 85 >> 86 const GLubyte G4OpenGLSceneHandler::fStippleMaskHashed [128] = { >> 87 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 88 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 89 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 90 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 91 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 92 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 93 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 94 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 95 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 96 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 97 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 98 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 99 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 100 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 101 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55, >> 102 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55 >> 103 }; >> 104 102 void G4OpenGLSceneHandler::ClearAndDestroyAtts 105 void G4OpenGLSceneHandler::ClearAndDestroyAtts() 103 { 106 { 104 std::map<GLuint, G4AttHolder*>::iterator i; 107 std::map<GLuint, G4AttHolder*>::iterator i; 105 for (i = fPickMap.begin(); i != fPickMap.end 108 for (i = fPickMap.begin(); i != fPickMap.end(); ++i) delete i->second; 106 fPickMap.clear(); 109 fPickMap.clear(); 107 } 110 } 108 111 109 G4int G4OpenGLSceneHandler::fEntitiesFlushInte << 110 G4OpenGLSceneHandler::FlushAction << 111 G4OpenGLSceneHandler::fFlushAction = G4OpenGLS << 112 << 113 void G4OpenGLSceneHandler::ScaledFlush() 112 void G4OpenGLSceneHandler::ScaledFlush() 114 { 113 { 115 if (fReadyForTransients) { << 114 fEventsWaitingToBeFlushed++; 116 << 115 if (fEventsWaitingToBeFlushed < fEventsDrawInterval) return; 117 // Drawing transients, e.g., trajectories. << 116 glFlush(); 118 << 117 fEventsWaitingToBeFlushed = 0; 119 if (!fpScene) { << 120 // No scene - shouldn't happen << 121 glFlush(); << 122 return; << 123 } << 124 // Get event from modeling parameters << 125 if (!fpModel) { << 126 // No model - shouldn't happen << 127 glFlush(); << 128 return; << 129 } << 130 const G4ModelingParameters* modelingParame << 131 fpModel->GetModelingParameters(); << 132 if (!modelingParameters) { << 133 // No modeling parameters - shouldn't ha << 134 glFlush(); << 135 return; << 136 } << 137 const G4Event* thisEvent = modelingParamet << 138 if (!thisEvent) { << 139 // No event, so not in event loop. << 140 if (fFlushAction == endOfEvent) { << 141 fFlushAction = endOfRun; << 142 } else if (fFlushAction == NthEvent) { << 143 fFlushAction = NthPrimitive; << 144 } << 145 } << 146 G4RunManager* runMan = G4RunManagerFactory << 147 if (!runMan) { << 148 // No run manager - shouldn't happen << 149 glFlush(); << 150 return; << 151 } << 152 const G4Run* thisRun = runMan->GetCurrentR << 153 if (!thisRun) { << 154 // No run, so not in event loop. << 155 if (fFlushAction == endOfRun) { << 156 fFlushAction = NthPrimitive; << 157 } else if (fFlushAction == NthEvent) { << 158 fFlushAction = NthPrimitive; << 159 } << 160 } << 161 << 162 switch (fFlushAction) { << 163 case endOfEvent: << 164 // If "/vis/scene/endOfEventAction ref << 165 // end of run anyway, so only scale if << 166 if (!fpScene->GetRefreshAtEndOfEvent() << 167 // But if "/vis/scene/endOfEventActi << 168 // called until end of run, so we ha << 169 // Get event from modeling parameter << 170 G4int thisEventID = thisEvent->GetEv << 171 static G4int lastEventID = 0; << 172 if (thisEventID != lastEventID) { << 173 glFlush(); << 174 lastEventID = thisEventID; << 175 } << 176 } << 177 break; << 178 case endOfRun: << 179 // If "/vis/scene/endOfRunAction refre << 180 // end of run anyway, so only scale if << 181 if (!fpScene->GetRefreshAtEndOfRun()) << 182 // If "/vis/scene/endOfRunAction acc << 183 // so we have to watch for a new run << 184 G4int thisRunID = thisRun->GetRunID( << 185 static G4int lastRunID = 0; << 186 if (thisRunID != lastRunID) { << 187 glFlush(); << 188 lastRunID = thisRunID; << 189 } << 190 } << 191 break; << 192 case eachPrimitive: << 193 // This is equivalent to numeric with << 194 fEntitiesFlushInterval = 1; << 195 [[fallthrough]]; // Fall through to NthPrim << 196 case NthPrimitive: << 197 { // Encapsulate in scope {} brackets to << 198 static G4int primitivesWaitingToBeFlus << 199 primitivesWaitingToBeFlushed++; << 200 if (primitivesWaitingToBeFlushed < fEn << 201 glFlush(); << 202 primitivesWaitingToBeFlushed = 0; << 203 break; << 204 } << 205 case NthEvent: << 206 // If "/vis/scene/endOfEventAction ref << 207 // end of event anyway, so only scale << 208 if (!fpScene->GetRefreshAtEndOfEvent() << 209 G4int thisEventID = thisEvent->GetEv << 210 static G4int lastEventID = 0; << 211 if (thisEventID != lastEventID) { << 212 static G4int eventsWaitingToBeFlus << 213 eventsWaitingToBeFlushed++; << 214 if (eventsWaitingToBeFlushed < fEn << 215 glFlush(); << 216 eventsWaitingToBeFlushed = 0; << 217 lastEventID = thisEventID; << 218 } << 219 } << 220 break; << 221 case never: << 222 break; << 223 default: << 224 break; << 225 } << 226 << 227 } << 228 << 229 else << 230 << 231 { << 232 << 233 // For run duration model drawing (detecto << 234 // Immediate mode: a huge speed up is obta << 235 // Stored mode: no discernable difference << 236 // back buffer and then swapped. << 237 // So eachPrimitive and NthPrimitive make << 238 // endOfRun are treated as "no action", i. << 239 // as happens anyway, when drawing is comp << 240 << 241 switch (fFlushAction) { << 242 case endOfEvent: << 243 break; << 244 case endOfRun: << 245 break; << 246 case eachPrimitive: << 247 // This is equivalent to NthPrimitive << 248 fEntitiesFlushInterval = 1; << 249 [[fallthrough]]; // Fall through to NthPrim << 250 case NthPrimitive: << 251 { // Encapsulate in scope {} brackets to << 252 static G4int primitivesWaitingToBeFlus << 253 primitivesWaitingToBeFlushed++; << 254 if (primitivesWaitingToBeFlushed < fEn << 255 glFlush(); << 256 primitivesWaitingToBeFlushed = 0; << 257 break; << 258 } << 259 case NthEvent: << 260 break; << 261 case never: << 262 break; << 263 default: << 264 break; << 265 } << 266 << 267 } << 268 } 118 } 269 119 270 void G4OpenGLSceneHandler::ProcessScene() 120 void G4OpenGLSceneHandler::ProcessScene() 271 { 121 { 272 fThreePassCapable = true; 122 fThreePassCapable = true; 273 123 274 G4VSceneHandler::ProcessScene(); 124 G4VSceneHandler::ProcessScene(); 275 125 276 // Repeat if required... 126 // Repeat if required... 277 if (fSecondPassForTransparencyRequested) { 127 if (fSecondPassForTransparencyRequested) { 278 fSecondPassForTransparency = true; 128 fSecondPassForTransparency = true; 279 G4VSceneHandler::ProcessScene(); 129 G4VSceneHandler::ProcessScene(); 280 fSecondPassForTransparency = false; 130 fSecondPassForTransparency = false; 281 fSecondPassForTransparencyRequested = fals 131 fSecondPassForTransparencyRequested = false; 282 } 132 } 283 133 284 // And again if required... 134 // And again if required... 285 if (fThirdPassForNonHiddenMarkersRequested) 135 if (fThirdPassForNonHiddenMarkersRequested) { 286 fThirdPassForNonHiddenMarkers = true; 136 fThirdPassForNonHiddenMarkers = true; 287 G4VSceneHandler::ProcessScene(); 137 G4VSceneHandler::ProcessScene(); 288 fThirdPassForNonHiddenMarkers = false; 138 fThirdPassForNonHiddenMarkers = false; 289 fThirdPassForNonHiddenMarkersRequested = f 139 fThirdPassForNonHiddenMarkersRequested = false; 290 } 140 } 291 141 292 fThreePassCapable = false; 142 fThreePassCapable = false; 293 } 143 } 294 144 295 void G4OpenGLSceneHandler::PreAddSolid 145 void G4OpenGLSceneHandler::PreAddSolid 296 (const G4Transform3D& objectTransformation, 146 (const G4Transform3D& objectTransformation, 297 const G4VisAttributes& visAttribs) 147 const G4VisAttributes& visAttribs) 298 { 148 { 299 G4VSceneHandler::PreAddSolid (objectTransfor 149 G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs); 300 } 150 } 301 151 302 void G4OpenGLSceneHandler::BeginPrimitives 152 void G4OpenGLSceneHandler::BeginPrimitives 303 (const G4Transform3D& objectTransformation) 153 (const G4Transform3D& objectTransformation) 304 { 154 { 305 G4VSceneHandler::BeginPrimitives (objectTran 155 G4VSceneHandler::BeginPrimitives (objectTransformation); 306 } 156 } 307 157 308 void G4OpenGLSceneHandler::EndPrimitives () 158 void G4OpenGLSceneHandler::EndPrimitives () 309 { 159 { 310 G4VSceneHandler::EndPrimitives (); 160 G4VSceneHandler::EndPrimitives (); 311 } 161 } 312 162 313 void G4OpenGLSceneHandler::BeginPrimitives2D 163 void G4OpenGLSceneHandler::BeginPrimitives2D 314 (const G4Transform3D& objectTransformation) 164 (const G4Transform3D& objectTransformation) 315 { 165 { 316 G4VSceneHandler::BeginPrimitives2D (objectTr 166 G4VSceneHandler::BeginPrimitives2D (objectTransformation); 317 } 167 } 318 168 319 void G4OpenGLSceneHandler::EndPrimitives2D () 169 void G4OpenGLSceneHandler::EndPrimitives2D () 320 { 170 { 321 G4VSceneHandler::EndPrimitives2D (); 171 G4VSceneHandler::EndPrimitives2D (); 322 } 172 } 323 173 324 G4DisplacedSolid* G4OpenGLSceneHandler::Create << 174 G4VSolid* G4OpenGLSceneHandler::CreateSectionSolid () 325 { 175 { 326 return G4VSceneHandler::CreateSectionSolid() << 176 // Clipping done in G4OpenGLViewer::SetView. 327 // If clipping done in G4OpenGLViewer::SetVi << 328 // return 0; 177 // return 0; 329 // Note: if you change this, you must also c << 178 330 // G4OpenGLStoredViewer::CompareForKernelVis << 179 // But...OpenGL no longer seems to reconstruct clipped edges, so, >> 180 // when the BooleanProcessor is up to it, abandon this and use >> 181 // generic clipping in G4VSceneHandler::CreateSectionSolid... >> 182 return G4VSceneHandler::CreateSectionSolid(); 331 } 183 } 332 184 333 G4DisplacedSolid* G4OpenGLSceneHandler::Create << 185 G4VSolid* G4OpenGLSceneHandler::CreateCutawaySolid () 334 { 186 { 335 // return G4VSceneHandler::CreateCutawaySoli << 187 // Cutaway done in G4OpenGLViewer::SetView. 336 // If cutaway done in G4OpenGLViewer::SetVie << 188 // return 0; 337 return 0; << 189 338 // Note: if you change this, you must also c << 190 // But...if not, when the BooleanProcessor is up to it... 339 // G4OpenGLStoredViewer::CompareForKernelVis << 191 return G4VSceneHandler::CreateCutawaySolid(); 340 } 192 } 341 193 342 void G4OpenGLSceneHandler::AddPrimitive (const 194 void G4OpenGLSceneHandler::AddPrimitive (const G4Polyline& line) 343 { 195 { 344 std::size_t nPoints = line.size (); << 196 G4int nPoints = line.size (); 345 if (nPoints <= 0) return; 197 if (nPoints <= 0) return; 346 198 347 // Note: colour and depth test treated in su 199 // Note: colour and depth test treated in sub-class. 348 200 >> 201 #ifndef G4OPENGL_VERSION_2 349 glDisable (GL_LIGHTING); 202 glDisable (GL_LIGHTING); >> 203 #endif 350 204 351 G4double lineWidth = GetLineWidth(fpVisAttri << 205 // Get vis attributes - pick up defaults if none. >> 206 const G4VisAttributes* pVA = >> 207 fpViewer -> GetApplicableVisAttributes (line.GetVisAttributes ()); >> 208 >> 209 G4double lineWidth = GetLineWidth(pVA); 352 // Need access to method in G4OpenGLViewer. 210 // Need access to method in G4OpenGLViewer. static_cast doesn't 353 // work with a virtual base class, so use dy 211 // work with a virtual base class, so use dynamic_cast. No need to 354 // test the outcome since viewer is guarante 212 // test the outcome since viewer is guaranteed to be a 355 // G4OpenGLViewer, but test it anyway to kee 213 // G4OpenGLViewer, but test it anyway to keep Coverity happy. 356 G4OpenGLViewer* pGLViewer = dynamic_cast<G4O 214 G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer); 357 if (pGLViewer) pGLViewer->ChangeLineWidth(li 215 if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth); 358 216 359 fEdgeFlag = true; 217 fEdgeFlag = true; >> 218 #ifndef G4OPENGL_VERSION_2 360 glBegin (GL_LINE_STRIP); 219 glBegin (GL_LINE_STRIP); 361 // No ned glEdgeFlag for lines : 220 // No ned glEdgeFlag for lines : 362 // Boundary and nonboundary edge flags on ve 221 // Boundary and nonboundary edge flags on vertices are significant only if GL_POLYGON_MODE is set to GL_POINT or GL_LINE. See glPolygonMode. 363 222 364 // glEdgeFlag (GL_TRUE); 223 // glEdgeFlag (GL_TRUE); 365 for (std::size_t iPoint = 0; iPoint < nPoint << 224 for (G4int iPoint = 0; iPoint < nPoints; iPoint++) { 366 G4double x, y, z; 225 G4double x, y, z; 367 x = line[iPoint].x(); 226 x = line[iPoint].x(); 368 y = line[iPoint].y(); 227 y = line[iPoint].y(); 369 z = line[iPoint].z(); 228 z = line[iPoint].z(); 370 glVertex3d (x, y, z); 229 glVertex3d (x, y, z); 371 } 230 } 372 glEnd (); 231 glEnd (); >> 232 #else >> 233 glBeginVBO(GL_LINE_STRIP); >> 234 >> 235 for (G4int iPoint = 0; iPoint < nPoints; iPoint++) { >> 236 fOglVertex.push_back(line[iPoint].x()); >> 237 fOglVertex.push_back(line[iPoint].y()); >> 238 fOglVertex.push_back(line[iPoint].z()); >> 239 // normal >> 240 fOglVertex.push_back(0); >> 241 fOglVertex.push_back(0); >> 242 fOglVertex.push_back(1); >> 243 } >> 244 >> 245 glEndVBO(); >> 246 #endif 373 } 247 } 374 248 375 void G4OpenGLSceneHandler::AddPrimitive (const 249 void G4OpenGLSceneHandler::AddPrimitive (const G4Polymarker& polymarker) 376 { 250 { 377 if (polymarker.size() == 0) { 251 if (polymarker.size() == 0) { 378 return; 252 return; 379 } 253 } 380 254 381 // Note: colour and depth test treated in su 255 // Note: colour and depth test treated in sub-class. 382 256 >> 257 #ifndef G4OPENGL_VERSION_2 383 glDisable (GL_LIGHTING); 258 glDisable (GL_LIGHTING); >> 259 #endif 384 260 >> 261 // Get vis attributes - pick up defaults if none. >> 262 const G4VisAttributes* pVA = >> 263 fpViewer -> GetApplicableVisAttributes (polymarker.GetVisAttributes ()); >> 264 385 MarkerSizeType sizeType; 265 MarkerSizeType sizeType; 386 G4double size = GetMarkerSize(polymarker, si 266 G4double size = GetMarkerSize(polymarker, sizeType); 387 267 388 // Need access to method in G4OpenGLViewer. 268 // Need access to method in G4OpenGLViewer. static_cast doesn't 389 // work with a virtual base class, so use dy 269 // work with a virtual base class, so use dynamic_cast. No need to 390 // test the outcome since viewer is guarante 270 // test the outcome since viewer is guaranteed to be a 391 // G4OpenGLViewer, but test it anyway to kee 271 // G4OpenGLViewer, but test it anyway to keep Coverity happy. 392 G4OpenGLViewer* pGLViewer = dynamic_cast<G4O 272 G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer); 393 if (!pGLViewer) return; 273 if (!pGLViewer) return; 394 274 395 if (sizeType == world) { // Size specified 275 if (sizeType == world) { // Size specified in world coordinates. 396 G4double lineWidth = GetLineWidth(fpVisAtt << 276 G4double lineWidth = GetLineWidth(pVA); 397 pGLViewer->ChangeLineWidth(lineWidth); 277 pGLViewer->ChangeLineWidth(lineWidth); 398 278 399 G4VMarker::FillStyle style = polymarker.Ge 279 G4VMarker::FillStyle style = polymarker.GetFillStyle(); 400 280 401 // G4bool filled = false; Not actually us 281 // G4bool filled = false; Not actually used - comment out to prevent compiler warnings (JA). 402 static G4bool hashedWarned = false; 282 static G4bool hashedWarned = false; 403 283 404 switch (style) { 284 switch (style) { 405 case G4VMarker::noFill: 285 case G4VMarker::noFill: 406 glPolygonMode (GL_FRONT_AND_BACK, GL_L 286 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 407 glEdgeFlag (GL_TRUE); 287 glEdgeFlag (GL_TRUE); 408 //filled = false; 288 //filled = false; 409 break; 289 break; 410 case G4VMarker::hashed: 290 case G4VMarker::hashed: 411 if (!hashedWarned) { 291 if (!hashedWarned) { 412 G4cout << "Hashed fill style in G4Op 292 G4cout << "Hashed fill style in G4OpenGLSceneHandler." 413 << "\n Not implemented. Using G4VM 293 << "\n Not implemented. Using G4VMarker::filled." 414 << G4endl; 294 << G4endl; 415 hashedWarned = true; 295 hashedWarned = true; 416 } 296 } 417 // Maybe use 297 // Maybe use 418 //glPolygonStipple (fStippleMaskHashed 298 //glPolygonStipple (fStippleMaskHashed); 419 [[fallthrough]]; // Drop through to filled << 299 // Drop through to filled... 420 case G4VMarker::filled: 300 case G4VMarker::filled: 421 glPolygonMode (GL_FRONT_AND_BACK, GL_F 301 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 422 //filled = true; 302 //filled = true; 423 break; 303 break; 424 } 304 } 425 } 305 } 426 306 427 // Draw... 307 // Draw... 428 if (sizeType == world) { // Size specified 308 if (sizeType == world) { // Size specified in world coordinates. 429 309 430 G4int nSides; 310 G4int nSides; 431 G4double startPhi; 311 G4double startPhi; 432 switch (polymarker.GetMarkerType()) { 312 switch (polymarker.GetMarkerType()) { 433 default: 313 default: 434 case G4Polymarker::dots: 314 case G4Polymarker::dots: 435 size = 1.; << 315 size = 1.; 436 [[fallthrough]]; // Fall through to circles << 316 // Drop through to circles 437 case G4Polymarker::circles: 317 case G4Polymarker::circles: 438 nSides = GetNoOfSides(fpVisAttribs); << 318 nSides = GetNoOfSides(pVA); 439 startPhi = 0.; 319 startPhi = 0.; 440 break; 320 break; 441 case G4Polymarker::squares: 321 case G4Polymarker::squares: 442 nSides = 4; 322 nSides = 4; 443 startPhi = -pi / 4.; 323 startPhi = -pi / 4.; 444 break; 324 break; 445 } 325 } 446 326 447 const G4Vector3D& viewpointDirection = 327 const G4Vector3D& viewpointDirection = 448 fpViewer -> GetViewParameters().GetViewp 328 fpViewer -> GetViewParameters().GetViewpointDirection(); 449 const G4Vector3D& up = fpViewer->GetViewPa 329 const G4Vector3D& up = fpViewer->GetViewParameters().GetUpVector(); 450 const G4double dPhi = twopi / nSides; 330 const G4double dPhi = twopi / nSides; 451 const G4double radius = size / 2.; 331 const G4double radius = size / 2.; 452 G4Vector3D start = radius * (up.cross(view 332 G4Vector3D start = radius * (up.cross(viewpointDirection)).unit(); 453 G4double phi; 333 G4double phi; 454 G4int i; 334 G4int i; 455 for (size_t iPoint = 0; iPoint < polymarke 335 for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) { 456 fEdgeFlag = true; 336 fEdgeFlag = true; >> 337 #ifndef G4OPENGL_VERSION_2 457 glBegin (GL_POLYGON); 338 glBegin (GL_POLYGON); 458 for (i = 0, phi = startPhi; i < nSides; 339 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) { 459 G4Vector3D r = start; r.rotate(phi, viewpoin 340 G4Vector3D r = start; r.rotate(phi, viewpointDirection); 460 G4Vector3D p = polymarker[iPoint] + r; 341 G4Vector3D p = polymarker[iPoint] + r; 461 glVertex3d (p.x(), p.y(), p.z()); 342 glVertex3d (p.x(), p.y(), p.z()); 462 } 343 } 463 glEnd (); 344 glEnd (); >> 345 #else >> 346 glBeginVBO (GL_TRIANGLE_STRIP); >> 347 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) { >> 348 G4Vector3D r = start; r.rotate(phi, viewpointDirection); >> 349 G4Vector3D p = polymarker[iPoint] + r; >> 350 >> 351 #ifdef G4DEBUG_VIS_OGL >> 352 printf(".....G4OpenGLSceneHandler::AddPrimitive polyhedron QUADS VBO 5\n"); >> 353 #endif >> 354 fOglVertex.push_back(p.x()); >> 355 fOglVertex.push_back(p.y()); >> 356 fOglVertex.push_back(p.z()); >> 357 // normal >> 358 fOglVertex.push_back(0); >> 359 fOglVertex.push_back(0); >> 360 fOglVertex.push_back(1); >> 361 } >> 362 glEndVBO (); >> 363 #endif 464 } 364 } 465 365 466 } else { // Size specified in screen (window 366 } else { // Size specified in screen (window) coordinates. 467 367 468 pGLViewer->ChangePointSize(size); 368 pGLViewer->ChangePointSize(size); 469 369 470 //Antialiasing only for circles 370 //Antialiasing only for circles >> 371 #ifndef G4OPENGL_VERSION_2 471 switch (polymarker.GetMarkerType()) { 372 switch (polymarker.GetMarkerType()) { 472 default: 373 default: 473 case G4Polymarker::dots: 374 case G4Polymarker::dots: 474 case G4Polymarker::circles: 375 case G4Polymarker::circles: 475 glEnable (GL_POINT_SMOOTH); break; 376 glEnable (GL_POINT_SMOOTH); break; 476 case G4Polymarker::squares: 377 case G4Polymarker::squares: 477 glDisable (GL_POINT_SMOOTH); break; 378 glDisable (GL_POINT_SMOOTH); break; 478 } 379 } >> 380 #endif >> 381 #ifndef G4OPENGL_VERSION_2 479 glBegin (GL_POINTS); 382 glBegin (GL_POINTS); 480 for (size_t iPoint = 0; iPoint < polymarke 383 for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) { 481 G4Point3D centre = polymarker[iPoint]; 384 G4Point3D centre = polymarker[iPoint]; 482 glVertex3d(centre.x(),centre.y(),centre. 385 glVertex3d(centre.x(),centre.y(),centre.z()); 483 } 386 } 484 glEnd(); 387 glEnd(); >> 388 #else >> 389 glBeginVBO(GL_POINTS); >> 390 >> 391 for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) { >> 392 fOglVertex.push_back(polymarker[iPoint].x()); >> 393 fOglVertex.push_back(polymarker[iPoint].y()); >> 394 fOglVertex.push_back(polymarker[iPoint].z()); >> 395 fOglVertex.push_back(0); >> 396 fOglVertex.push_back(0); >> 397 fOglVertex.push_back(1); >> 398 } >> 399 glEndVBO(); >> 400 #endif 485 } 401 } 486 } 402 } 487 403 488 void G4OpenGLSceneHandler::AddPrimitive (const 404 void G4OpenGLSceneHandler::AddPrimitive (const G4Text& text) { 489 // Pass to specific viewer via virtual funct 405 // Pass to specific viewer via virtual function DrawText. >> 406 // FIXME : Not ready for OPENGL2 for the moment >> 407 #ifdef G4OPENGL_VERSION_2 >> 408 return; >> 409 #endif 490 G4OpenGLViewer* pGLViewer = dynamic_cast<G4O 410 G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer); 491 if (pGLViewer) pGLViewer->DrawText(text); 411 if (pGLViewer) pGLViewer->DrawText(text); 492 } 412 } 493 413 494 void G4OpenGLSceneHandler::AddPrimitive (const 414 void G4OpenGLSceneHandler::AddPrimitive (const G4Circle& circle) { 495 G4Polymarker oneCircle(circle); 415 G4Polymarker oneCircle(circle); 496 oneCircle.push_back(circle.GetPosition()); 416 oneCircle.push_back(circle.GetPosition()); 497 oneCircle.SetMarkerType(G4Polymarker::circle 417 oneCircle.SetMarkerType(G4Polymarker::circles); 498 // Call this AddPrimitive to avoid re-doing 418 // Call this AddPrimitive to avoid re-doing sub-class code. 499 G4OpenGLSceneHandler::AddPrimitive(oneCircle 419 G4OpenGLSceneHandler::AddPrimitive(oneCircle); 500 } 420 } 501 421 502 void G4OpenGLSceneHandler::AddPrimitive (const 422 void G4OpenGLSceneHandler::AddPrimitive (const G4Square& square) { 503 G4Polymarker oneSquare(square); 423 G4Polymarker oneSquare(square); 504 oneSquare.push_back(square.GetPosition()); 424 oneSquare.push_back(square.GetPosition()); 505 oneSquare.SetMarkerType(G4Polymarker::square 425 oneSquare.SetMarkerType(G4Polymarker::squares); 506 // Call this AddPrimitive to avoid re-doing 426 // Call this AddPrimitive to avoid re-doing sub-class code. 507 G4OpenGLSceneHandler::AddPrimitive(oneSquare 427 G4OpenGLSceneHandler::AddPrimitive(oneSquare); 508 } 428 } 509 429 >> 430 void G4OpenGLSceneHandler::AddPrimitive (const G4Scale& scale) >> 431 { >> 432 G4VSceneHandler::AddPrimitive(scale); >> 433 } >> 434 510 //Method for handling G4Polyhedron objects for 435 //Method for handling G4Polyhedron objects for drawing solids. 511 void G4OpenGLSceneHandler::AddPrimitive (const 436 void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) { 512 437 513 // Assume all facets are planar convex quadr 438 // Assume all facets are planar convex quadrilaterals. 514 // Draw each facet individually 439 // Draw each facet individually 515 440 516 if (polyhedron.GetNoFacets() == 0) return; 441 if (polyhedron.GetNoFacets() == 0) return; 517 442 518 // Need access to data in G4OpenGLViewer. s 443 // Need access to data in G4OpenGLViewer. static_cast doesn't work 519 // with a virtual base class, so use dynamic 444 // with a virtual base class, so use dynamic_cast. 520 G4OpenGLViewer* pGLViewer = dynamic_cast<G4O 445 G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer); 521 if (!pGLViewer) return; 446 if (!pGLViewer) return; 522 447 >> 448 // Get vis attributes - pick up defaults if none. >> 449 const G4VisAttributes* pVA = >> 450 fpViewer -> GetApplicableVisAttributes (polyhedron.GetVisAttributes ()); >> 451 523 // Get view parameters that the user can for 452 // Get view parameters that the user can force through the vis 524 // attributes, thereby over-riding the curre 453 // attributes, thereby over-riding the current view parameter. 525 G4ViewParameters::DrawingStyle drawing_style << 454 G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA); 526 455 527 // Note that in stored mode, because this ca 456 // Note that in stored mode, because this call gets embedded in a display 528 // list, it is the colour _at the time of_ 457 // list, it is the colour _at the time of_ creation of the display list, so 529 // even if the colour is changed, for examp 458 // even if the colour is changed, for example, by interaction with a Qt 530 // window, current_colour does not change. 459 // window, current_colour does not change. 531 GLfloat* painting_colour; 460 GLfloat* painting_colour; 532 GLfloat clear_colour[4]; << 461 GLfloat current_colour [4]; 533 GLfloat current_colour[4]; << 534 glGetFloatv (GL_CURRENT_COLOR, current_colou 462 glGetFloatv (GL_CURRENT_COLOR, current_colour); 535 463 536 G4bool isTransparent = false; 464 G4bool isTransparent = false; 537 if (current_colour[3] < 1.) { // This objec 465 if (current_colour[3] < 1.) { // This object is transparent 538 isTransparent = true; 466 isTransparent = true; 539 } 467 } 540 468 >> 469 541 if (drawing_style == G4ViewParameters::hlr) 470 if (drawing_style == G4ViewParameters::hlr) { 542 // This is the colour used to paint surfac 471 // This is the colour used to paint surfaces in hlr mode. >> 472 GLfloat clear_colour[4]; 543 glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_c 473 glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_colour); 544 painting_colour = clear_colour; 474 painting_colour = clear_colour; 545 } else { // drawing_style == G4ViewParamete 475 } else { // drawing_style == G4ViewParameters::hlhsr 546 painting_colour = current_colour; 476 painting_colour = current_colour; 547 } 477 } 548 478 549 G4double lineWidth = GetLineWidth(fpVisAttri << 479 G4double lineWidth = GetLineWidth(pVA); 550 pGLViewer->ChangeLineWidth(lineWidth); 480 pGLViewer->ChangeLineWidth(lineWidth); 551 481 552 G4bool isAuxEdgeVisible = GetAuxEdgeVisible << 482 G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA); 553 483 554 G4bool clipping = pGLViewer->fVP.IsSection() 484 G4bool clipping = pGLViewer->fVP.IsSection() || pGLViewer->fVP.IsCutaway(); 555 485 556 // Lighting disabled unless otherwise reques 486 // Lighting disabled unless otherwise requested >> 487 #ifndef G4OPENGL_VERSION_2 557 glDisable (GL_LIGHTING); 488 glDisable (GL_LIGHTING); >> 489 #endif 558 490 559 switch (drawing_style) { 491 switch (drawing_style) { 560 case (G4ViewParameters::hlhsr): 492 case (G4ViewParameters::hlhsr): 561 // Set up as for hidden line removal but p 493 // Set up as for hidden line removal but paint polygon faces later... 562 case (G4ViewParameters::hlr): 494 case (G4ViewParameters::hlr): 563 glEnable (GL_STENCIL_TEST); 495 glEnable (GL_STENCIL_TEST); 564 // The stencil buffer is cleared in G4Open 496 // The stencil buffer is cleared in G4OpenGLViewer::ClearView. 565 // The procedure below leaves it clear. 497 // The procedure below leaves it clear. 566 glStencilFunc (GL_ALWAYS, 0, 1); 498 glStencilFunc (GL_ALWAYS, 0, 1); 567 glStencilOp (GL_INVERT, GL_INVERT, GL_INVE 499 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT); 568 glEnable (GL_DEPTH_TEST); 500 glEnable (GL_DEPTH_TEST); 569 glDepthFunc (GL_LEQUAL); 501 glDepthFunc (GL_LEQUAL); 570 if (isTransparent) { 502 if (isTransparent) { 571 // Transparent... 503 // Transparent... 572 glColorMaterial(GL_FRONT_AND_BACK, GL_AM 504 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); 573 glEnable(GL_COLOR_MATERIAL); 505 glEnable(GL_COLOR_MATERIAL); 574 //glDisable (GL_CULL_FACE); << 506 glDisable (GL_CULL_FACE); 575 glPolygonMode (GL_FRONT_AND_BACK, GL_LIN 507 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 576 } else { 508 } else { 577 // Opaque... 509 // Opaque... 578 if (clipping) { 510 if (clipping) { 579 glColorMaterial(GL_FRONT_AND_BACK, GL_ 511 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); 580 glEnable(GL_COLOR_MATERIAL); 512 glEnable(GL_COLOR_MATERIAL); 581 //glDisable (GL_CULL_FACE); << 513 glDisable (GL_CULL_FACE); 582 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 514 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 583 } else { 515 } else { 584 glColorMaterial(GL_FRONT, GL_AMBIENT_A 516 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); 585 glEnable(GL_COLOR_MATERIAL); 517 glEnable(GL_COLOR_MATERIAL); 586 //glEnable (GL_CULL_FACE); << 518 glEnable (GL_CULL_FACE); 587 //glCullFace (GL_BACK); << 519 glCullFace (GL_BACK); 588 glPolygonMode (GL_FRONT, GL_LINE); 520 glPolygonMode (GL_FRONT, GL_LINE); 589 } 521 } 590 } 522 } 591 break; 523 break; 592 case (G4ViewParameters::hsr): 524 case (G4ViewParameters::hsr): 593 glEnable (GL_DEPTH_TEST); 525 glEnable (GL_DEPTH_TEST); 594 glDepthFunc (GL_LEQUAL); 526 glDepthFunc (GL_LEQUAL); 595 if (isTransparent) { 527 if (isTransparent) { 596 // Transparent... 528 // Transparent... 597 glDepthMask (GL_FALSE); // Make depth b 529 glDepthMask (GL_FALSE); // Make depth buffer read-only. 598 glColorMaterial(GL_FRONT_AND_BACK, GL_AM 530 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); >> 531 #ifndef G4OPENGL_VERSION_2 599 glEnable(GL_COLOR_MATERIAL); 532 glEnable(GL_COLOR_MATERIAL); 600 //glDisable (GL_CULL_FACE); << 533 #endif >> 534 glDisable (GL_CULL_FACE); 601 glPolygonMode (GL_FRONT_AND_BACK, GL_FIL 535 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 602 } else { 536 } else { 603 // Opaque... 537 // Opaque... 604 glDepthMask (GL_TRUE); // Make depth bu 538 glDepthMask (GL_TRUE); // Make depth buffer writable (default). 605 if (clipping) { 539 if (clipping) { 606 glColorMaterial(GL_FRONT_AND_BACK, GL_ 540 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); 607 glEnable(GL_COLOR_MATERIAL); 541 glEnable(GL_COLOR_MATERIAL); 608 //glDisable (GL_CULL_FACE); << 542 glDisable (GL_CULL_FACE); 609 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 543 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 610 } else { 544 } else { 611 glColorMaterial(GL_FRONT, GL_AMBIENT_A 545 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); >> 546 #ifndef G4OPENGL_VERSION_2 612 glEnable(GL_COLOR_MATERIAL); 547 glEnable(GL_COLOR_MATERIAL); 613 //glEnable (GL_CULL_FACE); << 548 #endif 614 //glCullFace (GL_BACK); << 549 glEnable (GL_CULL_FACE); >> 550 glCullFace (GL_BACK); 615 glPolygonMode (GL_FRONT, GL_FILL); 551 glPolygonMode (GL_FRONT, GL_FILL); 616 } 552 } 617 } 553 } >> 554 #ifndef G4OPENGL_VERSION_2 618 if (!fProcessing2D) glEnable (GL_LIGHTING) 555 if (!fProcessing2D) glEnable (GL_LIGHTING); >> 556 #endif 619 break; 557 break; 620 case (G4ViewParameters::wireframe): 558 case (G4ViewParameters::wireframe): 621 default: 559 default: 622 glEnable (GL_DEPTH_TEST); 560 glEnable (GL_DEPTH_TEST); 623 glDepthFunc (GL_LEQUAL); //??? was GL_A 561 glDepthFunc (GL_LEQUAL); //??? was GL_ALWAYS 624 //glDisable (GL_CULL_FACE); << 562 glDisable (GL_CULL_FACE); 625 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE) 563 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 626 break; 564 break; 627 } 565 } 628 566 629 //Loop through all the facets... 567 //Loop through all the facets... 630 fEdgeFlag = true; 568 fEdgeFlag = true; >> 569 #ifndef G4OPENGL_VERSION_2 631 glBegin (GL_QUADS); 570 glBegin (GL_QUADS); 632 glEdgeFlag (GL_TRUE); 571 glEdgeFlag (GL_TRUE); >> 572 #else >> 573 fEmulate_GL_QUADS = true; >> 574 glBeginVBO(GL_TRIANGLE_STRIP); >> 575 #endif 633 G4bool notLastFace; 576 G4bool notLastFace; 634 do { 577 do { 635 578 636 //First, find vertices, edgeflags and norm 579 //First, find vertices, edgeflags and normals and note "not last facet"... 637 G4Point3D vertex[4]; 580 G4Point3D vertex[4]; 638 G4int edgeFlag[4]; 581 G4int edgeFlag[4]; 639 G4Normal3D normals[4]; 582 G4Normal3D normals[4]; 640 G4int nEdges; 583 G4int nEdges; 641 notLastFace = polyhedron.GetNextFacet(nEdg 584 notLastFace = polyhedron.GetNextFacet(nEdges, vertex, edgeFlag, normals); 642 585 643 //Loop through the four edges of each G4Fa 586 //Loop through the four edges of each G4Facet... 644 for(G4int edgeCount = 0; edgeCount < nEdge 587 for(G4int edgeCount = 0; edgeCount < nEdges; ++edgeCount) { 645 // Check to see if edge is visible or no 588 // Check to see if edge is visible or not... 646 if (isAuxEdgeVisible) { 589 if (isAuxEdgeVisible) { 647 edgeFlag[edgeCount] = 1; 590 edgeFlag[edgeCount] = 1; 648 } 591 } >> 592 #ifndef G4OPENGL_VERSION_2 649 if (edgeFlag[edgeCount] > 0) { 593 if (edgeFlag[edgeCount] > 0) { 650 if (fEdgeFlag != true) { 594 if (fEdgeFlag != true) { 651 glEdgeFlag (GL_TRUE); 595 glEdgeFlag (GL_TRUE); 652 fEdgeFlag = true; 596 fEdgeFlag = true; 653 } 597 } 654 } else { 598 } else { 655 if (fEdgeFlag != false) { 599 if (fEdgeFlag != false) { 656 glEdgeFlag (GL_FALSE); 600 glEdgeFlag (GL_FALSE); 657 fEdgeFlag = false; 601 fEdgeFlag = false; 658 } 602 } 659 } 603 } 660 glNormal3d (normals[edgeCount].x(), 604 glNormal3d (normals[edgeCount].x(), 661 normals[edgeCount].y(), 605 normals[edgeCount].y(), 662 normals[edgeCount].z()); 606 normals[edgeCount].z()); 663 glVertex3d (vertex[edgeCount].x(), 607 glVertex3d (vertex[edgeCount].x(), 664 vertex[edgeCount].y(), 608 vertex[edgeCount].y(), 665 vertex[edgeCount].z()); 609 vertex[edgeCount].z()); >> 610 #else >> 611 >> 612 fOglVertex.push_back(vertex[edgeCount].x()); >> 613 fOglVertex.push_back(vertex[edgeCount].y()); >> 614 fOglVertex.push_back(vertex[edgeCount].z()); >> 615 >> 616 fOglVertex.push_back(normals[edgeCount].x()); >> 617 fOglVertex.push_back(normals[edgeCount].y()); >> 618 fOglVertex.push_back(normals[edgeCount].z()); >> 619 >> 620 #endif >> 621 666 } 622 } 667 623 668 // HepPolyhedron produces triangles too; i 624 // HepPolyhedron produces triangles too; in that case add an extra 669 // vertex identical to first... 625 // vertex identical to first... 670 if (nEdges == 3) { 626 if (nEdges == 3) { 671 G4int edgeCount = 3; 627 G4int edgeCount = 3; 672 normals[edgeCount] = normals[0]; 628 normals[edgeCount] = normals[0]; 673 vertex[edgeCount] = vertex[0]; 629 vertex[edgeCount] = vertex[0]; >> 630 #ifndef G4OPENGL_VERSION_2 674 edgeFlag[edgeCount] = -1; 631 edgeFlag[edgeCount] = -1; 675 if (fEdgeFlag != false) { 632 if (fEdgeFlag != false) { 676 glEdgeFlag (GL_FALSE); 633 glEdgeFlag (GL_FALSE); 677 fEdgeFlag = false; 634 fEdgeFlag = false; 678 } 635 } 679 636 680 glNormal3d (normals[edgeCount].x(), 637 glNormal3d (normals[edgeCount].x(), 681 normals[edgeCount].y(), 638 normals[edgeCount].y(), 682 normals[edgeCount].z()); 639 normals[edgeCount].z()); 683 glVertex3d (vertex[edgeCount].x(), 640 glVertex3d (vertex[edgeCount].x(), 684 vertex[edgeCount].y(), 641 vertex[edgeCount].y(), 685 vertex[edgeCount].z()); 642 vertex[edgeCount].z()); >> 643 #else >> 644 fOglVertex.push_back(vertex[edgeCount].x()); >> 645 fOglVertex.push_back(vertex[edgeCount].y()); >> 646 fOglVertex.push_back(vertex[edgeCount].z()); >> 647 >> 648 fOglVertex.push_back(normals[edgeCount].x()); >> 649 fOglVertex.push_back(normals[edgeCount].y()); >> 650 fOglVertex.push_back(normals[edgeCount].z()); >> 651 >> 652 #endif 686 } 653 } 687 // Trap situation where number of edges is 654 // Trap situation where number of edges is > 4... 688 if (nEdges > 4) { 655 if (nEdges > 4) { 689 G4cerr << 656 G4cerr << 690 "G4OpenGLSceneHandler::AddPrimitive(G4Polyhe 657 "G4OpenGLSceneHandler::AddPrimitive(G4Polyhedron): WARNING" 691 "\n G4Polyhedron facet with " << nEdges << 658 "\n G4Polyhedron facet with " << nEdges << " edges" << G4endl; 692 } 659 } 693 660 694 661 695 // Do it all over again (twice) for hlr... 662 // Do it all over again (twice) for hlr... 696 if (drawing_style == G4ViewParameters::hl 663 if (drawing_style == G4ViewParameters::hlr || 697 drawing_style == G4ViewParameters::hlhsr) { 664 drawing_style == G4ViewParameters::hlhsr) { 698 665 >> 666 #ifndef G4OPENGL_VERSION_2 699 glDisable(GL_COLOR_MATERIAL); // Revert 667 glDisable(GL_COLOR_MATERIAL); // Revert to glMaterial for hlr/sr. >> 668 #endif >> 669 >> 670 #ifndef G4OPENGL_VERSION_2 700 glEnd (); // Placed here to balance glB 671 glEnd (); // Placed here to balance glBegin above, allowing GL 701 << 672 #else >> 673 glEndVBO(); >> 674 #endif 702 // state changes below, then glBegin aga 675 // state changes below, then glBegin again. Avoids 703 // having glBegin/End pairs *inside* loop 676 // having glBegin/End pairs *inside* loop in the more 704 // usual case of no hidden line removal. 677 // usual case of no hidden line removal. 705 678 706 // Lighting disabled unless otherwise re 679 // Lighting disabled unless otherwise requested 707 glDisable (GL_LIGHTING); 680 glDisable (GL_LIGHTING); 708 681 709 // Draw through stencil... 682 // Draw through stencil... 710 glStencilFunc (GL_EQUAL, 0, 1); 683 glStencilFunc (GL_EQUAL, 0, 1); 711 glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); 684 glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); 712 if (drawing_style == G4ViewParameters::h 685 if (drawing_style == G4ViewParameters::hlhsr) { 713 if (!fProcessing2D) glEnable (GL_LIGHTING); 686 if (!fProcessing2D) glEnable (GL_LIGHTING); 714 } 687 } 715 glEnable (GL_DEPTH_TEST); 688 glEnable (GL_DEPTH_TEST); 716 glDepthFunc (GL_LEQUAL); 689 glDepthFunc (GL_LEQUAL); 717 if (isTransparent) { 690 if (isTransparent) { 718 // Transparent... 691 // Transparent... 719 glDepthMask (GL_FALSE); // Make depth buffe 692 glDepthMask (GL_FALSE); // Make depth buffer read-only. 720 //glDisable (GL_CULL_FACE); << 693 glDisable (GL_CULL_FACE); 721 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 694 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 722 } else { 695 } else { 723 // Opaque... 696 // Opaque... 724 glDepthMask (GL_TRUE); // Make depth buffer 697 glDepthMask (GL_TRUE); // Make depth buffer writable (default). 725 if (clipping) { 698 if (clipping) { 726 //glDisable (GL_CULL_FACE); << 699 glDisable (GL_CULL_FACE); 727 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL) 700 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); 728 } else { 701 } else { 729 //glEnable (GL_CULL_FACE); << 702 glEnable (GL_CULL_FACE); 730 //glCullFace (GL_BACK); << 703 glCullFace (GL_BACK); 731 glPolygonMode (GL_FRONT, GL_FILL); 704 glPolygonMode (GL_FRONT, GL_FILL); 732 } 705 } 733 } 706 } 734 if (drawing_style == G4ViewParameters:: 707 if (drawing_style == G4ViewParameters::hlr) { 735 if (isTransparent) { 708 if (isTransparent) { 736 // Transparent - don't paint... 709 // Transparent - don't paint... 737 goto end_of_drawing_through_stencil; 710 goto end_of_drawing_through_stencil; 738 } 711 } 739 } 712 } 740 if (isTransparent) { 713 if (isTransparent) { 741 // Transparent... 714 // Transparent... 742 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_ 715 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, painting_colour); 743 } else { 716 } else { 744 // Opaque... 717 // Opaque... 745 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFU 718 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, painting_colour); 746 } 719 } 747 glColor4fv (painting_colour); 720 glColor4fv (painting_colour); >> 721 #ifndef G4OPENGL_VERSION_2 748 glBegin (GL_QUADS); 722 glBegin (GL_QUADS); 749 glEdgeFlag (GL_TRUE); 723 glEdgeFlag (GL_TRUE); 750 fEdgeFlag = true; 724 fEdgeFlag = true; >> 725 #else >> 726 fEmulate_GL_QUADS = true; >> 727 glBeginVBO(GL_TRIANGLE_STRIP); >> 728 #endif 751 729 752 for (int edgeCount = 0; edgeCount < 4; + 730 for (int edgeCount = 0; edgeCount < 4; ++edgeCount) { >> 731 #ifndef G4OPENGL_VERSION_2 753 if (edgeFlag[edgeCount] > 0) { 732 if (edgeFlag[edgeCount] > 0) { 754 if (fEdgeFlag != true) { 733 if (fEdgeFlag != true) { 755 glEdgeFlag (GL_TRUE); 734 glEdgeFlag (GL_TRUE); 756 fEdgeFlag = true; 735 fEdgeFlag = true; 757 } 736 } 758 } else { 737 } else { 759 if (fEdgeFlag != false) { 738 if (fEdgeFlag != false) { 760 glEdgeFlag (GL_FALSE); 739 glEdgeFlag (GL_FALSE); 761 fEdgeFlag = false; 740 fEdgeFlag = false; 762 } 741 } 763 } 742 } 764 glNormal3d (normals[edgeCount].x(), << 743 glNormal3d (normals[edgeCount].x(), 765 normals[edgeCount].y(), << 744 normals[edgeCount].y(), 766 normals[edgeCount].z()); << 745 normals[edgeCount].z()); 767 glVertex3d (vertex[edgeCount].x(), 746 glVertex3d (vertex[edgeCount].x(), 768 vertex[edgeCount].y(), 747 vertex[edgeCount].y(), 769 vertex[edgeCount].z()); 748 vertex[edgeCount].z()); >> 749 #else >> 750 #ifdef G4DEBUG_VIS_OGL >> 751 printf(".....G4OpenGLSceneHandler::AddPrimitive polyhedron QUADS VBO 2\n"); >> 752 #endif >> 753 fOglVertex.push_back(vertex[edgeCount].x()); >> 754 fOglVertex.push_back(vertex[edgeCount].y()); >> 755 fOglVertex.push_back(vertex[edgeCount].z()); >> 756 >> 757 fOglVertex.push_back(normals[edgeCount].x()); >> 758 fOglVertex.push_back(normals[edgeCount].y()); >> 759 fOglVertex.push_back(normals[edgeCount].z()); >> 760 >> 761 #endif 770 } 762 } >> 763 #ifndef G4OPENGL_VERSION_2 771 glEnd (); 764 glEnd (); >> 765 #else >> 766 glEndVBO(); >> 767 #endif 772 end_of_drawing_through_stencil: 768 end_of_drawing_through_stencil: 773 769 774 // and once more to reset the stencil bi 770 // and once more to reset the stencil bits... 775 glStencilFunc (GL_ALWAYS, 0, 1); 771 glStencilFunc (GL_ALWAYS, 0, 1); 776 glStencilOp (GL_INVERT, GL_INVERT, GL_IN 772 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT); 777 glDepthFunc (GL_LEQUAL); // to make sur 773 glDepthFunc (GL_LEQUAL); // to make sure line gets drawn. 778 if (isTransparent) { 774 if (isTransparent) { 779 // Transparent... 775 // Transparent... 780 //glDisable (GL_CULL_FACE); << 776 glDisable (GL_CULL_FACE); 781 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 777 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 782 } else { 778 } else { 783 // Opaque... 779 // Opaque... 784 if (clipping) { 780 if (clipping) { 785 //glDisable (GL_CULL_FACE); << 781 glDisable (GL_CULL_FACE); 786 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE) 782 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE); 787 } else { 783 } else { 788 //glEnable (GL_CULL_FACE); << 784 glEnable (GL_CULL_FACE); 789 //glCullFace (GL_BACK); << 785 glCullFace (GL_BACK); 790 glPolygonMode (GL_FRONT, GL_LINE); 786 glPolygonMode (GL_FRONT, GL_LINE); 791 } 787 } 792 } 788 } 793 glDisable (GL_LIGHTING); 789 glDisable (GL_LIGHTING); 794 glColor4fv (current_colour); 790 glColor4fv (current_colour); 795 fEdgeFlag = true; 791 fEdgeFlag = true; >> 792 #ifndef G4OPENGL_VERSION_2 796 glBegin (GL_QUADS); 793 glBegin (GL_QUADS); 797 glEdgeFlag (GL_TRUE); 794 glEdgeFlag (GL_TRUE); 798 fEdgeFlag = true; 795 fEdgeFlag = true; >> 796 #else >> 797 fEmulate_GL_QUADS = true; >> 798 glBeginVBO(GL_TRIANGLE_STRIP); >> 799 #endif 799 for (int edgeCount = 0; edgeCount < 4; + 800 for (int edgeCount = 0; edgeCount < 4; ++edgeCount) { >> 801 #ifndef G4OPENGL_VERSION_2 800 if (edgeFlag[edgeCount] > 0) { 802 if (edgeFlag[edgeCount] > 0) { 801 if (fEdgeFlag != true) { 803 if (fEdgeFlag != true) { 802 glEdgeFlag (GL_TRUE); 804 glEdgeFlag (GL_TRUE); 803 fEdgeFlag = true; 805 fEdgeFlag = true; 804 } 806 } 805 } else { 807 } else { 806 if (fEdgeFlag != false) { 808 if (fEdgeFlag != false) { 807 glEdgeFlag (GL_FALSE); 809 glEdgeFlag (GL_FALSE); 808 fEdgeFlag = false; 810 fEdgeFlag = false; 809 } 811 } 810 } 812 } 811 glNormal3d (normals[edgeCount].x(), 813 glNormal3d (normals[edgeCount].x(), 812 normals[edgeCount].y(), 814 normals[edgeCount].y(), 813 normals[edgeCount].z()); 815 normals[edgeCount].z()); 814 glVertex3d (vertex[edgeCount].x(), 816 glVertex3d (vertex[edgeCount].x(), 815 vertex[edgeCount].y(), 817 vertex[edgeCount].y(), 816 vertex[edgeCount].z()); 818 vertex[edgeCount].z()); >> 819 #else >> 820 #ifdef G4DEBUG_VIS_OGL >> 821 printf(".....G4OpenGLSceneHandler::AddPrimitive polyhedron QUADS VBO 3\n"); >> 822 #endif >> 823 fOglVertex.push_back(vertex[edgeCount].x()); >> 824 fOglVertex.push_back(vertex[edgeCount].y()); >> 825 fOglVertex.push_back(vertex[edgeCount].z()); >> 826 >> 827 fOglVertex.push_back(normals[edgeCount].x()); >> 828 fOglVertex.push_back(normals[edgeCount].y()); >> 829 fOglVertex.push_back(normals[edgeCount].z()); >> 830 >> 831 #endif 817 } 832 } >> 833 #ifndef G4OPENGL_VERSION_2 818 glEnd (); 834 glEnd (); >> 835 #else >> 836 glEndVBO(); >> 837 #endif 819 838 820 glDepthFunc (GL_LEQUAL); // Revert for 839 glDepthFunc (GL_LEQUAL); // Revert for next facet. 821 fEdgeFlag = true; 840 fEdgeFlag = true; >> 841 #ifndef G4OPENGL_VERSION_2 822 glBegin (GL_QUADS); // Ready for ne 842 glBegin (GL_QUADS); // Ready for next facet. GL 823 glEdgeFlag (GL_TRUE); 843 glEdgeFlag (GL_TRUE); 824 fEdgeFlag = true; 844 fEdgeFlag = true; 825 // says it ignores incomplete 845 // says it ignores incomplete 826 // quadrilaterals, so final empty 846 // quadrilaterals, so final empty 827 // glBegin/End sequence should be OK. 847 // glBegin/End sequence should be OK. >> 848 #else >> 849 fEmulate_GL_QUADS = true; >> 850 glBeginVBO(GL_TRIANGLE_STRIP); >> 851 #endif 828 } 852 } 829 } while (notLastFace); 853 } while (notLastFace); 830 854 >> 855 #ifndef G4OPENGL_VERSION_2 831 glEnd (); 856 glEnd (); >> 857 #else >> 858 >> 859 // FIXME: du grand n'importe quoi en test >> 860 // Cube optimization >> 861 >> 862 // store old DrawType because in case of optimization it could be changed >> 863 GLenum oldDrawArrayType = fDrawArrayType; >> 864 >> 865 if (dynamic_cast<const G4PolyhedronTrd2*>(&polyhedron)) { >> 866 // OptimizeVBOForTrd(); >> 867 } else if (dynamic_cast<const G4PolyhedronCons*>(&polyhedron)) { >> 868 // OptimizeVBOForCons((polyhedron.GetNoVertices()-2)/2 ); // top + bottom + all faces >> 869 } >> 870 >> 871 glEndVBO(); >> 872 fDrawArrayType = oldDrawArrayType; >> 873 #endif >> 874 832 glDisable (GL_STENCIL_TEST); // Revert to d 875 glDisable (GL_STENCIL_TEST); // Revert to default for next primitive. 833 glDepthMask (GL_TRUE); // Revert to d 876 glDepthMask (GL_TRUE); // Revert to default for next primitive. >> 877 #ifndef G4OPENGL_VERSION_2 834 glDisable (GL_LIGHTING); // Revert to d 878 glDisable (GL_LIGHTING); // Revert to default for next primitive. >> 879 #endif 835 } 880 } 836 881 837 void G4OpenGLSceneHandler::AddCompound(const G 882 void G4OpenGLSceneHandler::AddCompound(const G4VTrajectory& traj) { 838 G4VSceneHandler::AddCompound(traj); // For 883 G4VSceneHandler::AddCompound(traj); // For now. 839 } 884 } 840 885 841 void G4OpenGLSceneHandler::AddCompound(const G 886 void G4OpenGLSceneHandler::AddCompound(const G4VHit& hit) { 842 G4VSceneHandler::AddCompound(hit); // For n 887 G4VSceneHandler::AddCompound(hit); // For now. 843 } 888 } 844 889 845 void G4OpenGLSceneHandler::AddCompound(const G 890 void G4OpenGLSceneHandler::AddCompound(const G4VDigi& digi) { 846 G4VSceneHandler::AddCompound(digi); // For 891 G4VSceneHandler::AddCompound(digi); // For now. 847 } 892 } 848 893 849 void G4OpenGLSceneHandler::AddCompound(const G 894 void G4OpenGLSceneHandler::AddCompound(const G4THitsMap<G4double>& hits) { 850 G4VSceneHandler::AddCompound(hits); // For 895 G4VSceneHandler::AddCompound(hits); // For now. 851 } 896 } 852 897 853 void G4OpenGLSceneHandler::AddCompound(const G << 898 854 G4VSceneHandler::AddCompound(hits); // For << 899 #ifdef G4OPENGL_VERSION_2 >> 900 >> 901 // Optimize vertex and indices in order to render less vertex in OpenGL VBO/IBO >> 902 void G4OpenGLSceneHandler::OptimizeVBOForTrd(){ >> 903 >> 904 /* HOW IT IS BUILD (as we receive it from fOglVertex : >> 905 */ >> 906 >> 907 std::vector<double> vertices; >> 908 vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+6*6); // ABCDEF >> 909 vertices.insert (vertices.end(),fOglVertex.begin()+9*6,fOglVertex.begin()+9*6+6); // G >> 910 vertices.insert (vertices.end(),fOglVertex.begin()+13*6,fOglVertex.begin()+13*6+6); // H >> 911 fOglVertex = vertices; >> 912 >> 913 int myarray [] = { >> 914 3,2,0,1,4,5,7,6, 6,0,4,3,7,2,6,1,5 >> 915 }; >> 916 fOglIndices.insert(fOglIndices.begin(), myarray, myarray+17/*36*/); >> 917 >> 918 fDrawArrayType = GL_TRIANGLE_STRIP; >> 919 } >> 920 >> 921 // Optimize vertex and indices in order to render less vertex in OpenGL VBO/IBO >> 922 void G4OpenGLSceneHandler::OptimizeVBOForCons(G4int aNoFaces){ >> 923 // Optimized, 1st level : 10f/15sec with 1000 cones >> 924 // DrawElements:208 vertex and 605 (2*100+2*100+2*100+5) indices for a 100 face cone >> 925 >> 926 /* surface of polycone : could be optimized >> 927 for 100 faces : >> 928 - 100*4 = 400 points >> 929 - 100*2+2 = 202 points with TRIANGLE_STRIP >> 930 Total : >> 931 n*4+n*4+n*4 = n*12 >> 932 optimize : n*2+2+1+n+1 = n*3+3 (factor 4) >> 933 but could do better : n faces should give = n*2+2 >> 934 */ >> 935 >> 936 /* >> 937 0 >> 938 / \ >> 939 2---4 6 ....2 >> 940 | | >> 941 3---5 7 ....3 >> 942 \ / >> 943 1 >> 944 */ >> 945 // First, faces >> 946 std::vector<double> vertices; >> 947 >> 948 // Add bottom and top vertex >> 949 // aNoFaces*4*6+6 : nb Faces * 4 points per face * 6 vertex by point + 1 point offset >> 950 vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*4)*6,fOglVertex.begin()+(aNoFaces*4)*6+6); // 0 >> 951 vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*8+1)*6,fOglVertex.begin()+(aNoFaces*8+1)*6+6); // 1 >> 952 >> 953 // Add facets points >> 954 G4int posInVertice; >> 955 for (G4int a = 0; a<aNoFaces; a++) { >> 956 posInVertice = a*4*6; >> 957 vertices.insert (vertices.end(),fOglVertex.begin()+posInVertice,fOglVertex.begin()+posInVertice+1*6+6); // AB >> 958 } >> 959 vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+1*6*6); // AB >> 960 fOglVertex = vertices; >> 961 >> 962 // Add indices for top : >> 963 // simple version : 0-2-0-4-0-6-0-8-0-10.. >> 964 // optimized version : 2-0-4-6- 6-0-8-10.. but we have to deal with odd faces numbers >> 965 for (G4int a=0; a<aNoFaces; a++) { >> 966 fOglIndices.push_back(0); >> 967 fOglIndices.push_back(a*2+2); >> 968 } >> 969 // close strip >> 970 fOglIndices.push_back(0); >> 971 fOglIndices.push_back(2); >> 972 >> 973 // Add indices for faces >> 974 for (G4int a = 0; a<aNoFaces; a++) { >> 975 fOglIndices.push_back(a*2+2); >> 976 fOglIndices.push_back(a*2+1+2); >> 977 } >> 978 fOglIndices.push_back(2); >> 979 fOglIndices.push_back(2+1); >> 980 >> 981 // Second : top >> 982 // 3-1-5-1-7-1-9-1.. >> 983 for (G4int a=0; a<aNoFaces; a++) { >> 984 fOglIndices.push_back(a*2+3); >> 985 fOglIndices.push_back(1); >> 986 } >> 987 // close strip >> 988 fOglIndices.push_back(0+3); >> 989 >> 990 fDrawArrayType = GL_TRIANGLE_STRIP; >> 991 fEmulate_GL_QUADS = false; >> 992 } >> 993 >> 994 void G4OpenGLSceneHandler::glBeginVBO(GLenum type) { >> 995 fDrawArrayType = type; >> 996 #ifdef G4DEBUG_VIS_OGL >> 997 printf("G4OpenGLSceneHandler::glBeginVBO %d\n",type); >> 998 #endif >> 999 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER >> 1000 glGenBuffers(1,&fVertexBufferObject); >> 1001 glGenBuffers(1,&fIndicesBufferObject); >> 1002 #else >> 1003 fVertexBufferObject = glCreateBuffer(); //glGenBuffer(1,fVertexBufferObject_2) >> 1004 fIndicesBufferObject = glCreateBuffer(); //glGenBuffer(1,fIndicesBufferObject_2) >> 1005 #endif >> 1006 >> 1007 // clear data and indices for OpenGL >> 1008 fOglVertex.clear(); >> 1009 fOglIndices.clear(); >> 1010 } >> 1011 >> 1012 // 2 cases : >> 1013 /* >> 1014 glDrawArray : if there is no vertex indices : fOglIndices.size() == 0 >> 1015 glDrawElements : if there is vertex indices : fOglIndices.size() != 0 >> 1016 >> 1017 */ >> 1018 void G4OpenGLSceneHandler::glEndVBO() { >> 1019 if (fOglIndices.size() == 0) { >> 1020 >> 1021 >> 1022 std::vector<double> vertices; >> 1023 // check if it is a GL_QUADS emulation >> 1024 if (fEmulate_GL_QUADS == true) { >> 1025 fEmulate_GL_QUADS = false; >> 1026 // A point has 6 double : Vx Vy Vz Nx Ny Nz >> 1027 // A QUAD should be like this >> 1028 /* >> 1029 0 3/4 7/8 .. >> 1030 >> 1031 1 2/5 6/9 .. >> 1032 */ >> 1033 // And if 3==4 and 2==5, we should do it like this for a TRIANGLES_STRIP >> 1034 /* >> 1035 0 4 8 .. >> 1036 | / | / | >> 1037 1 5 9 .. >> 1038 // Optimized, 1st level : 24f/15sec with 10 cones >> 1039 // non Optimized, 1st level : 12f/15sec with 10 cones >> 1040 */ >> 1041 // should be 4 points >> 1042 for (unsigned int a=0; a<fOglVertex.size(); a+=6*4) { >> 1043 vertices.insert (vertices.end(),fOglVertex.begin()+a,fOglVertex.begin()+a+1*6+6); // 0-1 >> 1044 // if 2-3 == 4-5, do not add them >> 1045 // if differents, we are obliged to create a new GL_TRIANGLE_STRIP >> 1046 if (a+4*6+5 < fOglVertex.size()) { >> 1047 if ((fOglVertex[a+2*6+0] != fOglVertex[a+5*6+0]) || //Vx for 2 and 5 >> 1048 (fOglVertex[a+2*6+1] != fOglVertex[a+5*6+1]) || //Vy for 2 and 5 >> 1049 (fOglVertex[a+2*6+2] != fOglVertex[a+5*6+2]) || //Vz for 2 and 5 >> 1050 (fOglVertex[a+2*6+3] != fOglVertex[a+5*6+3]) || //Px for 2 and 5 >> 1051 (fOglVertex[a+2*6+4] != fOglVertex[a+5*6+4]) || //Py for 2 and 5 >> 1052 (fOglVertex[a+2*6+5] != fOglVertex[a+5*6+5]) || //Pz for 2 and 5 >> 1053 >> 1054 (fOglVertex[a+3*6+0] != fOglVertex[a+4*6+0]) || //Vx for 3 and 4 >> 1055 (fOglVertex[a+3*6+1] != fOglVertex[a+4*6+1]) || //Vy for 3 and 4 >> 1056 (fOglVertex[a+3*6+2] != fOglVertex[a+4*6+2]) || //Vz for 3 and 4 >> 1057 (fOglVertex[a+3*6+3] != fOglVertex[a+4*6+3]) || //Px for 3 and 4 >> 1058 (fOglVertex[a+3*6+4] != fOglVertex[a+4*6+4]) || //Py for 3 and 4 >> 1059 (fOglVertex[a+3*6+5] != fOglVertex[a+4*6+5])) { //Pz for 3 and 4 >> 1060 // add last points >> 1061 vertices.insert (vertices.end(),fOglVertex.begin()+a+3*6,fOglVertex.begin()+a+3*6+6); // 3 >> 1062 vertices.insert (vertices.end(),fOglVertex.begin()+a+2*6,fOglVertex.begin()+a+2*6+6); // 2 >> 1063 // build and send the GL_TRIANGLE_STRIP >> 1064 drawVBOArray(vertices); >> 1065 vertices.clear(); >> 1066 } >> 1067 } else { // end of volume >> 1068 vertices.insert (vertices.end(),fOglVertex.begin()+a+3*6,fOglVertex.begin()+a+3*6+6); // 3 >> 1069 vertices.insert (vertices.end(),fOglVertex.begin()+a+2*6,fOglVertex.begin()+a+2*6+6); // 2 >> 1070 } >> 1071 } >> 1072 fOglVertex = vertices; >> 1073 } >> 1074 >> 1075 drawVBOArray(fOglVertex); >> 1076 >> 1077 } else { >> 1078 >> 1079 // Bind VBO >> 1080 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject); >> 1081 >> 1082 // Load fOglVertex into VBO >> 1083 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER >> 1084 int sizeV = fOglVertex.size(); >> 1085 // FIXME : perhaps a problem withBufferData in OpenGL other than WebGL ? >> 1086 // void glBufferData( GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage); >> 1087 glBufferData(GL_ARRAY_BUFFER, sizeof(double)*sizeV, &fOglVertex[0], GL_STATIC_DRAW); >> 1088 #else >> 1089 glBufferDatafv(GL_ARRAY_BUFFER, fOglVertex.begin(), fOglVertex.end(), GL_STATIC_DRAW); >> 1090 #endif >> 1091 >> 1092 // Bind IBO >> 1093 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject); >> 1094 >> 1095 // Load fOglVertex into VBO >> 1096 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER >> 1097 int sizeI = fOglIndices.size(); >> 1098 glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(int)*sizeI, &fOglIndices[0], GL_STATIC_DRAW); >> 1099 #else >> 1100 glBufferDataiv(GL_ELEMENT_ARRAY_BUFFER, fOglIndices.begin(), fOglIndices.end(), GL_STATIC_DRAW, GL_UNSIGNED_BYTE); >> 1101 #endif >> 1102 >> 1103 //---------------------------- >> 1104 // Draw VBO >> 1105 //---------------------------- >> 1106 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject); >> 1107 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject); >> 1108 >> 1109 #ifdef G4DEBUG_VIS_OGL >> 1110 printf("G4OpenGLSceneHandler::glEndVBO() To DrawElements:%d vertex and %d indices\n",fOglVertex.size()/6,fOglIndices.size()); >> 1111 #endif >> 1112 >> 1113 // the fVertexPositionAttribute is inside the G4OpenGLViewer >> 1114 G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer); >> 1115 if (pGLViewer) { >> 1116 glEnableVertexAttribArray(pGLViewer->fVertexPositionAttribute); >> 1117 >> 1118 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute, >> 1119 3, // size: Every vertex has an X, Y anc Z component >> 1120 GL_FLOAT, // type: They are floats >> 1121 GL_FALSE, // normalized: Please, do NOT normalize the vertices >> 1122 2*3*4, // stride: The first byte of the next vertex is located this >> 1123 // amount of bytes further. The format of the VBO is >> 1124 // vx, vy, vz, nx, ny, nz and every element is a >> 1125 // Float32, hence 4 bytes large >> 1126 0); // offset: The byte position of the first vertex in the buffer >> 1127 } >> 1128 >> 1129 >> 1130 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject); >> 1131 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject); >> 1132 // glDrawElements(fDrawArrayType, fOglIndices.size(), GL_UNSIGNED_SHORT, 0); >> 1133 glDrawElements(fDrawArrayType, fOglIndices.size(), GL_UNSIGNED_SHORT, 0); >> 1134 >> 1135 if (pGLViewer) { >> 1136 glDisableVertexAttribArray(pGLViewer->fVertexPositionAttribute); >> 1137 } >> 1138 >> 1139 // delete the buffer >> 1140 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER >> 1141 glDeleteBuffers(1,&fVertexBufferObject); >> 1142 #else >> 1143 glDeleteBuffer(fVertexBufferObject); >> 1144 #endif >> 1145 } 855 } 1146 } >> 1147 >> 1148 void G4OpenGLSceneHandler::drawVBOArray(std::vector<double> vertices) { >> 1149 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER >> 1150 glGenBuffers(1,&fVertexBufferObject); >> 1151 glGenBuffers(1,&fIndicesBufferObject); >> 1152 #else >> 1153 fVertexBufferObject = glCreateBuffer(); //glGenBuffer(1,fVertexBufferObject_2) >> 1154 fIndicesBufferObject = glCreateBuffer(); //glGenBuffer(1,fIndicesBufferObject_2) >> 1155 #endif >> 1156 >> 1157 // Bind this buffer >> 1158 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject); >> 1159 // Load oglData into VBO >> 1160 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER >> 1161 int s = vertices.size(); >> 1162 glBufferData(GL_ARRAY_BUFFER, sizeof(double)*s, &vertices[0], GL_STATIC_DRAW); >> 1163 #else >> 1164 glBufferDatafv(GL_ARRAY_BUFFER, vertices.begin(), vertices.end(), GL_STATIC_DRAW); >> 1165 #endif >> 1166 >> 1167 //---------------------------- >> 1168 // Draw VBO >> 1169 //---------------------------- >> 1170 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject); >> 1171 >> 1172 // the fVertexPositionAttribute is inside the G4OpenGLViewer >> 1173 G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer); >> 1174 if (pGLViewer) { >> 1175 glEnableVertexAttribArray(pGLViewer->fVertexPositionAttribute); 856 1176 857 void G4OpenGLSceneHandler::AddCompound(const G << 1177 // glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer) 858 StandardSpecialMeshRendering(mesh); << 1178 >> 1179 /* >> 1180 GL_DOUBLE >> 1181 Warning: This section describes legacy OpenGL APIs that have been removed from core OpenGL 3.1 and above (they are only deprecated in OpenGL 3.0). It is recommended that you not use this functionality in your programs. >> 1182 >> 1183 glLoadMatrixd, glRotated and any other function that have to do with the double type. Most GPUs don't support GL_DOUBLE (double) so the driver will convert the data to GL_FLOAT (float) and send to the GPU. If you put GL_DOUBLE data in a VBO, the performance might even be much worst than immediate mode (immediate mode means glBegin, glVertex, glEnd). GL doesn't offer any better way to know what the GPU prefers. >> 1184 */ >> 1185 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER >> 1186 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute, >> 1187 3, // size: Every vertex has an X, Y anc Z component >> 1188 GL_DOUBLE, // type: They are double >> 1189 GL_FALSE, // normalized: Please, do NOT normalize the vertices >> 1190 6*sizeof(double), // stride: The first byte of the next vertex is located this >> 1191 // amount of bytes further. The format of the VBO is >> 1192 // vx, vy, vz, nx, ny, nz and every element is a >> 1193 // Float32, hence 4 bytes large >> 1194 0); // offset: The byte position of the first vertex in the buffer >> 1195 #else >> 1196 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute, >> 1197 3, // size: Every vertex has an X, Y anc Z component >> 1198 GL_FLOAT, // type: They are floats >> 1199 GL_FALSE, // normalized: Please, do NOT normalize the vertices >> 1200 2*3*4, // stride: The first byte of the next vertex is located this >> 1201 // amount of bytes further. The format of the VBO is >> 1202 // vx, vy, vz, nx, ny, nz and every element is a >> 1203 // Float32, hence 4 bytes large >> 1204 0); // offset: The byte position of the first vertex in the buffer >> 1205 #endif >> 1206 } >> 1207 >> 1208 glDrawArrays(fDrawArrayType, // GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP, and GL_TRIANGLES >> 1209 0, vertices.size()/6); >> 1210 if (pGLViewer) { >> 1211 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER >> 1212 glDisableClientState( GL_VERTEX_ARRAY ); >> 1213 #else >> 1214 glDisableVertexAttribArray(pGLViewer->fVertexPositionAttribute); >> 1215 #endif >> 1216 } >> 1217 >> 1218 // delet the buffer >> 1219 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER >> 1220 glDeleteBuffers(1,&fVertexBufferObject); >> 1221 #else >> 1222 glDeleteBuffer(fVertexBufferObject); >> 1223 #endif 859 } 1224 } >> 1225 #endif >> 1226 >> 1227 >> 1228 #endif 860 1229