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