Geant4_10
G4OpenGLSceneHandler.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4OpenGLSceneHandler.hh 75567 2013-11-04 11:35:11Z gcosmo $
28 //
29 //
30 // Andrew Walkden 27th March 1996
31 // OpenGL scene handler - base for immediate mode and stored mode classes to
32 // inherit from.
33 
34 #ifdef G4VIS_BUILD_OPENGL_DRIVER
35 
36 #ifndef G4OPENGLSCENEHANDLER_HH
37 #define G4OPENGLSCENEHANDLER_HH
38 
39 #include "globals.hh"
40 
41 #include "G4VSceneHandler.hh"
42 #include "G4OpenGL.hh"
43 
44 #include <map>
45 
46 class G4AttHolder;
47 
48 // Base class for various OpenGLSceneHandler classes.
49 class G4OpenGLSceneHandler: public G4VSceneHandler {
50 
51  friend class G4OpenGLViewer;
52 
53 public:
54  virtual void BeginPrimitives (const G4Transform3D& objectTransformation);
55  virtual void EndPrimitives ();
56  virtual void BeginPrimitives2D (const G4Transform3D& objectTransformation);
57  virtual void EndPrimitives2D ();
58  void AddPrimitive (const G4Polyline&);
59  void AddPrimitive (const G4Polymarker&);
60  void AddPrimitive (const G4Text&);
61  void AddPrimitive (const G4Circle&);
62  void AddPrimitive (const G4Square&);
63  void AddPrimitivesCircle (const std::vector <G4VMarker>&);
64  void AddPrimitivesSquare (const std::vector <G4VMarker>&);
65  void AddPrimitive (const G4Scale&);
66  void AddPrimitive (const G4Polyhedron&);
67 
68  void PreAddSolid (const G4Transform3D& objectTransformation,
69  const G4VisAttributes&);
70  void AddSolid (const G4Box&);
71  void AddSolid (const G4Cons&);
72  void AddSolid (const G4Tubs&);
73  void AddSolid (const G4Trd&);
74  void AddSolid (const G4Trap&);
75  void AddSolid (const G4Sphere&);
76  void AddSolid (const G4Para&);
77  void AddSolid (const G4Torus&);
78  void AddSolid (const G4Polycone&);
79  void AddSolid (const G4Polyhedra&);
80  void AddSolid (const G4VSolid&);
81  void AddCompound (const G4VTrajectory&);
82  void AddCompound (const G4VHit&);
83  void AddCompound (const G4VDigi&);
84  void AddCompound (const G4THitsMap<G4double>&);
85 
86  G4int GetEventsDrawInterval() {return fEventsDrawInterval;}
87  void SetEventsDrawInterval(G4int interval) {fEventsDrawInterval = interval;}
88 
89 #ifdef G4OPENGL_VERSION_2
90 private :
91  // vertex vector to be given to the graphic card
92  std::vector<double> fOglVertex;
93  // indices vector to be given to the graphic card
94  std::vector<unsigned short> fOglIndices;
95  // before, drawyType (as GL_QUADS, GL_TRIANGLES...) was
96  // given in glBegin. Now it has to be given in glDrawArray (at the end)
97  GLenum fDrawArrayType;
98  // emulate GL_QUADS behaviour by inverting two last positions
99  bool fEmulate_GL_QUADS;
100  // Try to optimize a bit the pipeline
101  void OptimizeVBOForTrd();
102  void OptimizeVBOForCons(G4int aNoFacet);
103  // emulating glEnd and glBegin
104  void glEndVBO();
105  void glBeginVBO(GLenum type);
106  void drawVBOArray(std::vector<double> vertices);
107 
108 // Buffers used to access vertex and indices elements
109 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
110  GLuint fVertexBufferObject;
111  GLuint fIndicesBufferObject;
112 #else
113  Wt::WGLWidget::Buffer fVertexBufferObject;
114  Wt::WGLWidget::Buffer fIndicesBufferObject;
115 #endif
116 
117 #endif
118 
119 protected:
120 
121  G4OpenGLSceneHandler (G4VGraphicsSystem& system,
122  G4int id,
123  const G4String& name = "");
124  virtual ~G4OpenGLSceneHandler ();
125 
126  void ProcessScene();
129 
130  void ClearAndDestroyAtts(); // Destroys att holders and clears pick map.
131 
132 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
133  // Special case for Wt, we want to have acces to the Wt drawer everywhere
134  // because instead of OpenGL call which are static, Wt openGL functions are functions of an WGLWidget
135  // object(G4OpenGLImmediateViewer in our case)
136 
137  inline void setWtDrawer(G4OpenGLWtDrawer* drawer) {
138  fWtDrawer = drawer;
139  }
140  G4OpenGLWtDrawer* fWtDrawer;
141 #endif
142 
143  GLuint fPickName;
144  std::map<GLuint, G4AttHolder*> fPickMap; // For picking.
145 
146  // Shared code to wait until we make a single glFlush
147  void ScaledFlush () ;
148  // Number of events to wait until we make a single glFlush
149  G4int fEventsDrawInterval;
150  // Number of events waiting to be flushed
151  G4int fEventsWaitingToBeFlushed;
152 
153  // True if caller of primitives is capable of processing three passes.
154  G4bool fThreePassCapable;
155 
156  G4bool fSecondPassForTransparencyRequested;
157  G4bool fSecondPassForTransparency;
158 
159  G4bool fThirdPassForNonHiddenMarkersRequested;
160  G4bool fThirdPassForNonHiddenMarkers;
161 
162  static const GLubyte fStippleMaskHashed [128];
163 };
164 
165 #include "G4OpenGLSceneHandler.icc"
166 
167 #endif
168 
169 #endif
Definition: G4Para.hh:76
virtual void AddSolid(const G4Box &)
Definition: G4Text.hh:73
virtual G4VSolid * CreateSectionSolid()
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
Definition: G4Box.hh:63
Definition: G4Tubs.hh:84
const XML_Char * name
Definition: expat.h:151
Definition: G4VHit.hh:48
Definition: G4Trd.hh:71
int G4int
Definition: G4Types.hh:78
virtual void AddPrimitive(const G4Polyline &)=0
virtual G4VSolid * CreateCutawaySolid()
bool G4bool
Definition: G4Types.hh:79
Definition: G4Cons.hh:82
virtual void EndPrimitives()
virtual void BeginPrimitives2D(const G4Transform3D &objectTransformation)
virtual void AddCompound(const G4VTrajectory &)
virtual void ProcessScene()
system("rm -rf dna.root")
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
virtual void EndPrimitives2D()