35 #ifdef G4VIS_BUILD_OPENGL_DRIVER
64 #ifdef G4OPENGL_VERSION_2
65 fEmulate_GL_QUADS(false),
70 fEventsDrawInterval(1),
71 fEventsWaitingToBeFlushed(0),
72 fThreePassCapable(false),
73 fSecondPassForTransparencyRequested(false),
74 fSecondPassForTransparency(false),
75 fThirdPassForNonHiddenMarkersRequested(false),
76 fThirdPassForNonHiddenMarkers(false),
81 G4OpenGLSceneHandler::~G4OpenGLSceneHandler ()
86 const GLubyte G4OpenGLSceneHandler::fStippleMaskHashed [128] = {
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 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
105 void G4OpenGLSceneHandler::ClearAndDestroyAtts()
107 std::map<GLuint, G4AttHolder*>::iterator i;
108 for (i = fPickMap.begin(); i != fPickMap.end(); ++i)
delete i->second;
112 void G4OpenGLSceneHandler::ScaledFlush()
114 fEventsWaitingToBeFlushed++;
115 if (fEventsWaitingToBeFlushed < fEventsDrawInterval)
return;
117 fEventsWaitingToBeFlushed = 0;
120 void G4OpenGLSceneHandler::ProcessScene()
122 fThreePassCapable =
true;
127 if (fSecondPassForTransparencyRequested) {
128 fSecondPassForTransparency =
true;
130 fSecondPassForTransparency =
false;
131 fSecondPassForTransparencyRequested =
false;
135 if (fThirdPassForNonHiddenMarkersRequested) {
136 fThirdPassForNonHiddenMarkers =
true;
138 fThirdPassForNonHiddenMarkers =
false;
139 fThirdPassForNonHiddenMarkersRequested =
false;
142 fThreePassCapable =
false;
145 void G4OpenGLSceneHandler::PreAddSolid
152 void G4OpenGLSceneHandler::BeginPrimitives
158 void G4OpenGLSceneHandler::EndPrimitives ()
163 void G4OpenGLSceneHandler::BeginPrimitives2D
169 void G4OpenGLSceneHandler::EndPrimitives2D ()
174 G4VSolid* G4OpenGLSceneHandler::CreateSectionSolid ()
185 G4VSolid* G4OpenGLSceneHandler::CreateCutawaySolid ()
194 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polyline& line)
196 G4int nPoints = line.size ();
197 if (nPoints <= 0)
return;
201 #ifndef G4OPENGL_VERSION_2
202 glDisable (GL_LIGHTING);
209 G4double lineWidth = GetLineWidth(pVA);
214 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
215 if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth);
218 #ifndef G4OPENGL_VERSION_2
219 glBegin (GL_LINE_STRIP);
224 for (
G4int iPoint = 0; iPoint < nPoints; iPoint++) {
226 x = line[iPoint].x();
227 y = line[iPoint].y();
228 z = line[iPoint].z();
229 glVertex3d (x, y, z);
233 glBeginVBO(GL_LINE_STRIP);
235 for (
G4int iPoint = 0; iPoint < nPoints; iPoint++) {
236 fOglVertex.push_back(line[iPoint].x());
237 fOglVertex.push_back(line[iPoint].y());
238 fOglVertex.push_back(line[iPoint].
z());
240 fOglVertex.push_back(0);
241 fOglVertex.push_back(0);
242 fOglVertex.push_back(1);
249 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polymarker& polymarker)
251 if (polymarker.size() == 0) {
257 #ifndef G4OPENGL_VERSION_2
258 glDisable (GL_LIGHTING);
265 MarkerSizeType sizeType;
266 G4double size = GetMarkerSize(polymarker, sizeType);
272 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
273 if (!pGLViewer)
return;
275 if (sizeType == world) {
276 G4double lineWidth = GetLineWidth(pVA);
277 pGLViewer->ChangeLineWidth(lineWidth);
282 static G4bool hashedWarned =
false;
286 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
287 glEdgeFlag (GL_TRUE);
292 G4cout <<
"Hashed fill style in G4OpenGLSceneHandler."
293 <<
"\n Not implemented. Using G4VMarker::filled."
301 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
308 if (sizeType == world) {
318 nSides = GetNoOfSides(pVA);
328 fpViewer -> GetViewParameters().GetViewpointDirection();
329 const G4Vector3D& up = fpViewer->GetViewParameters().GetUpVector();
330 const G4double dPhi = twopi / nSides;
332 G4Vector3D start = radius * (up.cross(viewpointDirection)).unit();
335 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
337 #ifndef G4OPENGL_VERSION_2
338 glBegin (GL_POLYGON);
339 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
340 G4Vector3D r = start; r.rotate(phi, viewpointDirection);
342 glVertex3d (p.x(), p.y(), p.z());
346 glBeginVBO (GL_TRIANGLE_STRIP);
347 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
348 G4Vector3D r = start; r.rotate(phi, viewpointDirection);
351 #ifdef G4DEBUG_VIS_OGL
352 printf(
".....G4OpenGLSceneHandler::AddPrimitive polyhedron QUADS VBO 5\n");
354 fOglVertex.push_back(p.x());
355 fOglVertex.push_back(p.y());
356 fOglVertex.push_back(p.z());
358 fOglVertex.push_back(0);
359 fOglVertex.push_back(0);
360 fOglVertex.push_back(1);
368 pGLViewer->ChangePointSize(size);
371 #ifndef G4OPENGL_VERSION_2
376 glEnable (GL_POINT_SMOOTH);
break;
378 glDisable (GL_POINT_SMOOTH);
break;
381 #ifndef G4OPENGL_VERSION_2
383 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
385 glVertex3d(centre.x(),centre.y(),centre.z());
389 glBeginVBO(GL_POINTS);
391 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
392 fOglVertex.push_back(polymarker[iPoint].x());
393 fOglVertex.push_back(polymarker[iPoint].y());
394 fOglVertex.push_back(polymarker[iPoint].
z());
395 fOglVertex.push_back(0);
396 fOglVertex.push_back(0);
397 fOglVertex.push_back(1);
404 void G4OpenGLSceneHandler::AddPrimitive (
const G4Text& text) {
407 #ifdef G4OPENGL_VERSION_2
410 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
411 if (pGLViewer) pGLViewer->DrawText(text);
414 void G4OpenGLSceneHandler::AddPrimitive (
const G4Circle& circle) {
419 G4OpenGLSceneHandler::AddPrimitive(oneCircle);
422 void G4OpenGLSceneHandler::AddPrimitive (
const G4Square& square) {
427 G4OpenGLSceneHandler::AddPrimitive(oneSquare);
430 void G4OpenGLSceneHandler::AddPrimitive (
const G4Scale& scale)
436 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polyhedron& polyhedron) {
441 if (polyhedron.GetNoFacets() == 0)
return;
445 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
446 if (!pGLViewer)
return;
460 GLfloat* painting_colour;
461 GLfloat current_colour [4];
462 glGetFloatv (GL_CURRENT_COLOR, current_colour);
464 G4bool isTransparent =
false;
465 if (current_colour[3] < 1.) {
466 isTransparent =
true;
472 GLfloat clear_colour[4];
473 glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_colour);
474 painting_colour = clear_colour;
476 painting_colour = current_colour;
479 G4double lineWidth = GetLineWidth(pVA);
480 pGLViewer->ChangeLineWidth(lineWidth);
482 G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA);
484 G4bool clipping = pGLViewer->fVP.IsSection() || pGLViewer->fVP.IsCutaway();
487 #ifndef G4OPENGL_VERSION_2
488 glDisable (GL_LIGHTING);
491 switch (drawing_style) {
495 glEnable (GL_STENCIL_TEST);
498 glStencilFunc (GL_ALWAYS, 0, 1);
499 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
500 glEnable (GL_DEPTH_TEST);
501 glDepthFunc (GL_LEQUAL);
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_LINE);
511 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
512 glEnable(GL_COLOR_MATERIAL);
513 glDisable (GL_CULL_FACE);
514 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
516 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
517 glEnable(GL_COLOR_MATERIAL);
518 glEnable (GL_CULL_FACE);
519 glCullFace (GL_BACK);
520 glPolygonMode (GL_FRONT, GL_LINE);
525 glEnable (GL_DEPTH_TEST);
526 glDepthFunc (GL_LEQUAL);
529 glDepthMask (GL_FALSE);
530 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
531 #ifndef G4OPENGL_VERSION_2
532 glEnable(GL_COLOR_MATERIAL);
534 glDisable (GL_CULL_FACE);
535 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
538 glDepthMask (GL_TRUE);
540 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
541 glEnable(GL_COLOR_MATERIAL);
542 glDisable (GL_CULL_FACE);
543 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
545 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
546 #ifndef G4OPENGL_VERSION_2
547 glEnable(GL_COLOR_MATERIAL);
549 glEnable (GL_CULL_FACE);
550 glCullFace (GL_BACK);
551 glPolygonMode (GL_FRONT, GL_FILL);
554 #ifndef G4OPENGL_VERSION_2
555 if (!fProcessing2D) glEnable (GL_LIGHTING);
560 glEnable (GL_DEPTH_TEST);
561 glDepthFunc (GL_LEQUAL);
562 glDisable (GL_CULL_FACE);
563 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
569 #ifndef G4OPENGL_VERSION_2
571 glEdgeFlag (GL_TRUE);
573 fEmulate_GL_QUADS =
true;
574 glBeginVBO(GL_TRIANGLE_STRIP);
584 notLastFace = polyhedron.GetNextFacet(nEdges, vertex, edgeFlag, normals);
587 for(
G4int edgeCount = 0; edgeCount < nEdges; ++edgeCount) {
589 if (isAuxEdgeVisible) {
590 edgeFlag[edgeCount] = 1;
592 #ifndef G4OPENGL_VERSION_2
593 if (edgeFlag[edgeCount] > 0) {
594 if (fEdgeFlag !=
true) {
595 glEdgeFlag (GL_TRUE);
599 if (fEdgeFlag !=
false) {
600 glEdgeFlag (GL_FALSE);
604 glNormal3d (normals[edgeCount].x(),
605 normals[edgeCount].y(),
606 normals[edgeCount].
z());
607 glVertex3d (vertex[edgeCount].x(),
608 vertex[edgeCount].y(),
609 vertex[edgeCount].
z());
612 fOglVertex.push_back(vertex[edgeCount].x());
613 fOglVertex.push_back(vertex[edgeCount].y());
614 fOglVertex.push_back(vertex[edgeCount].
z());
616 fOglVertex.push_back(normals[edgeCount].x());
617 fOglVertex.push_back(normals[edgeCount].y());
618 fOglVertex.push_back(normals[edgeCount].
z());
628 normals[edgeCount] = normals[0];
629 vertex[edgeCount] = vertex[0];
630 #ifndef G4OPENGL_VERSION_2
631 edgeFlag[edgeCount] = -1;
632 if (fEdgeFlag !=
false) {
633 glEdgeFlag (GL_FALSE);
637 glNormal3d (normals[edgeCount].x(),
638 normals[edgeCount].y(),
639 normals[edgeCount].
z());
640 glVertex3d (vertex[edgeCount].x(),
641 vertex[edgeCount].y(),
642 vertex[edgeCount].
z());
644 fOglVertex.push_back(vertex[edgeCount].x());
645 fOglVertex.push_back(vertex[edgeCount].y());
646 fOglVertex.push_back(vertex[edgeCount].
z());
648 fOglVertex.push_back(normals[edgeCount].x());
649 fOglVertex.push_back(normals[edgeCount].y());
650 fOglVertex.push_back(normals[edgeCount].
z());
657 "G4OpenGLSceneHandler::AddPrimitive(G4Polyhedron): WARNING"
658 "\n G4Polyhedron facet with " << nEdges <<
" edges" <<
G4endl;
666 #ifndef G4OPENGL_VERSION_2
667 glDisable(GL_COLOR_MATERIAL);
670 #ifndef G4OPENGL_VERSION_2
680 glDisable (GL_LIGHTING);
683 glStencilFunc (GL_EQUAL, 0, 1);
684 glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
686 if (!fProcessing2D) glEnable (GL_LIGHTING);
688 glEnable (GL_DEPTH_TEST);
689 glDepthFunc (GL_LEQUAL);
692 glDepthMask (GL_FALSE);
693 glDisable (GL_CULL_FACE);
694 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
697 glDepthMask (GL_TRUE);
699 glDisable (GL_CULL_FACE);
700 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
702 glEnable (GL_CULL_FACE);
703 glCullFace (GL_BACK);
704 glPolygonMode (GL_FRONT, GL_FILL);
710 goto end_of_drawing_through_stencil;
715 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, painting_colour);
718 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, painting_colour);
720 glColor4fv (painting_colour);
721 #ifndef G4OPENGL_VERSION_2
723 glEdgeFlag (GL_TRUE);
726 fEmulate_GL_QUADS =
true;
727 glBeginVBO(GL_TRIANGLE_STRIP);
730 for (
int edgeCount = 0; edgeCount < 4; ++edgeCount) {
731 #ifndef G4OPENGL_VERSION_2
732 if (edgeFlag[edgeCount] > 0) {
733 if (fEdgeFlag !=
true) {
734 glEdgeFlag (GL_TRUE);
738 if (fEdgeFlag !=
false) {
739 glEdgeFlag (GL_FALSE);
743 glNormal3d (normals[edgeCount].x(),
744 normals[edgeCount].y(),
745 normals[edgeCount].
z());
746 glVertex3d (vertex[edgeCount].x(),
747 vertex[edgeCount].y(),
748 vertex[edgeCount].
z());
750 #ifdef G4DEBUG_VIS_OGL
751 printf(
".....G4OpenGLSceneHandler::AddPrimitive polyhedron QUADS VBO 2\n");
753 fOglVertex.push_back(vertex[edgeCount].x());
754 fOglVertex.push_back(vertex[edgeCount].y());
755 fOglVertex.push_back(vertex[edgeCount].
z());
757 fOglVertex.push_back(normals[edgeCount].x());
758 fOglVertex.push_back(normals[edgeCount].y());
759 fOglVertex.push_back(normals[edgeCount].
z());
763 #ifndef G4OPENGL_VERSION_2
768 end_of_drawing_through_stencil:
771 glStencilFunc (GL_ALWAYS, 0, 1);
772 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
773 glDepthFunc (GL_LEQUAL);
776 glDisable (GL_CULL_FACE);
777 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
781 glDisable (GL_CULL_FACE);
782 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
784 glEnable (GL_CULL_FACE);
785 glCullFace (GL_BACK);
786 glPolygonMode (GL_FRONT, GL_LINE);
789 glDisable (GL_LIGHTING);
790 glColor4fv (current_colour);
792 #ifndef G4OPENGL_VERSION_2
794 glEdgeFlag (GL_TRUE);
797 fEmulate_GL_QUADS =
true;
798 glBeginVBO(GL_TRIANGLE_STRIP);
800 for (
int edgeCount = 0; edgeCount < 4; ++edgeCount) {
801 #ifndef G4OPENGL_VERSION_2
802 if (edgeFlag[edgeCount] > 0) {
803 if (fEdgeFlag !=
true) {
804 glEdgeFlag (GL_TRUE);
808 if (fEdgeFlag !=
false) {
809 glEdgeFlag (GL_FALSE);
813 glNormal3d (normals[edgeCount].x(),
814 normals[edgeCount].y(),
815 normals[edgeCount].
z());
816 glVertex3d (vertex[edgeCount].x(),
817 vertex[edgeCount].y(),
818 vertex[edgeCount].
z());
820 #ifdef G4DEBUG_VIS_OGL
821 printf(
".....G4OpenGLSceneHandler::AddPrimitive polyhedron QUADS VBO 3\n");
823 fOglVertex.push_back(vertex[edgeCount].x());
824 fOglVertex.push_back(vertex[edgeCount].y());
825 fOglVertex.push_back(vertex[edgeCount].
z());
827 fOglVertex.push_back(normals[edgeCount].x());
828 fOglVertex.push_back(normals[edgeCount].y());
829 fOglVertex.push_back(normals[edgeCount].
z());
833 #ifndef G4OPENGL_VERSION_2
839 glDepthFunc (GL_LEQUAL);
841 #ifndef G4OPENGL_VERSION_2
843 glEdgeFlag (GL_TRUE);
849 fEmulate_GL_QUADS =
true;
850 glBeginVBO(GL_TRIANGLE_STRIP);
853 }
while (notLastFace);
855 #ifndef G4OPENGL_VERSION_2
863 GLenum oldDrawArrayType = fDrawArrayType;
865 if (dynamic_cast<const G4PolyhedronTrd2*>(&polyhedron)) {
867 }
else if (dynamic_cast<const G4PolyhedronCons*>(&polyhedron)) {
872 fDrawArrayType = oldDrawArrayType;
875 glDisable (GL_STENCIL_TEST);
876 glDepthMask (GL_TRUE);
877 #ifndef G4OPENGL_VERSION_2
878 glDisable (GL_LIGHTING);
882 void G4OpenGLSceneHandler::AddCompound(
const G4VTrajectory& traj) {
886 void G4OpenGLSceneHandler::AddCompound(
const G4VHit& hit) {
890 void G4OpenGLSceneHandler::AddCompound(
const G4VDigi& digi) {
899 #ifdef G4OPENGL_VERSION_2
902 void G4OpenGLSceneHandler::OptimizeVBOForTrd(){
907 std::vector<double> vertices;
908 vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+6*6);
909 vertices.insert (vertices.end(),fOglVertex.begin()+9*6,fOglVertex.begin()+9*6+6);
910 vertices.insert (vertices.end(),fOglVertex.begin()+13*6,fOglVertex.begin()+13*6+6);
911 fOglVertex = vertices;
914 3,2,0,1,4,5,7,6, 6,0,4,3,7,2,6,1,5
916 fOglIndices.insert(fOglIndices.begin(), myarray, myarray+17);
918 fDrawArrayType = GL_TRIANGLE_STRIP;
922 void G4OpenGLSceneHandler::OptimizeVBOForCons(
G4int aNoFaces){
946 std::vector<double> vertices;
950 vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*4)*6,fOglVertex.begin()+(aNoFaces*4)*6+6);
951 vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*8+1)*6,fOglVertex.begin()+(aNoFaces*8+1)*6+6);
955 for (
G4int a = 0;
a<aNoFaces;
a++) {
956 posInVertice =
a*4*6;
957 vertices.insert (vertices.end(),fOglVertex.begin()+posInVertice,fOglVertex.begin()+posInVertice+1*6+6);
959 vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+1*6*6);
960 fOglVertex = vertices;
966 fOglIndices.push_back(0);
967 fOglIndices.push_back(
a*2+2);
970 fOglIndices.push_back(0);
971 fOglIndices.push_back(2);
974 for (
G4int a = 0;
a<aNoFaces;
a++) {
975 fOglIndices.push_back(
a*2+2);
976 fOglIndices.push_back(
a*2+1+2);
978 fOglIndices.push_back(2);
979 fOglIndices.push_back(2+1);
984 fOglIndices.push_back(
a*2+3);
985 fOglIndices.push_back(1);
988 fOglIndices.push_back(0+3);
990 fDrawArrayType = GL_TRIANGLE_STRIP;
991 fEmulate_GL_QUADS =
false;
994 void G4OpenGLSceneHandler::glBeginVBO(GLenum type) {
995 fDrawArrayType = type;
996 #ifdef G4DEBUG_VIS_OGL
997 printf(
"G4OpenGLSceneHandler::glBeginVBO %d\n",type);
999 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1000 glGenBuffers(1,&fVertexBufferObject);
1001 glGenBuffers(1,&fIndicesBufferObject);
1003 fVertexBufferObject = glCreateBuffer();
1004 fIndicesBufferObject = glCreateBuffer();
1009 fOglIndices.clear();
1018 void G4OpenGLSceneHandler::glEndVBO() {
1019 if (fOglIndices.size() == 0) {
1022 std::vector<double> vertices;
1024 if (fEmulate_GL_QUADS ==
true) {
1025 fEmulate_GL_QUADS =
false;
1042 for (
unsigned int a=0;
a<fOglVertex.size();
a+=6*4) {
1043 vertices.insert (vertices.end(),fOglVertex.begin()+
a,fOglVertex.begin()+
a+1*6+6);
1046 if (
a+4*6+5 < fOglVertex.size()) {
1047 if ((fOglVertex[
a+2*6+0] != fOglVertex[
a+5*6+0]) ||
1048 (fOglVertex[
a+2*6+1] != fOglVertex[
a+5*6+1]) ||
1049 (fOglVertex[
a+2*6+2] != fOglVertex[
a+5*6+2]) ||
1050 (fOglVertex[
a+2*6+3] != fOglVertex[
a+5*6+3]) ||
1051 (fOglVertex[
a+2*6+4] != fOglVertex[
a+5*6+4]) ||
1052 (fOglVertex[
a+2*6+5] != fOglVertex[
a+5*6+5]) ||
1054 (fOglVertex[
a+3*6+0] != fOglVertex[
a+4*6+0]) ||
1055 (fOglVertex[
a+3*6+1] != fOglVertex[
a+4*6+1]) ||
1056 (fOglVertex[
a+3*6+2] != fOglVertex[
a+4*6+2]) ||
1057 (fOglVertex[
a+3*6+3] != fOglVertex[
a+4*6+3]) ||
1058 (fOglVertex[
a+3*6+4] != fOglVertex[
a+4*6+4]) ||
1059 (fOglVertex[
a+3*6+5] != fOglVertex[
a+4*6+5])) {
1061 vertices.insert (vertices.end(),fOglVertex.begin()+
a+3*6,fOglVertex.begin()+
a+3*6+6);
1062 vertices.insert (vertices.end(),fOglVertex.begin()+
a+2*6,fOglVertex.begin()+
a+2*6+6);
1064 drawVBOArray(vertices);
1068 vertices.insert (vertices.end(),fOglVertex.begin()+
a+3*6,fOglVertex.begin()+
a+3*6+6);
1069 vertices.insert (vertices.end(),fOglVertex.begin()+
a+2*6,fOglVertex.begin()+
a+2*6+6);
1072 fOglVertex = vertices;
1075 drawVBOArray(fOglVertex);
1080 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1083 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1084 int sizeV = fOglVertex.size();
1087 glBufferData(GL_ARRAY_BUFFER,
sizeof(
double)*sizeV, &fOglVertex[0], GL_STATIC_DRAW);
1089 glBufferDatafv(GL_ARRAY_BUFFER, fOglVertex.begin(), fOglVertex.end(), GL_STATIC_DRAW);
1093 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1096 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1097 int sizeI = fOglIndices.size();
1098 glBufferData(GL_ELEMENT_ARRAY_BUFFER,
sizeof(
int)*sizeI, &fOglIndices[0], GL_STATIC_DRAW);
1100 glBufferDataiv(GL_ELEMENT_ARRAY_BUFFER, fOglIndices.begin(), fOglIndices.end(), GL_STATIC_DRAW, GL_UNSIGNED_BYTE);
1106 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1107 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1109 #ifdef G4DEBUG_VIS_OGL
1110 printf(
"G4OpenGLSceneHandler::glEndVBO() To DrawElements:%d vertex and %d indices\n",fOglVertex.size()/6,fOglIndices.size());
1114 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
1116 glEnableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1118 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1130 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1131 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1133 glDrawElements(fDrawArrayType, fOglIndices.size(), GL_UNSIGNED_SHORT, 0);
1136 glDisableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1140 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1141 glDeleteBuffers(1,&fVertexBufferObject);
1143 glDeleteBuffer(fVertexBufferObject);
1148 void G4OpenGLSceneHandler::drawVBOArray(std::vector<double> vertices) {
1149 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1150 glGenBuffers(1,&fVertexBufferObject);
1151 glGenBuffers(1,&fIndicesBufferObject);
1153 fVertexBufferObject = glCreateBuffer();
1154 fIndicesBufferObject = glCreateBuffer();
1158 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1160 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1161 int s = vertices.size();
1162 glBufferData(GL_ARRAY_BUFFER,
sizeof(
double)*s, &vertices[0], GL_STATIC_DRAW);
1164 glBufferDatafv(GL_ARRAY_BUFFER, vertices.begin(), vertices.end(), GL_STATIC_DRAW);
1170 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1173 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
1175 glEnableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1185 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1186 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1196 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1208 glDrawArrays(fDrawArrayType,
1209 0, vertices.size()/6);
1211 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1212 glDisableClientState( GL_VERTEX_ARRAY );
1214 glDisableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1219 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1220 glDeleteBuffers(1,&fVertexBufferObject);
1222 glDeleteBuffer(fVertexBufferObject);
virtual G4VSolid * CreateSectionSolid()
MarkerType GetMarkerType() const
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
HepGeom::Point3D< G4double > G4Point3D
HepGeom::Vector3D< G4double > G4Vector3D
G4Point3D GetPosition() const
const G4VisAttributes * GetVisAttributes() const
virtual void AddPrimitive(const G4Polyline &)=0
virtual G4VSolid * CreateCutawaySolid()
G4GLOB_DLL std::ostream G4cout
virtual void EndPrimitives()
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
virtual void EndPrimitives2D()
G4GLOB_DLL std::ostream G4cerr
HepGeom::Normal3D< G4double > G4Normal3D