Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4OpenGLSceneHandler.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: G4OpenGLSceneHandler.cc 75567 2013-11-04 11:35:11Z gcosmo $
28 //
29 //
30 // Andrew Walkden 27th March 1996
31 // OpenGL stored scene - creates OpenGL display lists.
32 // OpenGL immediate scene - draws immediately to buffer
33 // (saving space on server).
34 
35 #ifdef G4VIS_BUILD_OPENGL_DRIVER
36 
37 #include "G4OpenGLSceneHandler.hh"
38 #include "G4OpenGLViewer.hh"
39 #include "G4OpenGLTransform3D.hh"
40 #include "G4Point3D.hh"
41 #include "G4Normal3D.hh"
42 #include "G4Transform3D.hh"
43 #include "G4Polyline.hh"
44 #include "G4Polymarker.hh"
45 #include "G4Text.hh"
46 #include "G4Circle.hh"
47 #include "G4Square.hh"
48 #include "G4VMarker.hh"
49 #include "G4Polyhedron.hh"
50 #include "G4VisAttributes.hh"
51 #include "G4PhysicalVolumeModel.hh"
52 #include "G4VPhysicalVolume.hh"
53 #include "G4LogicalVolume.hh"
54 #include "G4VSolid.hh"
55 #include "G4Scene.hh"
56 #include "G4VisExtent.hh"
57 #include "G4AttHolder.hh"
58 #include "G4PhysicalConstants.hh"
59 
60 G4OpenGLSceneHandler::G4OpenGLSceneHandler (G4VGraphicsSystem& system,
61  G4int id,
62  const G4String& name):
63 G4VSceneHandler (system, id, name),
64 #ifdef G4OPENGL_VERSION_2
65 fEmulate_GL_QUADS(false),
66 #endif
67 fPickName(0),
68 // glFlush take about 90% time. Dividing glFlush number by 100 will
69 // change the first vis time from 100% to 10+90/100 = 10,9%.
70 fEventsDrawInterval(1),
71 fEventsWaitingToBeFlushed(0),
72 fThreePassCapable(false),
73 fSecondPassForTransparencyRequested(false),
74 fSecondPassForTransparency(false),
75 fThirdPassForNonHiddenMarkersRequested(false),
76 fThirdPassForNonHiddenMarkers(false)
77 {
78 }
79 
80 G4OpenGLSceneHandler::~G4OpenGLSceneHandler ()
81 {
82  ClearStore ();
83 }
84 
85 const GLubyte G4OpenGLSceneHandler::fStippleMaskHashed [128] = {
86  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
87  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
88  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
89  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
90  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
91  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
92  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
93  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
94  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
95  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
96  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
97  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
98  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
99  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
100  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
101  0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
102 };
103 
104 void G4OpenGLSceneHandler::ClearAndDestroyAtts()
105 {
106  std::map<GLuint, G4AttHolder*>::iterator i;
107  for (i = fPickMap.begin(); i != fPickMap.end(); ++i) delete i->second;
108  fPickMap.clear();
109 }
110 
111 void G4OpenGLSceneHandler::ScaledFlush()
112 {
113  fEventsWaitingToBeFlushed++;
114  if (fEventsWaitingToBeFlushed < fEventsDrawInterval) return;
115  glFlush();
116  fEventsWaitingToBeFlushed = 0;
117 }
118 
119 void G4OpenGLSceneHandler::ProcessScene()
120 {
121  fThreePassCapable = true;
122 
124 
125  // Repeat if required...
126  if (fSecondPassForTransparencyRequested) {
127  fSecondPassForTransparency = true;
129  fSecondPassForTransparency = false;
130  fSecondPassForTransparencyRequested = false;
131  }
132 
133  // And again if required...
134  if (fThirdPassForNonHiddenMarkersRequested) {
135  fThirdPassForNonHiddenMarkers = true;
137  fThirdPassForNonHiddenMarkers = false;
138  fThirdPassForNonHiddenMarkersRequested = false;
139  }
140 
141  fThreePassCapable = false;
142 }
143 
144 void G4OpenGLSceneHandler::PreAddSolid
145 (const G4Transform3D& objectTransformation,
146  const G4VisAttributes& visAttribs)
147 {
148  G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs);
149 }
150 
151 void G4OpenGLSceneHandler::BeginPrimitives
152 (const G4Transform3D& objectTransformation)
153 {
154  G4VSceneHandler::BeginPrimitives (objectTransformation);
155 }
156 
157 void G4OpenGLSceneHandler::EndPrimitives ()
158 {
160 }
161 
162 void G4OpenGLSceneHandler::BeginPrimitives2D
163 (const G4Transform3D& objectTransformation)
164 {
165  G4VSceneHandler::BeginPrimitives2D (objectTransformation);
166 }
167 
168 void G4OpenGLSceneHandler::EndPrimitives2D ()
169 {
171 }
172 
173 G4VSolid* G4OpenGLSceneHandler::CreateSectionSolid ()
174 {
175  // Clipping done in G4OpenGLViewer::SetView.
176  // return 0;
177 
178  // But...OpenGL no longer seems to reconstruct clipped edges, so,
179  // when the BooleanProcessor is up to it, abandon this and use
180  // generic clipping in G4VSceneHandler::CreateSectionSolid...
182 }
183 
184 G4VSolid* G4OpenGLSceneHandler::CreateCutawaySolid ()
185 {
186  // Cutaway done in G4OpenGLViewer::SetView.
187  // return 0;
188 
189  // But...if not, when the BooleanProcessor is up to it...
191 }
192 
193 void G4OpenGLSceneHandler::AddPrimitive (const G4Polyline& line)
194 {
195  G4int nPoints = line.size ();
196  if (nPoints <= 0) return;
197 
198  // Note: colour and depth test treated in sub-class.
199 
200  glDisable (GL_LIGHTING);
201 
202  // Get vis attributes - pick up defaults if none.
203  const G4VisAttributes* pVA =
204  fpViewer -> GetApplicableVisAttributes (line.GetVisAttributes ());
205 
206  G4double lineWidth = GetLineWidth(pVA);
207  // Need access to method in G4OpenGLViewer. static_cast doesn't
208  // work with a virtual base class, so use dynamic_cast. No need to
209  // test the outcome since viewer is guaranteed to be a
210  // G4OpenGLViewer, but test it anyway to keep Coverity happy.
211  G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
212  if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth);
213 
214 #ifndef G4OPENGL_VERSION_2
215  glBegin (GL_LINE_STRIP);
216  for (G4int iPoint = 0; iPoint < nPoints; iPoint++) {
217  G4double x, y, z;
218  x = line[iPoint].x();
219  y = line[iPoint].y();
220  z = line[iPoint].z();
221  glVertex3d (x, y, z);
222  }
223  glEnd ();
224 #else
225  glBeginVBO(GL_LINE_STRIP);
226 
227  for (G4int iPoint = 0; iPoint < nPoints; iPoint++) {
228  fOglVertex.push_back(line[iPoint].x());
229  fOglVertex.push_back(line[iPoint].y());
230  fOglVertex.push_back(line[iPoint].z());
231  // normal
232  fOglVertex.push_back(0);
233  fOglVertex.push_back(0);
234  fOglVertex.push_back(1);
235  }
236 
237  glEndVBO();
238 #endif
239 }
240 
241 void G4OpenGLSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
242 {
243  if (polymarker.size() == 0) {
244  return;
245  }
246 
247  // Note: colour and depth test treated in sub-class.
248 
249  glDisable (GL_LIGHTING);
250 
251  // Get vis attributes - pick up defaults if none.
252  const G4VisAttributes* pVA =
253  fpViewer -> GetApplicableVisAttributes (polymarker.GetVisAttributes ());
254 
255  G4double lineWidth = GetLineWidth(pVA);
256  // Need access to method in G4OpenGLViewer. static_cast doesn't
257  // work with a virtual base class, so use dynamic_cast. No need to
258  // test the outcome since viewer is guaranteed to be a
259  // G4OpenGLViewer, but test it anyway to keep Coverity happy.
260  G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
261  if (!pGLViewer) return;
262  pGLViewer->ChangeLineWidth(lineWidth);
263 
264  G4VMarker::FillStyle style = polymarker.GetFillStyle();
265 
266  // G4bool filled = false; Not actually used - comment out to prevent compiler warnings (JA).
267  static G4bool hashedWarned = false;
268 
269  switch (style) {
270  case G4VMarker::noFill:
271  glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
272  //filled = false;
273  break;
274  case G4VMarker::hashed:
275  if (!hashedWarned) {
276  G4cout << "Hashed fill style in G4OpenGLSceneHandler."
277  << "\n Not implemented. Using G4VMarker::filled."
278  << G4endl;
279  hashedWarned = true;
280  }
281  // Maybe use
282  //glPolygonStipple (fStippleMaskHashed);
283  // Drop through to filled...
284  case G4VMarker::filled:
285  glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
286  //filled = true;
287  break;
288  }
289 
290  MarkerSizeType sizeType;
291  G4double size = GetMarkerSize(polymarker, sizeType);
292 
293  // Draw...
294  if (sizeType == world) { // Size specified in world coordinates.
295 
296  G4int nSides;
297  G4double startPhi;
298  switch (polymarker.GetMarkerType()) {
299  default:
300  case G4Polymarker::dots:
301  size = 1.;
302  // Drop through to circles
304  nSides = GetNoOfSides(pVA);
305  startPhi = 0.;
306  break;
308  nSides = 4;
309  startPhi = -pi / 4.;
310  break;
311  }
312 
313  const G4Vector3D& viewpointDirection =
314  fpViewer -> GetViewParameters().GetViewpointDirection();
315  const G4Vector3D& up = fpViewer->GetViewParameters().GetUpVector();
316  const G4double dPhi = twopi / nSides;
317  const G4double radius = size / 2.;
318  G4Vector3D start = radius * (up.cross(viewpointDirection)).unit();
319  G4double phi;
320  G4int i;
321  for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
322 #ifndef G4OPENGL_VERSION_2
323  glBegin (GL_POLYGON);
324  for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
325  G4Vector3D r = start; r.rotate(phi, viewpointDirection);
326  G4Vector3D p = polymarker[iPoint] + r;
327  glVertex3d (p.x(), p.y(), p.z());
328  }
329  glEnd ();
330 #else
331  glBeginVBO (GL_TRIANGLE_STRIP);
332  for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
333  G4Vector3D r = start; r.rotate(phi, viewpointDirection);
334  G4Vector3D p = polymarker[iPoint] + r;
335 
336 #ifdef G4DEBUG_VIS_OGL
337  printf(".....G4OpenGLSceneHandler::AddPrimitive polyhedron QUADS VBO 5\n");
338 #endif
339  fOglVertex.push_back(p.x());
340  fOglVertex.push_back(p.y());
341  fOglVertex.push_back(p.z());
342  // normal
343  fOglVertex.push_back(0);
344  fOglVertex.push_back(0);
345  fOglVertex.push_back(1);
346  }
347  glEndVBO ();
348 #endif
349  }
350 
351  } else { // Size specified in screen (window) coordinates.
352 
353  pGLViewer->ChangePointSize(size);
354 
355  //Antialiasing only for circles
356  switch (polymarker.GetMarkerType()) {
357  default:
358  case G4Polymarker::dots:
360  glEnable (GL_POINT_SMOOTH); break;
362  glDisable (GL_POINT_SMOOTH); break;
363  }
364 #ifndef G4OPENGL_VERSION_2
365  glBegin (GL_POINTS);
366  for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
367  G4Point3D centre = polymarker[iPoint];
368  glVertex3d(centre.x(),centre.y(),centre.z());
369  }
370  glEnd();
371 #else
372  glBeginVBO(GL_POINTS);
373 
374  for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
375  fOglVertex.push_back(polymarker[iPoint].x());
376  fOglVertex.push_back(polymarker[iPoint].y());
377  fOglVertex.push_back(polymarker[iPoint].z());
378  fOglVertex.push_back(0);
379  fOglVertex.push_back(0);
380  fOglVertex.push_back(1);
381  }
382  glEndVBO();
383 #endif
384  }
385 }
386 
387 void G4OpenGLSceneHandler::AddPrimitive (const G4Text& text) {
388  // Pass to specific viewer via virtual function DrawText.
389  // FIXME : Not ready for OPENGL2 for the moment
390 #ifdef G4OPENGL_VERSION_2
391  return;
392 #endif
393  G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
394  if (pGLViewer) pGLViewer->DrawText(text);
395 }
396 
397 void G4OpenGLSceneHandler::AddPrimitive (const G4Circle& circle) {
398  G4Polymarker oneCircle(circle);
399  oneCircle.push_back(circle.GetPosition());
400  oneCircle.SetMarkerType(G4Polymarker::circles);
401  // Call this AddPrimitive to avoid re-doing sub-class code.
402  G4OpenGLSceneHandler::AddPrimitive(oneCircle);
403 }
404 
405 void G4OpenGLSceneHandler::AddPrimitive (const G4Square& square) {
406  G4Polymarker oneSquare(square);
407  oneSquare.push_back(square.GetPosition());
408  oneSquare.SetMarkerType(G4Polymarker::squares);
409  // Call this AddPrimitive to avoid re-doing sub-class code.
410  G4OpenGLSceneHandler::AddPrimitive(oneSquare);
411 }
412 
413 void G4OpenGLSceneHandler::AddPrimitive (const G4Scale& scale)
414 {
416 }
417 
418 //Method for handling G4Polyhedron objects for drawing solids.
419 void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
420 
421  // Assume all facets are planar convex quadrilaterals.
422  // Draw each facet individually
423 
424  if (polyhedron.GetNoFacets() == 0) return;
425 
426  // Need access to data in G4OpenGLViewer. static_cast doesn't work
427  // with a virtual base class, so use dynamic_cast.
428  G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
429  if (!pGLViewer) return;
430 
431  // Get vis attributes - pick up defaults if none.
432  const G4VisAttributes* pVA =
433  fpViewer -> GetApplicableVisAttributes (polyhedron.GetVisAttributes ());
434 
435  // Get view parameters that the user can force through the vis
436  // attributes, thereby over-riding the current view parameter.
437  G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA);
438 
439  // Note that in stored mode, because this call gets embedded in a display
440  // list, it is the colour _at the time of_ creation of the display list, so
441  // even if the colour is changed, for example, by interaction with a Qt
442  // window, current_colour does not change.
443  GLfloat current_colour [4];
444  glGetFloatv (GL_CURRENT_COLOR, current_colour);
445 
446  G4bool isTransparent = false;
447  if (current_colour[3] < 1.) { // This object is transparent
448  isTransparent = true;
449  }
450 
451  // This is the colour used to paint surfaces in hlr mode.
452  GLfloat clear_colour[4];
453  glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_colour);
454 
455  G4double lineWidth = GetLineWidth(pVA);
456  pGLViewer->ChangeLineWidth(lineWidth);
457 
458  G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA);
459 
460  G4bool clipping = pGLViewer->fVP.IsSection() || pGLViewer->fVP.IsCutaway();
461 
462  // Lighting disabled unless otherwise requested
463  glDisable (GL_LIGHTING);
464 
465  switch (drawing_style) {
467  // Set up as for hidden line removal but paint polygon faces later...
468  case (G4ViewParameters::hlr):
469  glEnable (GL_STENCIL_TEST);
470  // The stencil buffer is cleared in G4OpenGLViewer::ClearView.
471  // The procedure below leaves it clear.
472  glStencilFunc (GL_ALWAYS, 0, 1);
473  glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
474  glEnable (GL_DEPTH_TEST);
475  glDepthFunc (GL_LEQUAL);
476  if (isTransparent) {
477  // Transparent...
478  glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
479  glEnable(GL_COLOR_MATERIAL);
480  glDisable (GL_CULL_FACE);
481  glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
482  } else {
483  // Opaque...
484  if (clipping) {
485  glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
486  glEnable(GL_COLOR_MATERIAL);
487  glDisable (GL_CULL_FACE);
488  glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
489  } else {
490  glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
491  glEnable(GL_COLOR_MATERIAL);
492  glEnable (GL_CULL_FACE);
493  glCullFace (GL_BACK);
494  glPolygonMode (GL_FRONT, GL_LINE);
495  }
496  }
497  break;
498  case (G4ViewParameters::hsr):
499  glEnable (GL_DEPTH_TEST);
500  glDepthFunc (GL_LEQUAL);
501  if (isTransparent) {
502  // Transparent...
503  glDepthMask (GL_FALSE); // Make depth buffer read-only.
504  glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
505  glEnable(GL_COLOR_MATERIAL);
506  glDisable (GL_CULL_FACE);
507  glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
508  } else {
509  // Opaque...
510  glDepthMask (GL_TRUE); // Make depth buffer writable (default).
511  if (clipping) {
512  glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
513  glEnable(GL_COLOR_MATERIAL);
514  glDisable (GL_CULL_FACE);
515  glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
516  } else {
517  glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
518  glEnable(GL_COLOR_MATERIAL);
519  glEnable (GL_CULL_FACE);
520  glCullFace (GL_BACK);
521  glPolygonMode (GL_FRONT, GL_FILL);
522  }
523  }
524  if (!fProcessing2D) glEnable (GL_LIGHTING);
525  break;
527  default:
528  glEnable (GL_DEPTH_TEST);
529  glDepthFunc (GL_LEQUAL); //??? was GL_ALWAYS
530  glDisable (GL_CULL_FACE);
531  glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
532  break;
533  }
534 
535  //Loop through all the facets...
536 #ifndef G4OPENGL_VERSION_2
537  glBegin (GL_QUADS);
538 #else
539  fEmulate_GL_QUADS = true;
540  glBeginVBO(GL_TRIANGLE_STRIP);
541 #endif
542  G4bool notLastFace;
543  do {
544 
545  //First, find vertices, edgeflags and normals and note "not last facet"...
546  G4Point3D vertex[4];
547  G4int edgeFlag[4];
548  G4Normal3D normals[4];
549  G4int nEdges;
550  notLastFace = polyhedron.GetNextFacet(nEdges, vertex, edgeFlag, normals);
551 
552  //Loop through the four edges of each G4Facet...
553  for(G4int edgeCount = 0; edgeCount < nEdges; ++edgeCount) {
554  // Check to see if edge is visible or not...
555  if (isAuxEdgeVisible) {
556  edgeFlag[edgeCount] = 1;
557  }
558  if (edgeFlag[edgeCount] > 0) {
559  glEdgeFlag (GL_TRUE);
560  } else {
561  glEdgeFlag (GL_FALSE);
562  }
563 #ifndef G4OPENGL_VERSION_2
564  glNormal3d (normals[edgeCount].x(),
565  normals[edgeCount].y(),
566  normals[edgeCount].z());
567  glVertex3d (vertex[edgeCount].x(),
568  vertex[edgeCount].y(),
569  vertex[edgeCount].z());
570 #else
571 
572  fOglVertex.push_back(vertex[edgeCount].x());
573  fOglVertex.push_back(vertex[edgeCount].y());
574  fOglVertex.push_back(vertex[edgeCount].z());
575 
576  fOglVertex.push_back(normals[edgeCount].x());
577  fOglVertex.push_back(normals[edgeCount].y());
578  fOglVertex.push_back(normals[edgeCount].z());
579 
580 #endif
581 
582  }
583 
584  // HepPolyhedron produces triangles too; in that case add an extra
585  // vertex identical to first...
586  if (nEdges == 3) {
587  G4int edgeCount = 3;
588  normals[edgeCount] = normals[0];
589  vertex[edgeCount] = vertex[0];
590  edgeFlag[edgeCount] = -1;
591  glEdgeFlag (GL_FALSE);
592 
593 #ifndef G4OPENGL_VERSION_2
594  glNormal3d (normals[edgeCount].x(),
595  normals[edgeCount].y(),
596  normals[edgeCount].z());
597  glVertex3d (vertex[edgeCount].x(),
598  vertex[edgeCount].y(),
599  vertex[edgeCount].z());
600 #else
601  fOglVertex.push_back(vertex[edgeCount].x());
602  fOglVertex.push_back(vertex[edgeCount].y());
603  fOglVertex.push_back(vertex[edgeCount].z());
604 
605  fOglVertex.push_back(normals[edgeCount].x());
606  fOglVertex.push_back(normals[edgeCount].y());
607  fOglVertex.push_back(normals[edgeCount].z());
608 
609 #endif
610  }
611  // Trap situation where number of edges is > 4...
612  if (nEdges > 4) {
613  G4cerr <<
614  "G4OpenGLSceneHandler::AddPrimitive(G4Polyhedron): WARNING"
615  "\n G4Polyhedron facet with " << nEdges << " edges" << G4endl;
616  }
617 
618  glDisable(GL_COLOR_MATERIAL); // Revert to glMaterial for hlr/sr.
619 
620  // Do it all over again (twice) for hlr...
621  if (drawing_style == G4ViewParameters::hlr ||
622  drawing_style == G4ViewParameters::hlhsr) {
623 
624 #ifndef G4OPENGL_VERSION_2
625  glEnd (); // Placed here to balance glBegin above, allowing GL
626 #else
627  glEndVBO();
628 #endif
629  // state changes below, then glBegin again. Avoids
630  // having glBegin/End pairs *inside* loop in the more
631  // usual case of no hidden line removal.
632 
633  // Lighting disabled unless otherwise requested
634  glDisable (GL_LIGHTING);
635 
636  // Draw through stencil...
637  glStencilFunc (GL_EQUAL, 0, 1);
638  glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
639  if (drawing_style == G4ViewParameters::hlhsr) {
640  if (!fProcessing2D) glEnable (GL_LIGHTING);
641  }
642  glEnable (GL_DEPTH_TEST);
643  glDepthFunc (GL_LEQUAL);
644  if (isTransparent) {
645  // Transparent...
646  glDepthMask (GL_FALSE); // Make depth buffer read-only.
647  glDisable (GL_CULL_FACE);
648  glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
649  } else {
650  // Opaque...
651  glDepthMask (GL_TRUE); // Make depth buffer writable (default).
652  if (clipping) {
653  glDisable (GL_CULL_FACE);
654  glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
655  } else {
656  glEnable (GL_CULL_FACE);
657  glCullFace (GL_BACK);
658  glPolygonMode (GL_FRONT, GL_FILL);
659  }
660  }
661  GLfloat* painting_colour;
662  if (drawing_style == G4ViewParameters::hlr) {
663  if (isTransparent) {
664  // Transparent - don't paint...
665  goto end_of_drawing_through_stencil;
666  }
667  painting_colour = clear_colour;
668  } else { // drawing_style == G4ViewParameters::hlhsr
669  painting_colour = current_colour;
670  }
671  if (isTransparent) {
672  // Transparent...
673  glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, painting_colour);
674  } else {
675  // Opaque...
676  glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, painting_colour);
677  }
678  glColor4fv (painting_colour);
679 #ifndef G4OPENGL_VERSION_2
680  glBegin (GL_QUADS);
681 #else
682  fEmulate_GL_QUADS = true;
683  glBeginVBO(GL_TRIANGLE_STRIP);
684 #endif
685 
686  for (int edgeCount = 0; edgeCount < 4; ++edgeCount) {
687  if (edgeFlag[edgeCount] > 0) {
688  glEdgeFlag (GL_TRUE);
689  } else {
690  glEdgeFlag (GL_FALSE);
691  }
692 #ifndef G4OPENGL_VERSION_2
693  glNormal3d (normals[edgeCount].x(),
694  normals[edgeCount].y(),
695  normals[edgeCount].z());
696  glVertex3d (vertex[edgeCount].x(),
697  vertex[edgeCount].y(),
698  vertex[edgeCount].z());
699 #else
700 #ifdef G4DEBUG_VIS_OGL
701  printf(".....G4OpenGLSceneHandler::AddPrimitive polyhedron QUADS VBO 2\n");
702 #endif
703  fOglVertex.push_back(vertex[edgeCount].x());
704  fOglVertex.push_back(vertex[edgeCount].y());
705  fOglVertex.push_back(vertex[edgeCount].z());
706 
707  fOglVertex.push_back(normals[edgeCount].x());
708  fOglVertex.push_back(normals[edgeCount].y());
709  fOglVertex.push_back(normals[edgeCount].z());
710 
711 #endif
712  }
713 #ifndef G4OPENGL_VERSION_2
714  glEnd ();
715 #else
716  glEndVBO();
717 #endif
718  end_of_drawing_through_stencil:
719 
720  // and once more to reset the stencil bits...
721  glStencilFunc (GL_ALWAYS, 0, 1);
722  glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
723  glDepthFunc (GL_LEQUAL); // to make sure line gets drawn.
724  if (isTransparent) {
725  // Transparent...
726  glDisable (GL_CULL_FACE);
727  glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
728  } else {
729  // Opaque...
730  if (clipping) {
731  glDisable (GL_CULL_FACE);
732  glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
733  } else {
734  glEnable (GL_CULL_FACE);
735  glCullFace (GL_BACK);
736  glPolygonMode (GL_FRONT, GL_LINE);
737  }
738  }
739  glDisable (GL_LIGHTING);
740  glColor4fv (current_colour);
741 #ifndef G4OPENGL_VERSION_2
742  glBegin (GL_QUADS);
743 #else
744  fEmulate_GL_QUADS = true;
745  glBeginVBO(GL_TRIANGLE_STRIP);
746 #endif
747  for (int edgeCount = 0; edgeCount < 4; ++edgeCount) {
748  if (edgeFlag[edgeCount] > 0) {
749  glEdgeFlag (GL_TRUE);
750  } else {
751  glEdgeFlag (GL_FALSE);
752  }
753 #ifndef G4OPENGL_VERSION_2
754  glNormal3d (normals[edgeCount].x(),
755  normals[edgeCount].y(),
756  normals[edgeCount].z());
757  glVertex3d (vertex[edgeCount].x(),
758  vertex[edgeCount].y(),
759  vertex[edgeCount].z());
760 #else
761 #ifdef G4DEBUG_VIS_OGL
762  printf(".....G4OpenGLSceneHandler::AddPrimitive polyhedron QUADS VBO 3\n");
763 #endif
764  fOglVertex.push_back(vertex[edgeCount].x());
765  fOglVertex.push_back(vertex[edgeCount].y());
766  fOglVertex.push_back(vertex[edgeCount].z());
767 
768  fOglVertex.push_back(normals[edgeCount].x());
769  fOglVertex.push_back(normals[edgeCount].y());
770  fOglVertex.push_back(normals[edgeCount].z());
771 
772 #endif
773  }
774 #ifndef G4OPENGL_VERSION_2
775  glEnd ();
776 #else
777  glEndVBO();
778 #endif
779 
780  glDepthFunc (GL_LEQUAL); // Revert for next facet.
781 #ifndef G4OPENGL_VERSION_2
782  glBegin (GL_QUADS); // Ready for next facet. GL
783  // says it ignores incomplete
784  // quadrilaterals, so final empty
785  // glBegin/End sequence should be OK.
786 #else
787  fEmulate_GL_QUADS = true;
788  glBeginVBO(GL_TRIANGLE_STRIP);
789 #endif
790  }
791  } while (notLastFace);
792 
793 #ifndef G4OPENGL_VERSION_2
794  glEnd ();
795 #else
796 
797 // FIXME: du grand n'importe quoi en test
798 // Cube optimization
799 
800  // store old DrawType because in case of optimization it could be changed
801  GLenum oldDrawArrayType = fDrawArrayType;
802 
803  if (dynamic_cast<const G4PolyhedronTrd2*>(&polyhedron)) {
804 // OptimizeVBOForTrd();
805  } else if (dynamic_cast<const G4PolyhedronCons*>(&polyhedron)) {
806  OptimizeVBOForCons((polyhedron.GetNoVertices()-2)/2 ); // top + bottom + all faces
807  }
808 
809  glEndVBO();
810  fDrawArrayType = oldDrawArrayType;
811 #endif
812 
813  glDisable (GL_STENCIL_TEST); // Revert to default for next primitive.
814  glDepthMask (GL_TRUE); // Revert to default for next primitive.
815  glDisable (GL_LIGHTING); // Revert to default for next primitive.
816 }
817 
818 void G4OpenGLSceneHandler::AddCompound(const G4VTrajectory& traj) {
819  G4VSceneHandler::AddCompound(traj); // For now.
820 }
821 
822 void G4OpenGLSceneHandler::AddCompound(const G4VHit& hit) {
823  G4VSceneHandler::AddCompound(hit); // For now.
824 }
825 
826 void G4OpenGLSceneHandler::AddCompound(const G4VDigi& digi) {
827  G4VSceneHandler::AddCompound(digi); // For now.
828 }
829 
830 void G4OpenGLSceneHandler::AddCompound(const G4THitsMap<G4double>& hits) {
831  G4VSceneHandler::AddCompound(hits); // For now.
832 }
833 
834 
835 #ifdef G4OPENGL_VERSION_2
836 
837 // Optimize vertex and indices in order to render less vertex in OpenGL VBO/IBO
838 void G4OpenGLSceneHandler::OptimizeVBOForTrd(){
839 
840  /* HOW IT IS BUILD (as we receive it from fOglVertex :
841  */
842 
843  std::vector<double> vertices;
844  vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+6*6); // ABCDEF
845  vertices.insert (vertices.end(),fOglVertex.begin()+9*6,fOglVertex.begin()+9*6+6); // G
846  vertices.insert (vertices.end(),fOglVertex.begin()+13*6,fOglVertex.begin()+13*6+6); // H
847  fOglVertex = vertices;
848 
849  int myarray [] = {
850  3,2,0,1,4,5,7,6, 6,0,4,3,7,2,6,1,5
851  };
852  fOglIndices.insert(fOglIndices.begin(), myarray, myarray+17/*36*/);
853 
854  fDrawArrayType = GL_TRIANGLE_STRIP;
855 }
856 
857 // Optimize vertex and indices in order to render less vertex in OpenGL VBO/IBO
858 void G4OpenGLSceneHandler::OptimizeVBOForCons(G4int aNoFaces){
859  // Optimized, 1st level : 10f/15sec with 1000 cones
860  // DrawElements:208 vertex and 605 (2*100+2*100+2*100+5) indices for a 100 face cone
861 
862  /* surface of polycone : could be optimized
863  for 100 faces :
864  - 100*4 = 400 points
865  - 100*2+2 = 202 points with TRIANGLE_STRIP
866  Total :
867  n*4+n*4+n*4 = n*12
868  optimize : n*2+2+1+n+1 = n*3+3 (factor 4)
869  but could do better : n faces should give = n*2+2
870  */
871 
872  /*
873  0
874  / \
875  2---4 6 ....2
876  | |
877  3---5 7 ....3
878  \ /
879  1
880  */
881  // First, faces
882  std::vector<double> vertices;
883 
884  // Add bottom and top vertex
885  // aNoFaces*4*6+6 : nb Faces * 4 points per face * 6 vertex by point + 1 point offset
886  vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*4)*6,fOglVertex.begin()+(aNoFaces*4)*6+6); // 0
887  vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*8+1)*6,fOglVertex.begin()+(aNoFaces*8+1)*6+6); // 1
888 
889  // Add facets points
890  G4int posInVertice;
891  for (G4int a = 0; a<aNoFaces; a++) {
892  posInVertice = a*4*6;
893  vertices.insert (vertices.end(),fOglVertex.begin()+posInVertice,fOglVertex.begin()+posInVertice+1*6+6); // AB
894  }
895  vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+1*6*6); // AB
896  fOglVertex = vertices;
897 
898  // Add indices for top :
899  // simple version : 0-2-0-4-0-6-0-8-0-10..
900  // optimized version : 2-0-4-6- 6-0-8-10.. but we have to deal with odd faces numbers
901  for (G4int a=0; a<aNoFaces; a++) {
902  fOglIndices.push_back(0);
903  fOglIndices.push_back(a*2+2);
904  }
905  // close strip
906  fOglIndices.push_back(0);
907  fOglIndices.push_back(2);
908 
909  // Add indices for faces
910  for (G4int a = 0; a<aNoFaces; a++) {
911  fOglIndices.push_back(a*2+2);
912  fOglIndices.push_back(a*2+1+2);
913  }
914  fOglIndices.push_back(2);
915  fOglIndices.push_back(2+1);
916 
917  // Second : top
918  // 3-1-5-1-7-1-9-1..
919  for (G4int a=0; a<aNoFaces; a++) {
920  fOglIndices.push_back(a*2+3);
921  fOglIndices.push_back(1);
922  }
923  // close strip
924  fOglIndices.push_back(0+3);
925 
926  fDrawArrayType = GL_TRIANGLE_STRIP;
927  fEmulate_GL_QUADS = false;
928 }
929 
930 void G4OpenGLSceneHandler::glBeginVBO(GLenum type) {
931  fDrawArrayType = type;
932 #ifdef G4DEBUG_VIS_OGL
933  printf("G4OpenGLSceneHandler::glBeginVBO %d\n",type);
934 #endif
935 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
936  glGenBuffers(1,&fVertexBufferObject);
937  glGenBuffers(1,&fIndicesBufferObject);
938 #else
939  fVertexBufferObject = glCreateBuffer(); //glGenBuffer(1,fVertexBufferObject_2)
940  fIndicesBufferObject = glCreateBuffer(); //glGenBuffer(1,fIndicesBufferObject_2)
941 #endif
942 
943  // clear data and indices for OpenGL
944  fOglVertex.clear();
945  fOglIndices.clear();
946 }
947 
948 // 2 cases :
949 /*
950  glDrawArray : if there is no vertex indices : fOglIndices.size() == 0
951  glDrawElements : if there is vertex indices : fOglIndices.size() != 0
952 
953  */
954 void G4OpenGLSceneHandler::glEndVBO() {
955  if (fOglIndices.size() == 0) {
956 
957 
958  std::vector<double> vertices;
959  // check if it is a GL_QUADS emulation
960  if (fEmulate_GL_QUADS == true) {
961  fEmulate_GL_QUADS = false;
962  // A point has 6 double : Vx Vy Vz Nx Ny Nz
963  // A QUAD should be like this
964  /*
965  0 3/4 7/8 ..
966 
967  1 2/5 6/9 ..
968  */
969  // And if 3==4 and 2==5, we should do it like this for a TRIANGLES_STRIP
970  /*
971  0 4 8 ..
972  | / | / |
973  1 5 9 ..
974  // Optimized, 1st level : 24f/15sec with 10 cones
975  // non Optimized, 1st level : 12f/15sec with 10 cones
976  */
977  // should be 4 points
978  for (unsigned int a=0; a<fOglVertex.size(); a+=6*4) {
979  vertices.insert (vertices.end(),fOglVertex.begin()+a,fOglVertex.begin()+a+1*6+6); // 0-1
980  // if 2-3 == 4-5, do not add them
981  // if differents, we are obliged to create a new GL_TRIANGLE_STRIP
982  if (a+4*6+5 < fOglVertex.size()) {
983  if ((fOglVertex[a+2*6+0] != fOglVertex[a+5*6+0]) || //Vx for 2 and 5
984  (fOglVertex[a+2*6+1] != fOglVertex[a+5*6+1]) || //Vy for 2 and 5
985  (fOglVertex[a+2*6+2] != fOglVertex[a+5*6+2]) || //Vz for 2 and 5
986  (fOglVertex[a+2*6+3] != fOglVertex[a+5*6+3]) || //Px for 2 and 5
987  (fOglVertex[a+2*6+4] != fOglVertex[a+5*6+4]) || //Py for 2 and 5
988  (fOglVertex[a+2*6+5] != fOglVertex[a+5*6+5]) || //Pz for 2 and 5
989 
990  (fOglVertex[a+3*6+0] != fOglVertex[a+4*6+0]) || //Vx for 3 and 4
991  (fOglVertex[a+3*6+1] != fOglVertex[a+4*6+1]) || //Vy for 3 and 4
992  (fOglVertex[a+3*6+2] != fOglVertex[a+4*6+2]) || //Vz for 3 and 4
993  (fOglVertex[a+3*6+3] != fOglVertex[a+4*6+3]) || //Px for 3 and 4
994  (fOglVertex[a+3*6+4] != fOglVertex[a+4*6+4]) || //Py for 3 and 4
995  (fOglVertex[a+3*6+5] != fOglVertex[a+4*6+5])) { //Pz for 3 and 4
996  // add last points
997  vertices.insert (vertices.end(),fOglVertex.begin()+a+3*6,fOglVertex.begin()+a+3*6+6); // 3
998  vertices.insert (vertices.end(),fOglVertex.begin()+a+2*6,fOglVertex.begin()+a+2*6+6); // 2
999  // build and send the GL_TRIANGLE_STRIP
1000  drawVBOArray(vertices);
1001  vertices.clear();
1002  }
1003  } else { // end of volume
1004  vertices.insert (vertices.end(),fOglVertex.begin()+a+3*6,fOglVertex.begin()+a+3*6+6); // 3
1005  vertices.insert (vertices.end(),fOglVertex.begin()+a+2*6,fOglVertex.begin()+a+2*6+6); // 2
1006  }
1007  }
1008  fOglVertex = vertices;
1009  }
1010 
1011  drawVBOArray(fOglVertex);
1012 
1013  } else {
1014 
1015  // Bind VBO
1016  glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1017 
1018  // Load fOglVertex into VBO
1019 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1020  int sizeV = fOglVertex.size();
1021  // FIXME : perhaps a problem withBufferData in OpenGL other than WebGL ?
1022 // void glBufferData( GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage);
1023  glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(double)*sizeV, &fOglVertex[0]);
1024 #else
1025  glBufferDatafv(GL_ARRAY_BUFFER, fOglVertex.begin(), fOglVertex.end(), GL_STATIC_DRAW);
1026 #endif
1027 
1028  // Bind IBO
1029  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1030 
1031  // Load fOglVertex into VBO
1032 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1033  int sizeI = fOglIndices.size();
1034  glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeof(int)*sizeI, &fOglIndices[0]);
1035 #else
1036  glBufferDataiv(GL_ELEMENT_ARRAY_BUFFER, fOglIndices.begin(), fOglIndices.end(), GL_STATIC_DRAW);
1037 #endif
1038 
1039  //----------------------------
1040  // Draw VBO
1041  //----------------------------
1042  glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1043  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1044 
1045 #ifdef G4DEBUG_VIS_OGL
1046  printf("G4OpenGLSceneHandler::glEndVBO() To DrawElements:%d vertex and %d indices\n",fOglVertex.size()/6,fOglIndices.size());
1047 #endif
1048 
1049  // the vertexPositionAttribute_ is inside the G4OpenGLViewer
1050  G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
1051  if (pGLViewer) {
1052  glEnableVertexAttribArray(pGLViewer->vertexPositionAttribute_);
1053 
1054  glVertexAttribPointer(pGLViewer->vertexPositionAttribute_,
1055  3, // size: Every vertex has an X, Y anc Z component
1056  GL_FLOAT, // type: They are floats
1057  GL_FALSE, // normalized: Please, do NOT normalize the vertices
1058  2*3*4, // stride: The first byte of the next vertex is located this
1059  // amount of bytes further. The format of the VBO is
1060  // vx, vy, vz, nx, ny, nz and every element is a
1061  // Float32, hence 4 bytes large
1062  0); // offset: The byte position of the first vertex in the buffer
1063  }
1064 
1065 
1066  /* glDrawArrays(fDrawArrayType, // GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP, and GL_TRIANGLES
1067  0, fOglVertex.size()/6);
1068  */
1069  glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1070  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1071 // glDrawElements(fDrawArrayType, fOglIndices.size(), GL_UNSIGNED_SHORT, 0);
1072  glDrawElements(fDrawArrayType, fOglIndices.size(), GL_UNSIGNED_SHORT, 0);
1073 
1074  if (pGLViewer) {
1075  glDisableVertexAttribArray(pGLViewer->vertexPositionAttribute_);
1076  }
1077 
1078  // delete the buffer
1079 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1080  glDeleteBuffers(1,&fVertexBufferObject);
1081 #else
1082  glDeleteBuffer(fVertexBufferObject);
1083 #endif
1084  }
1085 }
1086 
1087 void G4OpenGLSceneHandler::drawVBOArray(std::vector<double> vertices) {
1088 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1089  glGenBuffers(1,&fVertexBufferObject);
1090  glGenBuffers(1,&fIndicesBufferObject);
1091 #else
1092  fVertexBufferObject = glCreateBuffer(); //glGenBuffer(1,fVertexBufferObject_2)
1093  fIndicesBufferObject = glCreateBuffer(); //glGenBuffer(1,fIndicesBufferObject_2)
1094 #endif
1095 
1096  // Bind this buffer
1097  glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1098  // Load oglData into VBO
1099 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1100  int s = vertices.size();
1101  glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(double)*s, &vertices[0]);
1102 
1103 #else
1104  glBufferDatafv(GL_ARRAY_BUFFER, vertices.begin(), vertices.end(), GL_STATIC_DRAW);
1105 #endif
1106 
1107  //----------------------------
1108  // Draw VBO
1109  //----------------------------
1110  glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1111 
1112 #ifdef G4DEBUG_VIS_OGL
1113  printf("G4OpenGLSceneHandler::drawVBOArray To DrawArray:%d\n",vertices.size()/6);
1114 #endif
1115 
1116  // the vertexPositionAttribute_ is inside the G4OpenGLViewer
1117  G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
1118  if (pGLViewer) {
1119  glEnableVertexAttribArray(pGLViewer->vertexPositionAttribute_);
1120 
1121  glVertexAttribPointer(pGLViewer->vertexPositionAttribute_,
1122  3, // size: Every vertex has an X, Y anc Z component
1123  GL_FLOAT, // type: They are floats
1124  GL_FALSE, // normalized: Please, do NOT normalize the vertices
1125  2*3*4, // stride: The first byte of the next vertex is located this
1126  // amount of bytes further. The format of the VBO is
1127  // vx, vy, vz, nx, ny, nz and every element is a
1128  // Float32, hence 4 bytes large
1129  0); // offset: The byte position of the first vertex in the buffer
1130  }
1131 
1132  glDrawArrays(fDrawArrayType, // GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP, and GL_TRIANGLES
1133  0, vertices.size()/6);
1134  if (pGLViewer) {
1135  glDisableVertexAttribArray(pGLViewer->vertexPositionAttribute_);
1136  }
1137 
1138  // delet the buffer
1139 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1140  glDeleteBuffers(1,&fVertexBufferObject);
1141 #else
1142  glDeleteBuffer(fVertexBufferObject);
1143 #endif
1144 }
1145 #endif
1146 
1147 
1148 #endif
BasicVector3D< T > & rotate(T a, const BasicVector3D< T > &v)
Definition: G4Text.hh:73
virtual G4VSolid * CreateSectionSolid()
MarkerType GetMarkerType() const
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
const XML_Char * s
G4double z
Definition: TRTMaterials.hh:39
const char * p
Definition: xmltok.h:285
const XML_Char * name
Definition: G4VHit.hh:48
G4Point3D GetPosition() const
const G4VisAttributes * GetVisAttributes() const
int G4int
Definition: G4Types.hh:78
virtual void AddPrimitive(const G4Polyline &)=0
virtual G4VSolid * CreateCutawaySolid()
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
virtual void EndPrimitives()
G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=0, G4Normal3D *normals=0) const
G4int GetNoVertices() const
virtual void BeginPrimitives2D(const G4Transform3D &objectTransformation)
virtual void AddCompound(const G4VTrajectory &)
virtual void ProcessScene()
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
FillStyle GetFillStyle() const
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4int GetNoFacets() const
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
virtual void EndPrimitives2D()
G4GLOB_DLL std::ostream G4cerr