Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4OpenGLVboDrawer.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: G4OpenGLVboDrawer.hh 74103 2014-06-23 07:52:38Z lgarnier $
28 //
29 //
30 // G4OpenGLVboDrawer : Class to provide Wt and Qt specific
31 // functionality for OpenGL in GEANT4
32 
33 #ifndef G4OpenGLVboDrawer_HH
34 #define G4OpenGLVboDrawer_HH
35 
36 #include "G4OpenGL.hh"
37 
38 #ifdef G4OPENGL_VERSION_2
39 
40 // GL2PS
41 #define GL2PS_TEXT_B 4
42 #define GL2PS_TEXT_BL 5
43 #define GL2PS_TEXT_BR 6
44 #define GL2PS_EPS 1
45 #define GL2PS_PDF 2
46 #define GL2PS_PS 3
47 #define GL2PS_SVG 4
48 
49 
50 #define glEdgeFlag(a) fVboDrawer->empty()
51 #define glRenderMode(a) fVboDrawer->returnNULL()
52 #define glClipPlane(a,b) fVboDrawer->empty()
53 #define glGetIntegerv(a,b) fVboDrawer->empty()
54 #define glGetFloatv(a,b) fVboDrawer->empty()
55 #define glGetDoublev(a,b) fVboDrawer->empty()
56 #define glPassThrough fVboDrawer->empty()
57 #define glGetBooleanv fVboDrawer->empty()
58 #define glLoadName(a) fVboDrawer->empty()
59 #define glPushMatrix() fVboDrawer->empty()
60 #define glLoadIdentity() fVboDrawer->empty()
61 #define glPopMatrix() fVboDrawer->empty()
62 #define glCallList(a) fVboDrawer->empty()
63 #define glGenLists(a) fVboDrawer->returnNULL()
64 #define glVertex3d fVboDrawer->empty()
65 #define glBegin fVboDrawer->empty()
66 #define glEnd fVboDrawer->empty()
67 #define glNewList(a,b) fVboDrawer->empty()
68 #define glEndList() fVboDrawer->empty()
69 #define glPolygonMode(a,b) fVboDrawer->empty()
70 #define glDrawBuffer(a) fVboDrawer->empty()
71 #define glDeleteLists(a,b) fVboDrawer->empty()
72 #define glStencilFunc(a,b,c) fVboDrawer->empty()
73 #define glStencilOp(a,b,c) fVboDrawer->empty()
74 #define glColorMaterial(a,b) fVboDrawer->empty()
75 #define glLightfv(a,b,c) fVboDrawer->empty()
76 #define glScaled(a,b,c) fVboDrawer->empty()
77 #define gluLookAt fVboDrawer->empty()
78 #define gluPickMatrix fVboDrawer->empty()
79 #define glSelectBuffer(a,b) fVboDrawer->empty()
80 #define glInitNames() fVboDrawer->empty()
81 #define glPushNames(a) fVboDrawer->empty()
82 #define glPushName(a) fVboDrawer->empty()
83 #define glPixelStorei(a,b) fVboDrawer->empty()
84 #define glRasterPos3d(a,b,c) fVboDrawer->empty()
85 #define Geant4_gl2psTextOpt(a,b,c,d,e) fVboDrawer->empty()
86 #define glMaterialfv(a,b,c) fVboDrawer->empty()
87 #define glCullFace(a) fVboDrawer->empty()
88 #define glReadBuffer(a) fVboDrawer->empty()
89 #define glReadPixels(a,b,c,d,e,f,g) fVboDrawer->empty()
90 #define glTranslatef(a,b,c) fVboDrawer->empty() // TO BE FIXED
91 
92 // +--------------------------------+
93 // + WT (OpenGL ES) case +
94 // +--------------------------------+
95 
96 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
97 
98 class G4OpenGLImmediateWtViewer;
99 
100 // specific definition for WT :
101 // WARNING fVboDrawer should be the exact name of the object!
102 
103 #define glGetError() Wt::WGLWidget::NONE
104 
105 #define glOrtho fVboDrawer->vboGlOrtho
106 #define glFrustum fVboDrawer->vboGlFrustum
107 #define glViewport fVboDrawer->vboGlViewport
108 #define glEnable fVboDrawer->vboGlEnable
109 #define glDisable fVboDrawer->vboGlDisable
110 #define glBlendFunc fVboDrawer->vboGlBlendFunc
111 #define glClear fVboDrawer->vboGlClear
112 #define glClearColor fVboDrawer->vboGlClearColor
113 #define glClearDepth fVboDrawer->vboGlClearDepth
114 #define glDepthFunc fVboDrawer->vboGlDepthFunc
115 #define glDepthMask fVboDrawer->vboGlDepthMask
116 #define glFlush fVboDrawer->vboGlFlush
117 #define glColorMask fVboDrawer->vboGlColorMask
118 #define glLineWidth fVboDrawer->vboGlLineWidth
119 #define glUniformMatrix4 fVboDrawer->vboGlUniformMatrix4
120 #define glDrawArrays fVboDrawer->vboGlDrawArrays
121 #define glCreateBuffer fVboDrawer->vboGlCreateBuffer
122 #define glVertexPointer fVboDrawer->vboGlVertexPointer
123 #define glBindBuffer fVboDrawer->vboGlBindBuffer
124 #define glDeleteBuffer fVboDrawer->vboGlDeleteBuffer
125 #define glBufferDatafv fVboDrawer->vboGlBufferDatafv
126 #define glBufferDataiv fVboDrawer->vboGlBufferDataiv
127 #define glGetAttribLocation fVboDrawer->vboGlGetAttribLocation
128 #define glEnableVertexAttribArray fVboDrawer->vboGlEnableVertexAttribArray
129 #define glDisableVertexAttribArray fVboDrawer->vboGlDisableVertexAttribArray
130 #define glShaderSource fVboDrawer->vboGlShaderSource
131 #define glCompileShader fVboDrawer->vboGlCompileShader
132 #define glCreateShader fVboDrawer->vboGlCreateShader
133 #define glCreateProgram fVboDrawer->vboGlCreateProgram
134 #define glAttachShader fVboDrawer->vboGlAttachShader
135 #define glLinkProgram fVboDrawer->vboGlLinkProgram
136 #define glUseProgram fVboDrawer->vboGlUseProgram
137 #define glDrawElements fVboDrawer->vboGlDrawElements
138 #define glVertexAttribPointer fVboDrawer->vboGlVertexAttribPointer
139 #define glGetUniformLocation fVboDrawer->vboGlGetUniformLocation
140 #define glPointSize fVboDrawer->vboGlPointSize
141 #define glColor3d fVboDrawer->vboGlColor3d
142 #define glColor4d fVboDrawer->vboGlColor4d
143 #define glColor4fv fVboDrawer->vboGlColor4fv
144 #define glMultMatrixd fVboDrawer->vboGlMultMatrixd
145 #define glMultMatrixf fVboDrawer->vboGlMultMatrixf
146 #define glGetUniformLocation fVboDrawer->vboGlGetUniformLocation
147 #define glGetAttribLocation fVboDrawer->vboGlGetAttribLocation
148 #define glMatrixMode fVboDrawer->vboGlMatrixMode
149 
150 
151 // Only used in fvboDrawer->VboDrawer to be compatible between Wt and Qt framework
152 #define glUniform1f fVboViewer->uniform1f
153 #define glUniform4fv fVboViewer->uniform4fv
154 #define glUniformMatrix4dv fVboDrawer->vboGlUniformMatrix4;
155 #define glUniformMatrix4fv fVboDrawer->vboGlUniformMatrix4fv;
156 
157 
158 
159 #define GL_VIEWPORT Wt::WGLWidget::VIEWPORT
160 #define GL_RGBA Wt::WGLWidget::RGBA
161 #define GL_ONE_MINUS_SRC_ALPHA Wt::WGLWidget::ONE_MINUS_SRC_ALPHA
162 #define GL_BLEND Wt::WGLWidget::BLEND
163 #define GL_SRC_ALPHA Wt::WGLWidget::SRC_ALPHA
164 #define GL_LEQUAL Wt::WGLWidget::LEQUAL
165 #define GL_FALSE false
166 #define GL_LESS Wt::WGLWidget::LESS
167 #define GL_SELECT Wt::WGLWidget::SELECT
168 #define GL_TRUE true
169 #define GL_RGB Wt::WGLWidget::RGB
170 #define GL_CURRENT_RASTER_POSITION_VALID Wt::WGLWidget::CURRENT_RASTER_POSITION_VALID
171 #define GL_ONE Wt::WGLWidget::ONE
172 #define GL_ZERO Wt::WGLWidget::ZERO
173 #define GL_COLOR_INDEX Wt::WGLWidget::COLOR_INDEX
174 #define GL_LINE_TOKEN Wt::WGLWidget::LINE_TOKEN
175 #define GL_LINE_RESET_TOKEN Wt::WGLWidget::LINE_RESET_TOKEN
176 #define GL_POLYGON_TOKEN Wt::WGLWidget::POLYGON_TOKEN
177 #define GL_FEEDBACK Wt::WGLWidget::FEEDBACK
178 #define GL_COLOR_CLEAR_VALUE Wt::WGLWidget::COLOR_CLEAR_VALUE
179 #define GL_BITMAP_TOKEN Wt::WGLWidget::BITMAP_TOKEN
180 #define GL_DRAW_PIXEL_TOKEN Wt::WGLWidget::DRAW_PIXEL_TOKEN
181 #define GL_COPY_PIXEL_TOKEN Wt::WGLWidget::COPY_PIXEL_TOKEN
182 #define GL_PASS_THROUGH_TOKEN Wt::WGLWidget::PASS_THROUGH_TOKEN
183 #define GL_3D_COLOR Wt::WGLWidget::3D_COLOR
184 #define GL_DEPTH_TEST Wt::WGLWidget::DEPTH_TEST
185 #define GL_FRONT Wt::WGLWidget::FRONT
186 #define GL_BACK Wt::WGLWidget::BACK
187 #define GL_FRONT_AND_BACK Wt::WGLWidget::FRONT_AND_BACK
188 #define GL_OUT_OF_MEMORY Wt::WGLWidget::OUT_OF_MEMORY
189 #define GL_LINE_STRIP Wt::WGLWidget::LINE_STRIP
190 #define GL_QUADS Wt::WGLWidget::QUADS
191 #define GL_LINE_LOOP Wt::WGLWidget::LINE_LOOP
192 #define GL_LINES Wt::WGLWidget::LINES
193 #define GL_POINTS Wt::WGLWidget::POINTS
194 #define GL_TRIANGLES Wt::WGLWidget::TRIANGLES
195 #define GL_TRIANGLE_STRIP Wt::WGLWidget::TRIANGLE_STRIP
196 #define GL_TRIANGLE_FAN Wt::WGLWidget::TRIANGLE_FAN
197 #define GL_FLOAT Wt::WGLWidget::FLOAT
198 #define GL_STENCIL_TEST Wt::WGLWidget::STENCIL_TEST
199 #define GL_ALWAYS Wt::WGLWidget::ALWAYS
200 #define GL_INVERT Wt::WGLWidget::INVERT
201 #define GL_COMPILE_AND_EXECUTE Wt::WGLWidget::COMPILE_AND_EXECUTE
202 #define GL_COMPILE Wt::WGLWidget::COMPILE
203 #define GL_COLOR_BUFFER_BIT Wt::WGLWidget::COLOR_BUFFER_BIT
204 #define GL_DEPTH_BUFFER_BIT Wt::WGLWidget::DEPTH_BUFFER_BIT
205 #define GL_STENCIL_BUFFER_BIT Wt::WGLWidget::STENCIL_BUFFER_BIT
206 #define GL_UNSIGNED_BYTE Wt::WGLWidget::UNSIGNED_BYTE
207 #define GL_ARRAY_BUFFER Wt::WGLWidget::ARRAY_BUFFER
208 #define GL_ELEMENT_ARRAY_BUFFER Wt::WGLWidget::ELEMENT_ARRAY_BUFFER
209 #define GL_RENDER Wt::WGLWidget::RENDER
210 #define GL_LUMINANCE Wt::WGLWidget::LUMINANCE
211 #define GL_STATIC_DRAW Wt::WGLWidget::STATIC_DRAW
212 #define GL_FRAGMENT_SHADER Wt::WGLWidget::FRAGMENT_SHADER
213 #define GL_VERTEX_SHADER Wt::WGLWidget::VERTEX_SHADER
214 #define GL_UNSIGNED_INT Wt::WGLWidget::UNSIGNED_INT
215 #define GL_UNSIGNED_SHORT Wt::WGLWidget::UNSIGNED_SHORT
216 #define GL_CULL_FACE Wt::WGLWidget::CULL_FACE
217 #define GL_MAX_VIEWPORT_DIMS Wt::WGLWidget::MAX_VIEWPORT_DIMS
218 #define GL_PROJECTION Wt::WGLWidget::FRAGMENT_SHADER // Not the good value, but should be ok, work together with GL_MODELVIEW
219 #define GL_MODELVIEW Wt::WGLWidget::VERTEX_SHADER // Not the good value, but should be ok, work together with GL_PROJECTION
220 
221 // to be implemented
222 #define GL_LINE 0
223 #define GL_FILL 0
224 #define GL_PROJECTION_MATRIX 0
225 #define GL_UNPACK_SWAP_BYTES 0
226 #define GL_UNPACK_LSB_FIRST 0
227 #define GL_UNPACK_SKIP_ROWS 0
228 #define GL_UNPACK_LOW_LENGHT 0
229 #define GL_UNPACK_SKIP_PIXELS 0
230 #define GL_UNPACK_ALIGNMENT 0
231 #define GL_UNPACK_ROW_LENGTH 0
232 #define GL_CLIP_PLANE0 Wt::WGLWidget::NONE
233 #define GL_CLIP_PLANE1 Wt::WGLWidget::NONE
234 #define GL_CLIP_PLANE2 Wt::WGLWidget::NONE
235 #define GL_CLIP_PLANE3 Wt::WGLWidget::NONE
236 #define GL_CLIP_PLANE4 Wt::WGLWidget::NONE
237 #define GL_COLOR_MATERIAL Wt::WGLWidget::NONE
238 #define GL_AMBIENT_AND_DIFFUSE Wt::WGLWidget::NONE
239 #define GL_POLYGON 0
240 #define GL_LIGHTING Wt::WGLWidget::NONE
241 #define GL_POINT_SMOOTH Wt::WGLWidget::NONE
242 #define GL_LINE_SMOOTH Wt::WGLWidget::NONE
243 #define GL_POLYGON_SMOOTH Wt::WGLWidget::NONE
244 #define GL_LIGHT0 Wt::WGLWidget::NONE
245 #define GL_AMBIENT Wt::WGLWidget::NONE
246 #define GL_DIFFUSE Wt::WGLWidget::NONE
247 #define GL_POSITION Wt::WGLWidget::NONE
248 
249 #define GLenum Wt::WGLWidget::GLenum
250 #define GLchar char
251 typedef unsigned char GLboolean;
252 typedef unsigned int GLbitfield;
253 typedef void GLvoid;
254 typedef char GLbyte;
255 typedef short GLshort;
256 typedef int GLint;
257 typedef unsigned char GLubyte;
258 typedef unsigned short GLushort;
259 typedef unsigned int GLuint;
260 typedef int GLsizei;
261 typedef float GLfloat;
262 typedef float GLclampf;
263 typedef double GLdouble;
264 typedef double GLclampd;
265 
266 
267 #else
268 
269 // +--------------------------------+
270 // + QT (OpenGL ES) case +
271 // +--------------------------------+
272 
273 class G4OpenGLImmediateQtViewer;
274 
275 #define glOrtho fVboDrawer->vboGlOrtho
276 #define glFrustum fVboDrawer->vboGlFrustum
277 #define glMultMatrixf fVboDrawer->vboGlMultMatrixf
278 #define glMultMatrixd fVboDrawer->vboGlMultMatrixd
279 #define glMatrixMode fVboDrawer->vboGlMatrixMode
280 #define glPointSize fVboDrawer->vboGlPointSize
281 #define glColor3d fVboDrawer->vboGlColor3d
282 #define glColor4d fVboDrawer->vboGlColor4d
283 #define glColor4fv fVboDrawer->vboGlColor4fv
284 
285 
286 #endif // G4VIS_BUILD_OPENGLQT_DRIVER
287 
288 
289 class G4OpenGLViewer;
290 
291 class G4OpenGLVboDrawer {
292 public:
293  G4OpenGLVboDrawer (G4OpenGLViewer*, std::string type);
294  // Create a new OpenGL Drawer. Type could be one of the following :
295  // OGL-ES, OGL-Stored, OGL-Immediate, OGL-VBO
296 
297  virtual ~G4OpenGLVboDrawer ();
298 
299 // WT specific
300 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
301  void vboGlClear(Wt::WFlags< GLenum > mask);
302  void vboGlUniformMatrix4(const Wt::WGLWidget::UniformLocation &location, const Wt::WMatrix4x4 &mat);
303  void vboGlUniformMatrix4(const Wt::WGLWidget::UniformLocation &location, const double* matrix);
304  void vboGlUniformMatrix4fv(const Wt::WGLWidget::UniformLocation &location, const float* matrix);
305  void vboGlUniformMatrix4(const Wt::WGLWidget::UniformLocation &location, const Wt::WGLWidget::JavaScriptMatrix4x4 &mat);
306  Wt::WGLWidget::Buffer vboGlCreateBuffer();
307  void vboGlBindBuffer(GLenum target, Wt::WGLWidget::Buffer buffer);
308  void vboGlDeleteBuffer(Wt::WGLWidget::Buffer buffer);
309  void vboGlVertexAttribPointer(Wt::WGLWidget::AttribLocation location, int size, GLenum type, bool normalized, unsigned stride, unsigned offset);
310  void vboGlShaderSource(Wt::WGLWidget::Shader shader, GLsizei , const GLchar **src, const GLint *);
311  void vboGlCompileShader(Wt::WGLWidget::Shader shader);
312  Wt::WGLWidget::Shader vboGlCreateShader(GLenum shader);
313  Wt::WGLWidget::Program vboGlCreateProgram();
314  void vboGlAttachShader(Wt::WGLWidget::Program program, Wt::WGLWidget::Shader shader);
315  void vboGlLinkProgram(Wt::WGLWidget::Program program);
316  void vboGlUseProgram(Wt::WGLWidget::Program program);
317  void vboGlEnableVertexAttribArray(Wt::WGLWidget::AttribLocation pointer);
318  void vboGlDisableVertexAttribArray(Wt::WGLWidget::AttribLocation pointer);
319  Wt::WGLWidget::UniformLocation vboGlGetUniformLocation(Wt::WGLWidget::Program programm,const std::string &src);
320  Wt::WGLWidget::AttribLocation vboGlGetAttribLocation(Wt::WGLWidget::Program shader,const std::string &src);
321 
322  void vboGlClearColor (double r, double g, double b, double a);
323  void vboGlClearDepth(double depth);
324  void vboGlViewport(int x, int y, unsigned width, unsigned height);
325  void vboGlEnable(GLenum cap);
326  void vboGlDisable(GLenum cap);
327  void vboGlBlendFunc (GLenum sfactor, GLenum dfactor);
328  void vboGlDepthFunc (GLenum func);
329  void vboGlDepthMask(bool flag);
330  void vboGlColorMask (bool red, bool green, bool blue, bool alpha);
331  void vboGlLineWidth(double width);
332  void vboGlDrawArrays(GLenum mode, int first, unsigned count);
333  void vboGlBufferDatafv(GLenum target, const std::vector<double>::iterator begin, const std::vector<double>::iterator end, GLenum usage);
334  void vboGlBufferDataiv(GLenum target, const std::vector<unsigned short>::iterator begin, const std::vector<unsigned short>::iterator end, GLenum usage, GLenum type);
335  void vboGlDrawElements(GLenum mode, unsigned count, GLenum type, unsigned offset);
336  void vboGlMultMatrixf( const GLfloat *m );
337  void vboGlMultMatrixd( const GLdouble *m );
338 #else
339  void vboGlMultMatrixf( const GLfloat *m );
340  void vboGlMultMatrixd( const GLdouble *m );
341 #endif
342 
343  void vboGlFlush();
344  void vboGlOrtho(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble);
345  void vboGlFrustum(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble);
346  void vboGlMatrixMode(GLenum);
347  void vboGlPointSize(float size);
348  inline void vboGlColor3d(int red,int green,int blue) {
349  vboGlColor4d(red,green, blue, 1.0);
350  }
351  void vboGlColor4d(int red,int green,int blue,int alpha);
352  void vboGlColor4fv(const GLfloat*);
353  inline const char * getFragmentShaderSrc() {
354  return fFragmentShaderSrc;
355  }
356  inline const char * getVertexShaderSrc() {
357  return fVertexShaderSrc;
358  }
359  inline bool isVBO() {
360  if ((fOGLType == "OGL-ES") || (fOGLType == "OGL-VBO")) {
361  return true;
362  }
363  return false;
364  }
365  inline void empty() {}
366  inline GLuint returnNULL() {
367  return 0;
368  }
369 
370 private:
371  const char *fFragmentShaderSrc;
372  const char *fVertexShaderSrc;
373  std::string fOGLType;
374  GLenum fMatrixMode;
375 
376 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
377  G4OpenGLImmediateWtViewer* fVboViewer;
378 #else
379  G4OpenGLImmediateQtViewer* fVboViewer;
380 #endif // G4VIS_BUILD_OPENGLWT_DRIVER
381 };
382 
383 #endif // G4OPENGL_VERSION_2
384 
385 #endif // G4OpenGLVboDrawer_HH
386 
const XML_Char * target
Definition: expat.h:268
Definition: test07.cc:36
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
static ush mask[]
Definition: csz_inflate.cc:317
#define width
#define buffer
Definition: xmlparse.cc:628
tuple x
Definition: test.py:50
Definition: test07.cc:36
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
tuple b
Definition: test.py:12
static constexpr double m
Definition: G4SIunits.hh:129
void usage()
Definition: genwindef.cpp:23
static const G4double alpha