Geant4_10
G4OpenGLWtDrawer.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: G4OpenGLWtDrawer.cc 74103 2013-09-23 07:52:38Z lgarnier $
28 //
29 //
30 // G4OpenGLWtViewer : Class to provide Wt specific
31 // functionality for OpenGL in GEANT4
32 //
33 // 27/06/2003 : G.Barrand : implementation (at last !).
34 
35 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
36 
37 #include "G4OpenGLWtDrawer.hh"
39 
41 G4OpenGLWtDrawer::G4OpenGLWtDrawer (G4OpenGLViewer* viewer
42  ):
43 fWtViewer(NULL)
46 {
47  G4OpenGLImmediateWtViewer* v = dynamic_cast<G4OpenGLImmediateWtViewer*>(viewer);
48  if (v) {
49  fWtViewer = v;
50  }
51 }
52 
54 G4OpenGLWtDrawer::~G4OpenGLWtDrawer (
55 )
58 {
59 }
60 
61 void G4OpenGLWtDrawer::wglClearColor (double r, double g, double b, double a) {
62 
63  if (fWtViewer) {
64  fWtViewer->clearColor(r,g,b,a);
65  }
66 }
67 
68 void G4OpenGLWtDrawer::wglClearDepth(double depth) {
69  if (fWtViewer) {
70  fWtViewer->clearDepth(depth);
71  }
72 }
73 
74 void G4OpenGLWtDrawer::wglClear(Wt::WFlags< GLenum > mask) {
75  if (fWtViewer) {
76  fWtViewer->clear(mask);
77  }
78 }
79 
80 void G4OpenGLWtDrawer::wglFlush() {
81  if (fWtViewer) {
82  fWtViewer->flush();
83  }
84 }
85 
86 void G4OpenGLWtDrawer::wglViewport(int x, int y, unsigned width, unsigned height) {
87  if (fWtViewer) {
88  fWtViewer->viewport(x,y,width,height);
89  }
90 }
91 
92 void G4OpenGLWtDrawer::wglEnable(GLenum cap) {
93  if (fWtViewer) {
94  fWtViewer->enable(cap);
95  }
96 }
97 
98 void G4OpenGLWtDrawer::wglDisable(GLenum cap) {
99  if (fWtViewer) {
100  fWtViewer->disable(cap);
101  }
102 }
103 
104 void G4OpenGLWtDrawer::wglBlendFunc (GLenum sfactor, GLenum dfactor) {
105  if (fWtViewer) {
106  fWtViewer->blendFunc(sfactor, dfactor);
107  }
108 }
109 
110 void G4OpenGLWtDrawer::wglDepthFunc (GLenum func) {
111  if (fWtViewer) {
112  fWtViewer->depthFunc(func);
113  }
114 }
115 
116 void G4OpenGLWtDrawer::wglDepthMask(bool flag) {
117  if (fWtViewer) {
118  fWtViewer->depthMask(flag);
119  }
120 }
121 
122 void G4OpenGLWtDrawer::wglColorMask (bool red, bool green, bool blue, bool alpha) {
123  if (fWtViewer) {
124  fWtViewer->colorMask(red,green,blue,alpha);
125  }
126 }
127 
128 void G4OpenGLWtDrawer::wglLineWidth(double width) {
129  if (fWtViewer) {
130  fWtViewer->lineWidth(width);
131  }
132 }
133 
134 void G4OpenGLWtDrawer::wglUniformMatrix4(const Wt::WGLWidget::UniformLocation &location, const Wt::WMatrix4x4 &m) {
135  if (fWtViewer) {
136  fWtViewer->uniformMatrix4(location, m);
137  }
138 }
139 
140 void G4OpenGLWtDrawer::wglUniformMatrix4(const Wt::WGLWidget::UniformLocation &location, const Wt::WGLWidget::JavaScriptMatrix4x4 &m) {
141  if (fWtViewer) {
142  fWtViewer->uniformMatrix4(location, m);
143  }
144 }
145 
146 void G4OpenGLWtDrawer::wglDrawArrays(GLenum mode, int first, unsigned count){
147  if (fWtViewer) {
148  fWtViewer->drawArrays(mode,first, count);
149  }
150 }
151 
152 void G4OpenGLWtDrawer::wglDrawElements(GLenum mode, unsigned count, GLenum type, unsigned offset){
153  if (fWtViewer) {
154  fWtViewer->drawElements(mode,count,type,offset);
155  }
156 }
157 
158 Wt::WGLWidget::Buffer G4OpenGLWtDrawer::wglCreateBuffer(){
159  if (fWtViewer) {
160  return fWtViewer->createBuffer();
161  }
162  return NULL;
163 }
164 
165 void G4OpenGLWtDrawer::wglBindBuffer(GLenum target, Wt::WGLWidget::Buffer buffer){
166  if (fWtViewer) {
167  fWtViewer->bindBuffer(target,buffer);
168  }
169 }
170 
171 void G4OpenGLWtDrawer::wglDeleteBuffer(Wt::WGLWidget::Buffer buffer){
172  if (fWtViewer == NULL) return;
173  fWtViewer->deleteBuffer(buffer);
174 }
175 
176 void G4OpenGLWtDrawer::wglBufferDatafv(GLenum target, const std::vector<double>::iterator begin, const std::vector<double>::iterator end, GLenum usage){
177  if (fWtViewer) {
178  fWtViewer->bufferDatafv(target,begin,end,usage);
179  }
180 }
181 
182 void G4OpenGLWtDrawer::wglBufferDataiv(GLenum target, const std::vector<unsigned short>::iterator begin, const std::vector<unsigned short>::iterator end, GLenum usage){
183  if (fWtViewer) {
184  fWtViewer->bufferDataiv(target,begin,end,usage, GL_UNSIGNED_SHORT);
185  }
186 }
187 
188 void G4OpenGLWtDrawer::wglVertexAttribPointer(Wt::WGLWidget::AttribLocation location, int size, GLenum type, bool normalized, unsigned stride, unsigned offset){
189  if (fWtViewer) {
190  fWtViewer->vertexAttribPointer(location, size,type, normalized, stride, offset);
191  }
192 }
193 
194 void G4OpenGLWtDrawer::wglMultMatrixd(const GLdouble *matrix){
195  if (fWtViewer) {
196  Wt::WMatrix4x4 mat(
197  (double) matrix[0], (double) matrix[4], (double) matrix[8], (double) matrix[12],
198  (double) matrix[1], (double) matrix[5], (double) matrix[9], (double) matrix[13],
199  (double) matrix[2], (double) matrix[6], (double) matrix[10],(double) matrix[14],
200  (double) matrix[3],(double) matrix[7],(double) matrix[11],(double) matrix[15]);
201 
202  fWtViewer->uniformMatrix4(fWtViewer->getUniformLocation(fWtViewer->shaderProgram_, "uTMatrix"),mat);
203  }
204 }
205 
206 void G4OpenGLWtDrawer::wglPointSize(float size) {
207  if (fWtViewer) {
208  fWtViewer->uniform1f (fWtViewer->getUniformLocation(fWtViewer->shaderProgram_, "uPointSize"),size);
209  }
210 }
211 
212 void G4OpenGLWtDrawer::wglColor4d(int red,int green,int blue,int alpha) {
213  if (fWtViewer) {
214  // double color [] = { red, green, blue, alpha };
215  double color [] = { red, green, blue, 0.7 };
216  // FIXME : REMOVE /2 , used to render transparents for testing purpose
217  fWtViewer->uniform4fv (fWtViewer->getUniformLocation(fWtViewer->shaderProgram_, "uPointColor"),color);
218  }
219 }
220 
221 void G4OpenGLWtDrawer::wglColor4fv(const GLfloat* data) {
222  if (fWtViewer) {
223  // double color [] = { (data[0]), (data[1]), (data[2]), (data[3])};
224  double color [] = { (data[0]), (data[1]), (data[2]), 0.7};
225  // FIXME : REMOVE /2 , used to render transparents for testing purpose
226  fWtViewer->uniform4fv (fWtViewer->getUniformLocation(fWtViewer->shaderProgram_, "uPointColor"),color);
227  }
228 }
229 
230 void G4OpenGLWtDrawer::wglShaderSource(Shader shader, GLsizei , const GLchar **src, const GLint *){
231  if (fWtViewer) {
232  std::string s = *src;
233  fWtViewer->shaderSource(shader, s);
234  }
235 }
236 
237 void G4OpenGLWtDrawer::wglCompileShader(Shader shader){
238  if (fWtViewer) {
239  fWtViewer->compileShader(shader);
240  }
241 }
242 
243 Shader G4OpenGLWtDrawer::wglCreateShader(GLenum shader){
244  if (fWtViewer) {
245  return fWtViewer->createShader(shader);
246  }
247  return NULL;
248 }
249 
250 Wt::WGLWidget::Program G4OpenGLWtDrawer::wglCreateProgram(){
251  if (fWtViewer) {
252  return fWtViewer->createProgram();
253  }
254  return NULL;
255 }
256 
257 void G4OpenGLWtDrawer::wglAttachShader(Wt::WGLWidget::Program program, Shader shader){
258  if (fWtViewer) {
259  fWtViewer->attachShader(program,shader);
260  }
261 }
262 
263 void G4OpenGLWtDrawer::wglLinkProgram(Wt::WGLWidget::Program program){
264  if (fWtViewer) {
265  fWtViewer->linkProgram(program);
266  }
267 }
268 
269 void G4OpenGLWtDrawer::wglUseProgram(Wt::WGLWidget::Program program){
270  if (fWtViewer) {
271  fWtViewer->useProgram(program);
272  }
273 }
274 
275 void G4OpenGLWtDrawer::wglEnableVertexAttribArray(Wt::WGLWidget::AttribLocation pointer){
276  if (fWtViewer) {
277  fWtViewer->enableVertexAttribArray(pointer);
278  }
279 }
280 
281 void G4OpenGLWtDrawer::wglDisableVertexAttribArray(Wt::WGLWidget::AttribLocation pointer){
282  if (fWtViewer) {
283  fWtViewer->disableVertexAttribArray(pointer);
284  }
285 }
286 
287 Wt::WGLWidget::UniformLocation G4OpenGLWtDrawer::wglGetUniformLocation(Wt::WGLWidget::Program programm,const std::string &src){
288  if (fWtViewer) {
289  return fWtViewer->getUniformLocation(programm, src);
290  }
291  return NULL;
292 }
293 
294 Wt::WGLWidget::AttribLocation G4OpenGLWtDrawer::wglGetAttribLocation(Shader shader,const std::string &src){
295  if (fWtViewer) {
296  return fWtViewer->getAttribLocation(shader, src);
297  }
298  return NULL;
299 }
300 
301 
302 #endif
Definition: test07.cc:36
tuple a
Definition: test.py:11
const XML_Char * s
Definition: expat.h:262
#define width
#define buffer
Definition: xmlparse.cc:611
tuple x
Definition: test.py:50
const XML_Char * target
Definition: expat.h:268
Definition: test07.cc:36
Float_t mat
Definition: plot.C:40
Double_t y
Definition: plot.C:279
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
tuple b
Definition: test.py:12
tuple v
Definition: test.py:18
jump r
Definition: plot.C:36
G4int first
void usage()
Definition: genwindef.cpp:23
const XML_Char const XML_Char * data
Definition: expat.h:268