ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4OpenGLVboDrawer.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4OpenGLVboDrawer.cc
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 // G4OpenGLWtViewer : Class to provide Vertex Buffer Object (VBO) specific
30 // functionality for OpenGL > 2.0 in GEANT4
31 //
32 
33 #include "G4OpenGLViewer.hh"
34 #ifdef G4OPENGL_VERSION_2
35 
36 #include "G4OpenGLVboDrawer.hh"
37 
38 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
40 #else
42 #endif
43 
44 
46 G4OpenGLVboDrawer::G4OpenGLVboDrawer (G4OpenGLViewer* viewer,
47  std::string type
48  ):
49 fVboViewer(NULL),
50 fOGLType(type)
53 {
54 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
55  G4OpenGLImmediateWtViewer* v = dynamic_cast<G4OpenGLImmediateWtViewer*>(viewer);
56 #else
57  G4OpenGLImmediateQtViewer* v = dynamic_cast<G4OpenGLImmediateQtViewer*>(viewer);
58 #endif
59  if (v) {
60  fVboViewer = v;
61  }
62 
63  fFragmentShaderSrc =
64  "#ifdef GL_ES\n"
65  "precision highp float;\n"
66  "#endif\n"
67  "\n"
68  "varying vec3 vLightWeighting;\n"
69  "uniform vec4 uPointColor; // Point Color\n"
70  "\n"
71  "void main(void) {\n"
72  " vec4 matColor = uPointColor;\n"
73  " gl_FragColor = vec4(matColor.rgb, matColor.a);\n"
74  "}\n";
75 
76 
77 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
78  fVertexShaderSrc =
79  "attribute vec3 aVertexPosition;\n"
80  "attribute vec3 aVertexNormal;\n"
81  "\n"
82  "uniform mat4 uMVMatrix; // [M]odel[V]iew matrix\n"
83  "uniform mat4 uCMatrix; // Client-side manipulated [C]amera matrix\n"
84  "uniform mat4 uPMatrix; // Perspective [P]rojection matrix\n"
85  "uniform mat4 uNMatrix; // [N]ormal transformation\n"
86  "// uNMatrix is the transpose of the inverse of uCMatrix * uMVMatrix\n"
87  "uniform mat4 uTMatrix; // [T]ransformation matrix\n"
88  "uniform float uPointSize; // Point size\n"
89  "\n"
90  "varying vec3 vLightWeighting;\n"
91  "\n"
92  "void main(void) {\n"
93  " // Calculate the position of this vertex\n"
94  " gl_Position = uPMatrix * uCMatrix * uMVMatrix * uTMatrix * vec4(aVertexPosition, 1.0);\n"
95  "\n"
96  " // Phong shading\n"
97  " vec3 transformedNormal = normalize((uNMatrix * vec4(normalize(aVertexNormal), 0)).xyz);\n"
98  " vec3 lightingDirection = normalize(vec3(1, 1, 1));\n"
99  " float directionalLightWeighting = max(dot(transformedNormal, lightingDirection), 0.0);\n"
100  " vec3 uAmbientLightColor = vec3(0.2, 0.2, 0.2);\n"
101  " vec3 uDirectionalColor = vec3(0.8, 0.8, 0.8);\n"
102  " gl_PointSize = uPointSize;\n"
103  " vLightWeighting = uAmbientLightColor + uDirectionalColor * directionalLightWeighting;\n"
104  "}\n";
105 
106 #else
107 
108 
109  fVertexShaderSrc =
110  "attribute highp vec4 aVertexPosition;\n"
111  "attribute vec3 aVertexNormal;\n"
112  "uniform highp mat4 uCMatrix;\n"
113  "uniform highp mat4 uPMatrix; // Perspective [P]rojection matrix\n"
114  "uniform highp mat4 uMVMatrix; // [M]odel[V]iew matrix\n"
115  "uniform highp mat4 uTMatrix; // [T]ransformation matrix\n"
116  "uniform float uPointSize; // Point size\n"
117  "void main(void)\n"
118  "{\n"
119  " gl_Position = uPMatrix * uCMatrix * uMVMatrix * uTMatrix * aVertexPosition;\n"
120  " // Phong shading\n"
121  // " vec3 transformedNormal = normalize((uNMatrix * vec4(normalize(aVertexNormal), 0)).xyz);\n"
122  " vec3 lightingDirection = normalize(vec3(1, 1, 1));\n"
123  // " float directionalLightWeighting = max(dot(transformedNormal, lightingDirection), 0.0);\n"
124  // " vec3 uAmbientLightColor = vec3(0.2, 0.2, 0.2);\n"
125  // " vec3 uDirectionalColor = vec3(0.8, 0.8, 0.8);\n"
126  " gl_PointSize = uPointSize;\n"
127  // " vLightWeighting = uAmbientLightColor + uDirectionalColor * directionalLightWeighting;\n"
128  "}";
129 #endif
130 
131 
132 }
133 
135 G4OpenGLVboDrawer::~G4OpenGLVboDrawer (
136 )
139 {
140 }
141 // +--------------------------------+
142 // + WT (OpenGL ES) case +
143 // +--------------------------------+
144 
145 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
146 
147 void G4OpenGLVboDrawer:: vboGlClear(Wt::WFlags< GLenum > mask) {
148  if (fVboViewer->isInitialized()) {
149  fVboViewer->clear(mask);
150  }
151 }
152 
153 
154 void G4OpenGLVboDrawer:: vboGlUniformMatrix4(const Wt::WGLWidget::UniformLocation &location, const Wt::WMatrix4x4 &m) {
155  if (fVboViewer) {
156  vboGlUseProgram(fVboViewer->getShaderProgram());
157  fVboViewer->uniformMatrix4(location, m);
158  }
159 }
160 
161 
162 void G4OpenGLVboDrawer:: vboGlUniformMatrix4(const Wt::WGLWidget::UniformLocation &location, const double* matrix) {
163  if (fVboViewer) {
164  Wt::WMatrix4x4 mat(
165  (double) matrix[0], (double) matrix[4], (double) matrix[8], (double) matrix[12],
166  (double) matrix[1], (double) matrix[5], (double) matrix[9], (double) matrix[13],
167  (double) matrix[2], (double) matrix[6], (double) matrix[10],(double) matrix[14],
168  (double) matrix[3],(double) matrix[7],(double) matrix[11],(double) matrix[15]);
169 
170  fVboViewer->uniformMatrix4(location, mat);
171  }
172 }
173 
174 void G4OpenGLVboDrawer:: vboGlUniformMatrix4fv(const Wt::WGLWidget::UniformLocation &location, const float* matrix) {
175  if (fVboViewer) {
176  Wt::WMatrix4x4 mat(
177  (double) matrix[0], (double) matrix[4], (double) matrix[8], (double) matrix[12],
178  (double) matrix[1], (double) matrix[5], (double) matrix[9], (double) matrix[13],
179  (double) matrix[2], (double) matrix[6], (double) matrix[10],(double) matrix[14],
180  (double) matrix[3],(double) matrix[7],(double) matrix[11],(double) matrix[15]);
181 
182  fVboViewer->uniformMatrix4(location, mat);
183  }
184 }
185 
186 void G4OpenGLVboDrawer:: vboGlUniformMatrix4(const Wt::WGLWidget::UniformLocation &location, const Wt::WGLWidget::JavaScriptMatrix4x4 &m) {
187  if (fVboViewer->isInitialized()) {
188  fVboViewer->uniformMatrix4(location, m);
189  }
190 }
191 
192 Wt::WGLWidget::Buffer G4OpenGLVboDrawer:: vboGlCreateBuffer(){
193  if (fVboViewer) {
194  return fVboViewer->createBuffer();
195  }
196  return Wt::WGLWidget::Buffer();
197 }
198 
199 void G4OpenGLVboDrawer:: vboGlBindBuffer(GLenum target, Wt::WGLWidget::Buffer buffer){
200  if (fVboViewer) {
201  fVboViewer->bindBuffer(target,buffer);
202  }
203 }
204 
205 void G4OpenGLVboDrawer:: vboGlDeleteBuffer(Wt::WGLWidget::Buffer buffer){
206  if (fVboViewer == NULL) return;
207  fVboViewer->deleteBuffer(buffer);
208 }
209 
210 void G4OpenGLVboDrawer:: vboGlVertexAttribPointer(Wt::WGLWidget::AttribLocation location, int size, GLenum type, bool normalized, unsigned stride, unsigned offset){
211  if (fVboViewer->isInitialized()) {
212  fVboViewer->vertexAttribPointer(location, size,type, normalized, stride, offset);
213  }
214 }
215 
216 Wt::WGLWidget::Program G4OpenGLVboDrawer:: vboGlCreateProgram(){
217  if (fVboViewer) {
218  return fVboViewer->createProgram();
219  }
220  return Wt::WGLWidget::Program();
221 }
222 
223 void G4OpenGLVboDrawer:: vboGlAttachShader(Wt::WGLWidget::Program program, Shader shader){
224  if (fVboViewer) {
225  fVboViewer->attachShader(program,shader);
226  }
227 }
228 
229 void G4OpenGLVboDrawer:: vboGlLinkProgram(Wt::WGLWidget::Program program){
230  if (fVboViewer) {
231  fVboViewer->linkProgram(program);
232  }
233 }
234 
235 void G4OpenGLVboDrawer:: vboGlUseProgram(Wt::WGLWidget::Program program){
236  if (fVboViewer) {
237  fVboViewer->useProgram(program);
238  }
239 }
240 
241 void G4OpenGLVboDrawer:: vboGlEnableVertexAttribArray(Wt::WGLWidget::AttribLocation pointer){
242  if (fVboViewer) {
243  fVboViewer->enableVertexAttribArray(pointer);
244  }
245 }
246 
247 void G4OpenGLVboDrawer:: vboGlDisableVertexAttribArray(Wt::WGLWidget::AttribLocation pointer){
248  if (fVboViewer) {
249  fVboViewer->disableVertexAttribArray(pointer);
250  }
251 }
252 
253 Wt::WGLWidget::UniformLocation G4OpenGLVboDrawer:: vboGlGetUniformLocation(Wt::WGLWidget::Program programm,const std::string &src){
254  if (fVboViewer) {
255  return fVboViewer->getUniformLocation(programm, src);
256  }
257  return Wt::WGLWidget::UniformLocation();
258 }
259 
260 Wt::WGLWidget::AttribLocation G4OpenGLVboDrawer:: vboGlGetAttribLocation(Wt::WGLWidget::Program shader,const std::string &src){
261  if (fVboViewer) {
262  return fVboViewer->getAttribLocation(shader, src);
263  }
264  return Wt::WGLWidget::AttribLocation();
265 }
266 
267 
268 
269 
270 
271 void G4OpenGLVboDrawer::vboGlClearColor (double r, double g, double b, double a) {
272 
273  if (fVboViewer->isInitialized() ) {
274 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
275  fVboViewer->clearColor(r,g,b,a);
276 #else
277 #endif
278  }
279 }
280 
281 void G4OpenGLVboDrawer::vboGlClearDepth(double depth) {
282  if (fVboViewer->isInitialized()) {
283 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
284  fVboViewer->clearDepth(depth);
285 #else
286  glClearDepth(depth);
287 #endif
288  }
289 }
290 
291 
292 void G4OpenGLVboDrawer::vboGlFlush() {
293  if (fVboViewer->isInitialized()) {
294 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
295  fVboViewer->flush();
296 #else
297 #endif
298  }
299 }
300 
301 void G4OpenGLVboDrawer:: vboGlViewport(int x, int y, unsigned width, unsigned height) {
302  if (fVboViewer->isInitialized()) {
303 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
304  fVboViewer->viewport(x,y,width,height);
305 #else
306 #endif
307  }
308 }
309 
310 void G4OpenGLVboDrawer:: vboGlEnable(GLenum cap) {
311  if (fVboViewer->isInitialized()) {
312 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
313  if (cap != Wt::WGLWidget::NONE) {
314  fVboViewer->enable(cap);
315  }
316 #else
317 #endif
318  }
319 }
320 
321 void G4OpenGLVboDrawer:: vboGlDisable(GLenum cap) {
322  if (fVboViewer->isInitialized()) {
323 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
324  if (cap != Wt::WGLWidget::NONE) {
325  fVboViewer->disable(cap);
326  }
327 #else
328 #endif
329  }
330 }
331 
332 void G4OpenGLVboDrawer:: vboGlBlendFunc (GLenum sfactor, GLenum dfactor) {
333  if (fVboViewer->isInitialized()) {
334 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
335  fVboViewer->blendFunc(sfactor, dfactor);
336 #else
337 #endif
338 
339  }
340 }
341 
342 void G4OpenGLVboDrawer:: vboGlDepthFunc (GLenum func) {
343  if (fVboViewer->isInitialized()) {
344 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
345  fVboViewer->depthFunc(func);
346 #else
347 #endif
348  }
349 }
350 
351 void G4OpenGLVboDrawer:: vboGlDepthMask(bool flag) {
352  if (fVboViewer->isInitialized()) {
353 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
354  fVboViewer->depthMask(flag);
355 #else
356 #endif
357  }
358 }
359 
360 void G4OpenGLVboDrawer:: vboGlColorMask (bool red, bool green, bool blue, bool alpha) {
361  if (fVboViewer->isInitialized()) {
362 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
363  fVboViewer->colorMask(red,green,blue,alpha);
364 #else
365 #endif
366  }
367 }
368 
369 void G4OpenGLVboDrawer:: vboGlLineWidth(double width) {
370  if (fVboViewer->isInitialized()) {
371 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
372  fVboViewer->lineWidth(width);
373 #else
374 #endif
375  }
376 }
377 
378 
379 void G4OpenGLVboDrawer:: vboGlDrawArrays(GLenum mode, int first, unsigned count){
380  if (fVboViewer->isInitialized()) {
381 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
382  fVboViewer->drawArrays(mode,first, count);
383 #else
384 #endif
385  }
386 }
387 
388 void G4OpenGLVboDrawer:: vboGlDrawElements(GLenum mode, unsigned count, GLenum type, unsigned offset){
389  if (fVboViewer->isInitialized()) {
390 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
391  fVboViewer->drawElements(mode,count,type,offset);
392 #else
393 #endif
394  }
395 }
396 
397 void G4OpenGLVboDrawer:: vboGlBufferDatafv(GLenum target, const std::vector<double>::iterator begin, const std::vector<double>::iterator end, GLenum usage){
398  if (fVboViewer) {
399  if (fVboViewer->isInitialized()) {
400  fVboViewer->bufferDatafv(target,begin,end,usage);
401  }
402  }
403 }
404 
405 void G4OpenGLVboDrawer:: vboGlBufferDataiv(GLenum target, const std::vector<unsigned short>::iterator begin, const std::vector<unsigned short>::iterator end, GLenum usage, GLenum type){
406  if (fVboViewer) {
407  if (fVboViewer->isInitialized()) {
408  fVboViewer->bufferDataiv(target,begin,end,usage,type);
409  }
410  }
411 }
412 
413 
414 void G4OpenGLVboDrawer:: vboGlMultMatrixd(const GLdouble *matrix){
415  if (fVboViewer) {
416  if (fVboViewer->isInitialized()) {
417  Wt::WMatrix4x4 mat(
418  (double) matrix[0], (double) matrix[4], (double) matrix[8], (double) matrix[12],
419  (double) matrix[1], (double) matrix[5], (double) matrix[9], (double) matrix[13],
420  (double) matrix[2], (double) matrix[6], (double) matrix[10],(double) matrix[14],
421  (double) matrix[3],(double) matrix[7],(double) matrix[11],(double) matrix[15]);
422 
423  // FIXME !
424  fVboViewer->uniformMatrix4(fVboViewer->getShaderTransformMatrix(),mat);
425  if (fMatrixMode == GL_MODELVIEW) {
426  // fVboViewer->uniformMatrix4(fVboViewer->getShaderTransformMatrix(),mat);
427  } else {
428  G4cerr << "glMultMatrixd could only be used in GL_MODELVIEW mode" << G4endl;
429  }
430  }
431  }
432 }
433 
434 void G4OpenGLVboDrawer:: vboGlMultMatrixf(const GLfloat *matrix){
435  if (fVboViewer) {
436  if (fVboViewer->isInitialized()) {
437  Wt::WMatrix4x4 mat(
438  matrix[0], matrix[4], matrix[8], matrix[12],
439  matrix[1], matrix[5], matrix[9], matrix[13],
440  matrix[2], matrix[6], matrix[10], matrix[14],
441  matrix[3], matrix[7], matrix[11], matrix[15]);
442 
443  if (fMatrixMode == GL_MODELVIEW) {
444  fVboViewer->uniformMatrix4(fVboViewer->getShaderTransformMatrix(),mat);
445  } else {
446  G4cerr << "glMultMatrixf could only be used in GL_MODELVIEW mode" << G4endl;
447  }
448  }
449  }
450 }
451 
452 void G4OpenGLVboDrawer:: vboGlShaderSource(Shader shader, GLsizei , const GLchar **src, const GLint *){
453  if (fVboViewer) {
454  std::string s = *src;
455  fVboViewer->shaderSource(shader, s);
456  }
457 }
458 
459 void G4OpenGLVboDrawer:: vboGlCompileShader(Shader shader){
460  if (fVboViewer) {
461  fVboViewer->compileShader(shader);
462  }
463 }
464 
465 Shader G4OpenGLVboDrawer:: vboGlCreateShader(GLenum shader){
466  if (fVboViewer) {
467  return fVboViewer->createShader(shader);
468  }
469  return Shader();
470 }
471 
472 #else
473 
474 // +--------------------------------+
475 // + QT (OpenGL ES) case +
476 // +--------------------------------+
477 
478 void G4OpenGLVboDrawer:: vboGlMultMatrixf(const GLfloat *matrix){
479  if (fVboViewer) {
480  if (fVboViewer->isInitialized()) {
481  // FIXME
482  // glUniformMatrix4fv(12, 1, 0, 0x7fff5fbf5d00)
483  // Error: GL_INVALID_OPERATION
484 
485  if (fMatrixMode == GL_MODELVIEW) {
486  glUniformMatrix4fv(fVboViewer->getShaderTransformMatrix(),1,0,matrix);
487  } else {
488  G4cerr << "glMultMatrixf could only be used in GL_MODELVIEW mode" << G4endl;
489  }
490  }
491  }
492 }
493 
494 
495 void G4OpenGLVboDrawer:: vboGlMultMatrixd(const GLdouble *matrix){
496  if (fVboViewer) {
497  if (fVboViewer->isInitialized()) {
498  // FIXME !
499  // if (fMatrixMode == GL_MODELVIEW) {
500  // printf("G4OpenGLVboDrawer:: vboGlMultMatrixd %d %d\n",fVboViewer->getShaderTransformMatrix(), matrix);
502  float mat[16] = {
503  matrix[0],matrix[1],matrix[2],matrix[3],
504  matrix[4],matrix[5],matrix[6],matrix[7],
505  matrix[8],matrix[9],matrix[10],matrix[11],
506  matrix[12],matrix[13],matrix[14],matrix[15]
507  };
508 
509  glUniformMatrix4fv(fVboViewer->getShaderTransformMatrix(),1,0,mat);
510  GLenum e = glGetError();
511  printf("GL error : %d",e);
512  // } else {
513  // G4cerr << "glMultMatrixd could only be used in GL_MODELVIEW mode" << G4endl;
514  // }
515  }
516  }
517 }
518 
519 
520 
521 #endif
522 // +--------------------------------+
523 // + All case +
524 // +--------------------------------+
525 
526 
527 
528 void G4OpenGLVboDrawer::vboGlOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar) {
529  if (fVboViewer) {
530  if (fVboViewer->isInitialized()) {
531  printf("glOrtho implemented --- %f %f %f %f %f %f \n",left, right, bottom, top, zNear, zFar);
532  float a = 2.0f / (right - left);
533  float b = 2.0f / (top - bottom);
534  float c = -2.0f / (zFar - zNear);
535 
536  float tx = - (right + left)/(right - left);
537  float ty = - (top + bottom)/(top - bottom);
538  float tz = - (zFar + zNear)/(zFar - zNear);
539 
540  float ortho[16] = {
541  a, 0, 0, 0,
542  0, b, 0, 0,
543  0, 0, c, 0,
544  tx, ty, tz, 1
545  };
546  // FIXME :
547  // glUniformMatrix4fv(0, 1, 0, 0x7fff5fbf5d00)
548  // Error: GL_INVALID_OPERATION
549 
550  if (fMatrixMode == GL_PROJECTION) {
551 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
552  vboGlUniformMatrix4fv(fVboViewer->getShaderProjectionMatrix(), ortho);
553 #else
554  glUniformMatrix4fv(fVboViewer->getShaderProjectionMatrix(), 1, 0, ortho);
555 #endif
556  } else {
557  G4cerr << "glFrustum could only be used in GL_PROJECTION mode" << G4endl;
558  }
559  }
560  }
561 }
562 
563 
564 void G4OpenGLVboDrawer::vboGlFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar) {
565  if (fVboViewer) {
566  if (fVboViewer->isInitialized()) {
567  float deltaX = right - left;
568  float deltaY = top - bottom;
569  float deltaZ = zFar - zNear;
570 
571  float a = 2.0f * zNear / deltaX;
572  float b = 2.0f * zNear / deltaY;
573  float c = (right + left) / deltaX;
574  float d = (top + bottom) / deltaY;
575  float e = -(zFar + zNear) / (zFar - zNear);
576  float f = -2.0f * zFar * zNear / deltaZ;
577 
578  float proj[16] = {
579  a, 0, 0, 0,
580  0, b, 0, 0,
581  c, d, e, -1.0f,
582  0, 0, f, 0
583  };
584 
585  if (fMatrixMode == GL_PROJECTION) {
586 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
587  vboGlUniformMatrix4fv(fVboViewer->getShaderProjectionMatrix(), proj);
588 #else
589  glUniformMatrix4fv(fVboViewer->getShaderProjectionMatrix(), 1, 0, proj);
590 #endif
591  } else {
592  G4cerr << "glFrustrum could only be used in GL_PROJECTION mode" << G4endl;
593  }
594  }
595  }
596 }
597 
598 
599 void G4OpenGLVboDrawer::vboGlMatrixMode(GLenum a) {
600  if (fVboViewer) {
601  if (fVboViewer->isInitialized()) {
602  printf("G4OpenGLVboDrawer::vboGlMatrixMode CHANGED :%d \n",a);
603  fMatrixMode = a;
604  }
605  }
606 }
607 
608 
609 void G4OpenGLVboDrawer::vboGlColor4d(int red,int green,int blue,int alpha) {
610  if (fVboViewer) {
611  if (fVboViewer->isInitialized()) {
612  // double color [] = { red, green, blue, alpha };
613  // FIXME : REMOVE /2 , used to render transparents for testing purpose
614 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
615  double color [] = { red, green, blue, 0.7 };
616  glUniform4fv (fVboViewer->getUniformLocation(fVboViewer->getShaderProgram(), "uPointColor"),color);
617 #else
618  alpha = 0.7;
619  glUniform4f (glGetUniformLocation(fVboViewer->getShaderProgram(), "uPointColor"),red, green, blue, alpha);
620 #endif
621  }
622  }
623 }
624 
625 void G4OpenGLVboDrawer:: vboGlColor4fv(const GLfloat* data) {
626  if (fVboViewer) {
627  if (fVboViewer->isInitialized()) {
628  double color [] = { (data[0]), (data[1]), (data[2]), 0.7};
629  // FIXME : REMOVE /2 , used to render transparents for testing purpose
630 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
631  glUniform4fv (fVboViewer->getUniformLocation(fVboViewer->getShaderProgram(), "uPointColor"),color);
632 #else
633  glUniform4f (glGetUniformLocation(fVboViewer->getShaderProgram(), "uPointColor"),color[0],color[1],color[2], color[3]);
634 #endif
635  }
636  }
637 }
638 
639 void G4OpenGLVboDrawer:: vboGlPointSize(float size) {
640  if (fVboViewer) {
641  if (fVboViewer->isInitialized()) {
642 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
643  glUniform1f(fVboViewer->getUniformLocation(fVboViewer->getShaderProgram(), "uPointSize"),size);
644 #else
645  glUniform1f (glGetUniformLocation(fVboViewer->getShaderProgram(), "uPointSize"),size);
646 #endif
647  }
648  }
649 }
650 
651 #endif
652