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