ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4OpenGLSceneHandler.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4OpenGLSceneHandler.hh
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 //
28 //
29 // Andrew Walkden 27th March 1996
30 // OpenGL scene handler - base for immediate mode and stored mode classes to
31 // inherit from.
32 
33 #if defined (G4VIS_BUILD_OPENGL_DRIVER) || defined (G4VIS_USE_OPENGL)
34 
35 #ifndef G4OPENGLSCENEHANDLER_HH
36 #define G4OPENGLSCENEHANDLER_HH
37 
38 #include "globals.hh"
39 
40 #include "G4VSceneHandler.hh"
41 #include "G4OpenGL.hh"
42 
43 #include <map>
44 
45 class G4AttHolder;
46 
47 // Base class for various OpenGLSceneHandler classes.
48 class G4OpenGLSceneHandler: public G4VSceneHandler {
49 
50  friend class G4OpenGLViewer;
51 
52 public:
53  virtual void BeginPrimitives (const G4Transform3D& objectTransformation);
54  virtual void EndPrimitives ();
55  virtual void BeginPrimitives2D (const G4Transform3D& objectTransformation);
56  virtual void EndPrimitives2D ();
57  void AddPrimitive (const G4Polyline&);
58  void AddPrimitive (const G4Polymarker&);
59  void AddPrimitive (const G4Text&);
60  void AddPrimitive (const G4Circle&);
61  void AddPrimitive (const G4Square&);
62  void AddPrimitivesCircle (const std::vector <G4VMarker>&);
63  void AddPrimitivesSquare (const std::vector <G4VMarker>&);
64  void AddPrimitive (const G4Scale&);
65  void AddPrimitive (const G4Polyhedron&);
66 
67  void PreAddSolid (const G4Transform3D& objectTransformation,
68  const G4VisAttributes&);
69  void AddSolid (const G4Box&);
70  void AddSolid (const G4Cons&);
71  void AddSolid (const G4Tubs&);
72  void AddSolid (const G4Trd&);
73  void AddSolid (const G4Trap&);
74  void AddSolid (const G4Sphere&);
75  void AddSolid (const G4Para&);
76  void AddSolid (const G4Torus&);
77  void AddSolid (const G4Polycone&);
78  void AddSolid (const G4Polyhedra&);
79  void AddSolid (const G4Orb&);
80  void AddSolid (const G4Ellipsoid&);
81  void AddSolid (const G4TessellatedSolid&);
82  void AddSolid (const G4VSolid&);
83  void AddCompound (const G4VTrajectory&);
84  void AddCompound (const G4VHit&);
85  void AddCompound (const G4VDigi&);
86  void AddCompound (const G4THitsMap<G4double>&);
88 
89  // enum for /vis/ogl/flushAt.
90  enum FlushAction {
91  endOfEvent,
92  endOfRun,
93  eachPrimitive,
94  NthPrimitive,
95  NthEvent,
96  never
97  };
98  static G4int GetEntitiesFlushInterval()
99  {return fEntitiesFlushInterval;}
100  static FlushAction GetFlushAction()
101  {return fFlushAction;}
102  static void SetEntitiesFlushInterval(G4int interval)
103  {fEntitiesFlushInterval = interval;}
104  static void SetFlushAction(FlushAction action)
105  {fFlushAction = action;}
106 
107 #ifdef G4OPENGL_VERSION_2
108  private :
109  // vertex vector to be given to the graphic card
110  std::vector<double> fOglVertex;
111  // indices vector to be given to the graphic card
112  std::vector<unsigned short> fOglIndices;
113  // before, drawyType (as GL_QUADS, GL_TRIANGLES...) was
114  // given in glBegin. Now it has to be given in glDrawArray (at the end)
115  GLenum fDrawArrayType;
116  // emulate GL_QUADS behaviour by inverting two last positions
117  bool fEmulate_GL_QUADS;
118  // Try to optimize a bit the pipeline
119  void OptimizeVBOForTrd();
120  void OptimizeVBOForCons(G4int aNoFacet);
121  // emulating glEnd and glBegin
122  void glEndVBO();
123  void glBeginVBO(GLenum type);
124  void drawVBOArray(std::vector<double> vertices);
125 
126  // Buffers used to access vertex and indices elements
127 #if defined (G4VIS_BUILD_OPENGLWT_DRIVER) || defined (G4VIS_USE_OPENGLWT)
128  Wt::WGLWidget::Buffer fVertexBufferObject;
129  Wt::WGLWidget::Buffer fIndicesBufferObject;
130 #else
131  GLuint fVertexBufferObject;
132  GLuint fIndicesBufferObject;
133 #endif // G4VIS_BUILD_OPENGLWT_DRIVER
134 
135 #endif //G4OPENGL_VERSION_2
136 
137 protected:
138 
139  G4OpenGLSceneHandler (G4VGraphicsSystem& system,
140  G4int id,
141  const G4String& name = "");
142  virtual ~G4OpenGLSceneHandler ();
143 
144  void ProcessScene();
147 
148  void ClearAndDestroyAtts(); // Destroys att holders and clears pick map.
149 
150 #ifdef G4OPENGL_VERSION_2
151  // Special case for VBO, we want to have acces to the VBO drawer everywhere
152  // because instead of OpenGL call which are static, VBO openGL functions :
153  // - Are functions of an WGLWidget object(G4OpenGLImmediateViewer in our case)
154  // - Needs an access to the QGLSHader
155  // - Have to be redefined in a VBO way
156 
157  inline void setVboDrawer(G4OpenGLVboDrawer* drawer) {
158  fVboDrawer = drawer;
159  }
160  G4OpenGLVboDrawer* fVboDrawer;
161 #endif // G4OPENGL_VERSION_2
162 
163  GLuint fPickName;
164  std::map<GLuint, G4AttHolder*> fPickMap; // For picking.
165 
166  // Shared code to wait until we make a single glFlush
167  void ScaledFlush () ;
168  // Static so that they apply to all OGL scene handlers...
169  static FlushAction fFlushAction;
170  // Number of entities between flushes
171  static G4int fEntitiesFlushInterval;
172 
173  // True if caller of primitives is capable of processing three passes.
174  G4bool fThreePassCapable;
175 
176  G4bool fSecondPassForTransparencyRequested;
177  G4bool fSecondPassForTransparency;
178 
179  G4bool fThirdPassForNonHiddenMarkersRequested;
180  G4bool fThirdPassForNonHiddenMarkers;
181 
182  static const GLubyte fStippleMaskHashed [128];
183  bool fEdgeFlag;
184 };
185 
186 #include "G4OpenGLSceneHandler.icc"
187 
188 #endif // G4OPENGLSCENEHANDLER_HH
189 
190 #endif // G4VIS_BUILD_OPENGL_DRIVER