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: G4OpenGLImmediateSceneHandler.cc,v 1.35 2010-06-03 20:35:19 allison Exp $ >> 28 // GEANT4 tag $Name: geant4-09-04-patch-02 $ 27 // 29 // 28 // 30 // 29 // Andrew Walkden 10th February 1997 31 // Andrew Walkden 10th February 1997 30 // OpenGL immediate scene - draws immediately 32 // OpenGL immediate scene - draws immediately to buffer 31 // (saving space on 33 // (saving space on server). 32 34 >> 35 #ifdef G4VIS_BUILD_OPENGL_DRIVER >> 36 >> 37 // Included here - problems with HP compiler if not before other includes? >> 38 #include "G4NURBS.hh" >> 39 >> 40 // Here follows a special for Mesa, the OpenGL emulator. Does not affect >> 41 // other OpenGL's, as far as I'm aware. John Allison 18/9/96. >> 42 #define CENTERLINE_CLPP /* CenterLine C++ workaround: */ >> 43 // Also seems to be required for HP's CC and AIX xlC, at least. >> 44 33 #include "G4OpenGLImmediateSceneHandler.hh" 45 #include "G4OpenGLImmediateSceneHandler.hh" 34 46 35 #include "G4OpenGLViewer.hh" 47 #include "G4OpenGLViewer.hh" 36 #include "G4OpenGLTransform3D.hh" 48 #include "G4OpenGLTransform3D.hh" 37 #include "G4Polyline.hh" 49 #include "G4Polyline.hh" 38 #include "G4Polymarker.hh" 50 #include "G4Polymarker.hh" 39 #include "G4Text.hh" 51 #include "G4Text.hh" 40 #include "G4Circle.hh" 52 #include "G4Circle.hh" 41 #include "G4Square.hh" 53 #include "G4Square.hh" >> 54 #include "G4Scale.hh" 42 #include "G4Polyhedron.hh" 55 #include "G4Polyhedron.hh" 43 #include "G4AttHolder.hh" << 44 << 45 #include <typeinfo> << 46 56 47 G4OpenGLImmediateSceneHandler::G4OpenGLImmedia 57 G4OpenGLImmediateSceneHandler::G4OpenGLImmediateSceneHandler 48 (G4VGraphicsSystem& system,const G4String& nam 58 (G4VGraphicsSystem& system,const G4String& name): 49 G4OpenGLSceneHandler (system, fSceneIdCount+ 59 G4OpenGLSceneHandler (system, fSceneIdCount++, name) 50 {} 60 {} 51 61 52 G4OpenGLImmediateSceneHandler::~G4OpenGLImmedi 62 G4OpenGLImmediateSceneHandler::~G4OpenGLImmediateSceneHandler () 53 {} 63 {} 54 64 55 #include <iomanip> 65 #include <iomanip> 56 66 57 G4bool G4OpenGLImmediateSceneHandler::AddPrimi << 67 void G4OpenGLImmediateSceneHandler::AddPrimitivePreamble(const G4Visible& visible) 58 { << 59 return AddPrimitivePreambleInternal(visibl << 60 } << 61 G4bool G4OpenGLImmediateSceneHandler::AddPrimi << 62 { << 63 return AddPrimitivePreambleInternal(visible, << 64 } << 65 G4bool G4OpenGLImmediateSceneHandler::AddPrimi << 66 { << 67 return AddPrimitivePreambleInternal(visible, << 68 } << 69 << 70 G4bool G4OpenGLImmediateSceneHandler::AddPrimi << 71 { 68 { 72 // Get applicable vis attributes for all pri << 73 fpVisAttribs = fpViewer->GetApplicableVisAtt << 74 const G4Colour& c = GetColour (); << 75 G4double opacity = c.GetAlpha (); << 76 << 77 G4bool transparency_enabled = true; << 78 G4bool isMarkerNotHidden = true; << 79 G4OpenGLViewer* pViewer = dynamic_cast<G4Ope << 80 if (pViewer) { << 81 transparency_enabled = pViewer->transparen << 82 isMarkerNotHidden = pViewer->fVP.IsMarkerN << 83 } << 84 << 85 G4bool isMarkerOrPolyline = isMarker || isPo << 86 G4bool treatAsTransparent = transparency_ena << 87 G4bool treatAsNotHidden = isMarkerNotHidden << 88 << 89 if (fProcessing2D) glDisable (GL_DEPTH_TEST) << 90 else { << 91 if (isMarkerOrPolyline && isMarkerNotHidde << 92 glDisable (GL_DEPTH_TEST); << 93 else {glEnable (GL_DEPTH_TEST); glDepthFun << 94 } << 95 << 96 if (fThreePassCapable) { << 97 << 98 // Ensure transparent objects are drawn op << 99 // non-hidden markers. The problem of ble << 100 // is quite a tricky one - see History of << 101 if (!(fSecondPassForTransparency || fThird << 102 // First pass... << 103 if (treatAsTransparent) { // Request pa << 104 fSecondPassForTransparencyRequested = << 105 } << 106 if (treatAsNotHidden) { // Request pa << 107 fThirdPassForNonHiddenMarkersRequested << 108 } << 109 // On first pass, transparent objects an << 110 if (treatAsTransparent || treatAsNotHidd << 111 return false; << 112 } << 113 } << 114 << 115 // On second pass, only transparent object << 116 if (fSecondPassForTransparency) { << 117 if (!treatAsTransparent) { << 118 return false; << 119 } << 120 } << 121 << 122 // On third pass, only non-hidden markers << 123 if (fThirdPassForNonHiddenMarkers) { << 124 if (!treatAsNotHidden) { << 125 return false; << 126 } << 127 } << 128 } // fThreePassCapable << 129 << 130 // Loads G4Atts for picking... << 131 if (fpViewer->GetViewParameters().IsPicking( 69 if (fpViewer->GetViewParameters().IsPicking()) { 132 glLoadName(++fPickName); 70 glLoadName(++fPickName); 133 G4AttHolder* holder = new G4AttHolder; << 71 fPickMap[fPickName] = 0; 134 LoadAtts(visible, holder); << 135 fPickMap[fPickName] = holder; << 136 } << 137 << 138 if (transparency_enabled) { << 139 glColor4d(c.GetRed(),c.GetGreen(),c.GetBlu << 140 } else { << 141 glColor3d(c.GetRed(),c.GetGreen(),c.GetBlu << 142 } 72 } 143 73 144 return true; << 74 const G4Colour& c = GetColour (visible); >> 75 glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ()); 145 } 76 } 146 77 147 void G4OpenGLImmediateSceneHandler::AddPrimiti 78 void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Polyline& polyline) 148 { 79 { 149 G4bool furtherprocessing = AddPrimitivePream << 80 AddPrimitivePreamble(polyline); 150 if (furtherprocessing) { << 81 G4OpenGLSceneHandler::AddPrimitive(polyline); 151 G4OpenGLSceneHandler::AddPrimitive(polylin << 152 } << 153 } 82 } 154 83 155 void G4OpenGLImmediateSceneHandler::AddPrimiti 84 void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Polymarker& polymarker) 156 { 85 { 157 G4bool furtherprocessing = AddPrimitivePream << 86 AddPrimitivePreamble(polymarker); 158 if (furtherprocessing) { << 87 G4OpenGLSceneHandler::AddPrimitive(polymarker); 159 G4OpenGLSceneHandler::AddPrimitive(polymar << 160 } << 161 } 88 } 162 89 163 void G4OpenGLImmediateSceneHandler::AddPrimiti 90 void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Text& text) 164 { 91 { 165 // Note: colour is still handled in 92 // Note: colour is still handled in 166 // G4OpenGLSceneHandler::AddPrimitive(const 93 // G4OpenGLSceneHandler::AddPrimitive(const G4Text&). 167 G4bool furtherprocessing = AddPrimitivePream << 94 AddPrimitivePreamble(text); 168 if (furtherprocessing) { << 95 G4OpenGLSceneHandler::AddPrimitive(text); 169 G4OpenGLSceneHandler::AddPrimitive(text); << 170 } << 171 } 96 } 172 97 173 void G4OpenGLImmediateSceneHandler::AddPrimiti 98 void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Circle& circle) 174 { 99 { 175 G4bool furtherprocessing = AddPrimitivePream << 100 AddPrimitivePreamble(circle); 176 if (furtherprocessing) { << 101 G4OpenGLSceneHandler::AddPrimitive(circle); 177 G4OpenGLSceneHandler::AddPrimitive(circle) << 178 } << 179 } 102 } 180 103 181 void G4OpenGLImmediateSceneHandler::AddPrimiti 104 void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Square& square) 182 { 105 { 183 G4bool furtherprocessing = AddPrimitivePream << 106 AddPrimitivePreamble(square); 184 if (furtherprocessing) { << 107 G4OpenGLSceneHandler::AddPrimitive(square); 185 G4OpenGLSceneHandler::AddPrimitive(square) << 108 } 186 } << 109 >> 110 void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Scale& scale) >> 111 { >> 112 AddPrimitivePreamble(scale); >> 113 G4OpenGLSceneHandler::AddPrimitive(scale); 187 } 114 } 188 115 189 void G4OpenGLImmediateSceneHandler::AddPrimiti 116 void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) 190 { 117 { 191 // Note: colour is still handled in 118 // Note: colour is still handled in 192 // G4OpenGLSceneHandler::AddPrimitive(const 119 // G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&). 193 G4bool furtherprocessing = AddPrimitivePream << 120 AddPrimitivePreamble(polyhedron); 194 if (furtherprocessing) { << 121 G4OpenGLSceneHandler::AddPrimitive(polyhedron); 195 G4OpenGLSceneHandler::AddPrimitive(polyhed << 122 } 196 } << 123 >> 124 void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4NURBS& nurbs) >> 125 { >> 126 // Note: colour is still handled in >> 127 // G4OpenGLSceneHandler::AddPrimitive(const G4NURBS&). >> 128 AddPrimitivePreamble(nurbs); >> 129 G4OpenGLSceneHandler::AddPrimitive(nurbs); 197 } 130 } 198 131 199 void G4OpenGLImmediateSceneHandler::BeginPrimi 132 void G4OpenGLImmediateSceneHandler::BeginPrimitives 200 (const G4Transform3D& objectTransformation) 133 (const G4Transform3D& objectTransformation) 201 { 134 { 202 G4OpenGLSceneHandler::BeginPrimitives (objec 135 G4OpenGLSceneHandler::BeginPrimitives (objectTransformation); 203 136 204 G4OpenGLTransform3D oglt (objectTransformati 137 G4OpenGLTransform3D oglt (objectTransformation); 205 138 206 glPushMatrix(); 139 glPushMatrix(); 207 140 208 /*************************** Check matrix. 141 /*************************** Check matrix. 209 const GLdouble* m = oglt.GetGLMatrix (); 142 const GLdouble* m = oglt.GetGLMatrix (); 210 G4cout << "G4OpenGLTransform3D matrix:"; 143 G4cout << "G4OpenGLTransform3D matrix:"; 211 for (int i = 0; i < 16; i++) { 144 for (int i = 0; i < 16; i++) { 212 if ((i % 4) == 0) G4cout << '\n'; 145 if ((i % 4) == 0) G4cout << '\n'; 213 G4cout << std::setw (15) << m[i]; 146 G4cout << std::setw (15) << m[i]; 214 } 147 } 215 G4cout << G4endl; 148 G4cout << G4endl; 216 *****************************************/ 149 *****************************************/ 217 150 218 glMultMatrixd (oglt.GetGLMatrix ()); 151 glMultMatrixd (oglt.GetGLMatrix ()); 219 } 152 } 220 153 221 void G4OpenGLImmediateSceneHandler::EndPrimiti 154 void G4OpenGLImmediateSceneHandler::EndPrimitives () 222 { 155 { 223 glPopMatrix(); 156 glPopMatrix(); 224 157 225 // See all primitives immediately... At lea << 158 // See all primitives immediately... 226 ScaledFlush(); << 159 glFlush (); 227 160 228 G4OpenGLSceneHandler::EndPrimitives (); 161 G4OpenGLSceneHandler::EndPrimitives (); 229 } 162 } 230 163 231 void G4OpenGLImmediateSceneHandler::BeginPrimi 164 void G4OpenGLImmediateSceneHandler::BeginPrimitives2D 232 (const G4Transform3D& objectTransformation) 165 (const G4Transform3D& objectTransformation) 233 { 166 { 234 G4OpenGLSceneHandler::BeginPrimitives2D(obje 167 G4OpenGLSceneHandler::BeginPrimitives2D(objectTransformation); 235 168 236 // Push current 3D world matrices and load i 169 // Push current 3D world matrices and load identity to define screen 237 // coordinates... 170 // coordinates... 238 glMatrixMode (GL_PROJECTION); 171 glMatrixMode (GL_PROJECTION); 239 glPushMatrix(); 172 glPushMatrix(); 240 glLoadIdentity(); 173 glLoadIdentity(); 241 G4OpenGLViewer* pViewer = dynamic_cast<G4Ope << 174 glOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG); 242 if (pViewer) { << 243 pViewer->g4GlOrtho (-1., 1., -1., 1., -G4O << 244 } << 245 glMatrixMode (GL_MODELVIEW); 175 glMatrixMode (GL_MODELVIEW); 246 glPushMatrix(); 176 glPushMatrix(); 247 glLoadIdentity(); 177 glLoadIdentity(); 248 G4OpenGLTransform3D oglt (objectTransformati 178 G4OpenGLTransform3D oglt (objectTransformation); 249 glMultMatrixd (oglt.GetGLMatrix ()); 179 glMultMatrixd (oglt.GetGLMatrix ()); 250 glDisable(GL_DEPTH_TEST); // But see parent << 251 glDisable (GL_LIGHTING); // some cases, we << 252 } 180 } 253 181 254 void G4OpenGLImmediateSceneHandler::EndPrimiti 182 void G4OpenGLImmediateSceneHandler::EndPrimitives2D() 255 { 183 { 256 // Pop current 3D world matrices back again. 184 // Pop current 3D world matrices back again... 257 glMatrixMode (GL_PROJECTION); 185 glMatrixMode (GL_PROJECTION); 258 glPopMatrix(); 186 glPopMatrix(); 259 glMatrixMode (GL_MODELVIEW); 187 glMatrixMode (GL_MODELVIEW); 260 glPopMatrix(); 188 glPopMatrix(); 261 189 262 // See all primitives immediately... At lea << 190 // See all primitives immediately... 263 ScaledFlush(); << 191 glFlush (); 264 192 265 G4OpenGLSceneHandler::EndPrimitives2D (); 193 G4OpenGLSceneHandler::EndPrimitives2D (); 266 } 194 } 267 195 268 void G4OpenGLImmediateSceneHandler::BeginModel 196 void G4OpenGLImmediateSceneHandler::BeginModeling () { 269 G4VSceneHandler::BeginModeling(); 197 G4VSceneHandler::BeginModeling(); 270 } 198 } 271 199 272 void G4OpenGLImmediateSceneHandler::EndModelin 200 void G4OpenGLImmediateSceneHandler::EndModeling () { 273 G4VSceneHandler::EndModeling (); 201 G4VSceneHandler::EndModeling (); 274 } 202 } 275 203 276 void G4OpenGLImmediateSceneHandler::ClearTrans << 204 void G4OpenGLImmediateSceneHandler::ClearTransientStore () { 277 { << 205 278 // Nothing to do except redraw the scene rea << 206 G4VSceneHandler::ClearTransientStore (); >> 207 >> 208 // Make sure screen corresponds to graphical database... 279 if (fpViewer) { 209 if (fpViewer) { 280 fpViewer -> SetView (); 210 fpViewer -> SetView (); 281 fpViewer -> ClearView (); 211 fpViewer -> ClearView (); 282 fpViewer -> DrawView (); 212 fpViewer -> DrawView (); 283 } 213 } 284 } 214 } 285 215 >> 216 void G4OpenGLImmediateSceneHandler::RequestPrimitives (const G4VSolid& solid) >> 217 { >> 218 if (fReadyForTransients) { >> 219 // Always draw transient solids, e.g., hits represented as solids. >> 220 // (As we have no control over the order of drawing of transient >> 221 // objects, we cannot do anything about transparent ones, as >> 222 // below, so always draw them.) >> 223 G4VSceneHandler::RequestPrimitives (solid); >> 224 return; >> 225 } >> 226 >> 227 // For non-transient (run-duration) objects, ensure transparent >> 228 // objects are drawn last. The problem of >> 229 // blending/transparency/alpha is quite a tricky one - see History >> 230 // of opengl-V07-01-01/2/3. >> 231 // Get vis attributes - pick up defaults if none. >> 232 const G4VisAttributes* pVA = >> 233 fpViewer -> GetApplicableVisAttributes(fpVisAttribs); >> 234 const G4Colour& c = pVA -> GetColour (); >> 235 G4double opacity = c.GetAlpha (); >> 236 >> 237 if (!fSecondPass) { >> 238 G4bool transparency_enabled = true; >> 239 G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer); >> 240 if (pViewer) transparency_enabled = pViewer->transparency_enabled; >> 241 if (transparency_enabled && opacity < 1.) { >> 242 // On first pass, transparent objects are not drawn, but flag is set... >> 243 fSecondPassRequested = true; >> 244 return; >> 245 } >> 246 } >> 247 >> 248 // On second pass, opaque objects are not drwan... >> 249 if (fSecondPass && opacity >= 1.) return; >> 250 >> 251 // Else invoke base class method... >> 252 G4VSceneHandler::RequestPrimitives (solid); >> 253 } >> 254 286 G4int G4OpenGLImmediateSceneHandler::fSceneIdC 255 G4int G4OpenGLImmediateSceneHandler::fSceneIdCount = 0; >> 256 >> 257 #endif 287 258