35 #ifdef G4VIS_BUILD_OPENGL_DRIVER
60 #ifdef G4MULTITHREADED
65 const GLubyte G4OpenGLSceneHandler::fStippleMaskHashed [128] = {
66 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
67 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
68 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
69 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
70 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
71 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
72 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
73 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
74 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
75 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
76 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
77 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
78 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
79 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
80 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
81 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55
88 #ifdef G4OPENGL_VERSION_2
89 fEmulate_GL_QUADS(false),
92 fThreePassCapable(false),
93 fSecondPassForTransparencyRequested(false),
94 fSecondPassForTransparency(false),
95 fThirdPassForNonHiddenMarkersRequested(false),
96 fThirdPassForNonHiddenMarkers(false),
101 G4OpenGLSceneHandler::~G4OpenGLSceneHandler ()
106 void G4OpenGLSceneHandler::ClearAndDestroyAtts()
108 std::map<GLuint, G4AttHolder*>::iterator i;
109 for (i = fPickMap.begin(); i != fPickMap.end(); ++i)
delete i->second;
113 G4int G4OpenGLSceneHandler::fEntitiesFlushInterval = 100;
114 G4OpenGLSceneHandler::FlushAction
115 G4OpenGLSceneHandler::fFlushAction = G4OpenGLSceneHandler::NthEvent;
117 void G4OpenGLSceneHandler::ScaledFlush()
119 if (fReadyForTransients) {
123 switch (fFlushAction) {
129 if (fpScene->GetRefreshAtEndOfEvent())
return;
132 const G4Event* thisEvent = fpModel->GetModelingParameters()->GetEvent();
133 if (!thisEvent) {glFlush();
return;}
135 static G4int lastEventID = 0;
136 if (thisEventID != lastEventID) {
138 lastEventID = thisEventID;
147 if (fpScene->GetRefreshAtEndOfRun())
return;
150 #ifdef G4MULTITHREADED
155 if (!runMan) {glFlush();
return;}
157 if (!thisRun) {glFlush();
return;}
159 static G4int lastRunID = 0;
160 if (thisRunID != lastRunID) {
162 lastRunID = thisRunID;
168 fEntitiesFlushInterval = 1;
172 static G4int primitivesWaitingToBeFlushed = 0;
173 primitivesWaitingToBeFlushed++;
174 if (primitivesWaitingToBeFlushed < fEntitiesFlushInterval)
return;
176 primitivesWaitingToBeFlushed = 0;
182 if (fpScene->GetRefreshAtEndOfEvent())
return;
185 const G4Event* thisEvent = fpModel->GetModelingParameters()->GetEvent();
187 static G4int lastEventID = 0;
188 if (thisEventID != lastEventID) {
189 static G4int eventsWaitingToBeFlushed = 0;
190 eventsWaitingToBeFlushed++;
191 if (eventsWaitingToBeFlushed < fEntitiesFlushInterval)
return;
193 eventsWaitingToBeFlushed = 0;
194 lastEventID = thisEventID;
218 switch (fFlushAction) {
225 fEntitiesFlushInterval = 1;
229 static G4int primitivesWaitingToBeFlushed = 0;
230 primitivesWaitingToBeFlushed++;
231 if (primitivesWaitingToBeFlushed < fEntitiesFlushInterval)
return;
233 primitivesWaitingToBeFlushed = 0;
247 void G4OpenGLSceneHandler::ProcessScene()
249 fThreePassCapable =
true;
254 if (fSecondPassForTransparencyRequested) {
255 fSecondPassForTransparency =
true;
257 fSecondPassForTransparency =
false;
258 fSecondPassForTransparencyRequested =
false;
262 if (fThirdPassForNonHiddenMarkersRequested) {
263 fThirdPassForNonHiddenMarkers =
true;
265 fThirdPassForNonHiddenMarkers =
false;
266 fThirdPassForNonHiddenMarkersRequested =
false;
269 fThreePassCapable =
false;
272 void G4OpenGLSceneHandler::PreAddSolid
279 void G4OpenGLSceneHandler::BeginPrimitives
285 void G4OpenGLSceneHandler::EndPrimitives ()
290 void G4OpenGLSceneHandler::BeginPrimitives2D
296 void G4OpenGLSceneHandler::EndPrimitives2D ()
301 G4VSolid* G4OpenGLSceneHandler::CreateSectionSolid ()
308 G4VSolid* G4OpenGLSceneHandler::CreateCutawaySolid ()
316 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polyline& line)
318 G4int nPoints = line.size ();
319 if (nPoints <= 0)
return;
323 #ifndef G4OPENGL_VERSION_2
324 glDisable (GL_LIGHTING);
327 G4double lineWidth = GetLineWidth(fpVisAttribs);
332 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
333 if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth);
336 #ifndef G4OPENGL_VERSION_2
337 glBegin (GL_LINE_STRIP);
342 for (
G4int iPoint = 0; iPoint < nPoints; iPoint++) {
344 x = line[iPoint].x();
345 y = line[iPoint].y();
346 z = line[iPoint].z();
347 glVertex3d (x, y, z);
351 glBeginVBO(GL_LINE_STRIP);
353 for (
G4int iPoint = 0; iPoint < nPoints; iPoint++) {
354 fOglVertex.push_back(line[iPoint].x());
355 fOglVertex.push_back(line[iPoint].y());
356 fOglVertex.push_back(line[iPoint].z());
358 fOglVertex.push_back(0);
359 fOglVertex.push_back(0);
360 fOglVertex.push_back(1);
367 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polymarker& polymarker)
369 if (polymarker.size() == 0) {
375 #ifndef G4OPENGL_VERSION_2
376 glDisable (GL_LIGHTING);
379 MarkerSizeType sizeType;
380 G4double size = GetMarkerSize(polymarker, sizeType);
386 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
387 if (!pGLViewer)
return;
389 if (sizeType == world) {
390 G4double lineWidth = GetLineWidth(fpVisAttribs);
391 pGLViewer->ChangeLineWidth(lineWidth);
396 static G4bool hashedWarned =
false;
400 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
401 glEdgeFlag (GL_TRUE);
406 G4cout <<
"Hashed fill style in G4OpenGLSceneHandler."
407 <<
"\n Not implemented. Using G4VMarker::filled."
415 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
422 if (sizeType == world) {
432 nSides = GetNoOfSides(fpVisAttribs);
442 fpViewer -> GetViewParameters().GetViewpointDirection();
443 const G4Vector3D& up = fpViewer->GetViewParameters().GetUpVector();
446 G4Vector3D start = radius * (up.cross(viewpointDirection)).unit();
449 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
451 #ifndef G4OPENGL_VERSION_2
452 glBegin (GL_POLYGON);
453 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
454 G4Vector3D r = start; r.rotate(phi, viewpointDirection);
456 glVertex3d (p.x(), p.y(), p.z());
460 glBeginVBO (GL_TRIANGLE_STRIP);
461 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
462 G4Vector3D r = start; r.rotate(phi, viewpointDirection);
465 fOglVertex.push_back(p.x());
466 fOglVertex.push_back(p.y());
467 fOglVertex.push_back(p.z());
469 fOglVertex.push_back(0);
470 fOglVertex.push_back(0);
471 fOglVertex.push_back(1);
479 pGLViewer->ChangePointSize(size);
482 #ifndef G4OPENGL_VERSION_2
487 glEnable (GL_POINT_SMOOTH);
break;
489 glDisable (GL_POINT_SMOOTH);
break;
492 #ifndef G4OPENGL_VERSION_2
494 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
496 glVertex3d(centre.x(),centre.y(),centre.z());
500 glBeginVBO(GL_POINTS);
502 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
503 fOglVertex.push_back(polymarker[iPoint].x());
504 fOglVertex.push_back(polymarker[iPoint].y());
505 fOglVertex.push_back(polymarker[iPoint].z());
506 fOglVertex.push_back(0);
507 fOglVertex.push_back(0);
508 fOglVertex.push_back(1);
515 void G4OpenGLSceneHandler::AddPrimitive (
const G4Text& text) {
518 #ifdef G4OPENGL_VERSION_2
521 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
522 if (pGLViewer) pGLViewer->DrawText(text);
525 void G4OpenGLSceneHandler::AddPrimitive (
const G4Circle& circle) {
530 G4OpenGLSceneHandler::AddPrimitive(oneCircle);
533 void G4OpenGLSceneHandler::AddPrimitive (
const G4Square& square) {
538 G4OpenGLSceneHandler::AddPrimitive(oneSquare);
541 void G4OpenGLSceneHandler::AddPrimitive (
const G4Scale& scale)
547 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polyhedron& polyhedron) {
552 if (polyhedron.GetNoFacets() == 0)
return;
556 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
557 if (!pGLViewer)
return;
567 GLfloat* painting_colour;
568 GLfloat current_colour [4];
569 glGetFloatv (GL_CURRENT_COLOR, current_colour);
571 G4bool isTransparent =
false;
572 if (current_colour[3] < 1.) {
573 isTransparent =
true;
579 GLfloat clear_colour[4];
580 glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_colour);
581 painting_colour = clear_colour;
583 painting_colour = current_colour;
586 G4double lineWidth = GetLineWidth(fpVisAttribs);
587 pGLViewer->ChangeLineWidth(lineWidth);
589 G4bool isAuxEdgeVisible = GetAuxEdgeVisible (fpVisAttribs);
591 G4bool clipping = pGLViewer->fVP.IsSection() || pGLViewer->fVP.IsCutaway();
594 #ifndef G4OPENGL_VERSION_2
595 glDisable (GL_LIGHTING);
598 switch (drawing_style) {
602 glEnable (GL_STENCIL_TEST);
605 glStencilFunc (GL_ALWAYS, 0, 1);
606 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
607 glEnable (GL_DEPTH_TEST);
608 glDepthFunc (GL_LEQUAL);
611 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
612 glEnable(GL_COLOR_MATERIAL);
613 glDisable (GL_CULL_FACE);
614 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
618 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
619 glEnable(GL_COLOR_MATERIAL);
620 glDisable (GL_CULL_FACE);
621 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
623 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
624 glEnable(GL_COLOR_MATERIAL);
625 glEnable (GL_CULL_FACE);
626 glCullFace (GL_BACK);
627 glPolygonMode (GL_FRONT, GL_LINE);
632 glEnable (GL_DEPTH_TEST);
633 glDepthFunc (GL_LEQUAL);
636 glDepthMask (GL_FALSE);
637 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
638 #ifndef G4OPENGL_VERSION_2
639 glEnable(GL_COLOR_MATERIAL);
641 glDisable (GL_CULL_FACE);
642 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
645 glDepthMask (GL_TRUE);
647 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
648 glEnable(GL_COLOR_MATERIAL);
649 glDisable (GL_CULL_FACE);
650 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
652 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
653 #ifndef G4OPENGL_VERSION_2
654 glEnable(GL_COLOR_MATERIAL);
656 glEnable (GL_CULL_FACE);
657 glCullFace (GL_BACK);
658 glPolygonMode (GL_FRONT, GL_FILL);
661 #ifndef G4OPENGL_VERSION_2
662 if (!fProcessing2D) glEnable (GL_LIGHTING);
667 glEnable (GL_DEPTH_TEST);
668 glDepthFunc (GL_LEQUAL);
669 glDisable (GL_CULL_FACE);
670 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
676 #ifndef G4OPENGL_VERSION_2
678 glEdgeFlag (GL_TRUE);
680 fEmulate_GL_QUADS =
true;
681 glBeginVBO(GL_TRIANGLE_STRIP);
691 notLastFace = polyhedron.GetNextFacet(nEdges, vertex, edgeFlag, normals);
694 for(
G4int edgeCount = 0; edgeCount < nEdges; ++edgeCount) {
696 if (isAuxEdgeVisible) {
697 edgeFlag[edgeCount] = 1;
699 #ifndef G4OPENGL_VERSION_2
700 if (edgeFlag[edgeCount] > 0) {
701 if (fEdgeFlag !=
true) {
702 glEdgeFlag (GL_TRUE);
706 if (fEdgeFlag !=
false) {
707 glEdgeFlag (GL_FALSE);
711 glNormal3d (normals[edgeCount].x(),
712 normals[edgeCount].y(),
713 normals[edgeCount].z());
714 glVertex3d (vertex[edgeCount].x(),
715 vertex[edgeCount].y(),
716 vertex[edgeCount].z());
719 fOglVertex.push_back(vertex[edgeCount].x());
720 fOglVertex.push_back(vertex[edgeCount].y());
721 fOglVertex.push_back(vertex[edgeCount].z());
723 fOglVertex.push_back(normals[edgeCount].x());
724 fOglVertex.push_back(normals[edgeCount].y());
725 fOglVertex.push_back(normals[edgeCount].z());
735 normals[edgeCount] = normals[0];
736 vertex[edgeCount] = vertex[0];
737 #ifndef G4OPENGL_VERSION_2
738 edgeFlag[edgeCount] = -1;
739 if (fEdgeFlag !=
false) {
740 glEdgeFlag (GL_FALSE);
744 glNormal3d (normals[edgeCount].x(),
745 normals[edgeCount].y(),
746 normals[edgeCount].z());
747 glVertex3d (vertex[edgeCount].x(),
748 vertex[edgeCount].y(),
749 vertex[edgeCount].z());
751 fOglVertex.push_back(vertex[edgeCount].x());
752 fOglVertex.push_back(vertex[edgeCount].y());
753 fOglVertex.push_back(vertex[edgeCount].z());
755 fOglVertex.push_back(normals[edgeCount].x());
756 fOglVertex.push_back(normals[edgeCount].y());
757 fOglVertex.push_back(normals[edgeCount].z());
764 "G4OpenGLSceneHandler::AddPrimitive(G4Polyhedron): WARNING"
765 "\n G4Polyhedron facet with " << nEdges <<
" edges" <<
G4endl;
773 #ifndef G4OPENGL_VERSION_2
774 glDisable(GL_COLOR_MATERIAL);
777 #ifndef G4OPENGL_VERSION_2
787 glDisable (GL_LIGHTING);
790 glStencilFunc (GL_EQUAL, 0, 1);
791 glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
793 if (!fProcessing2D) glEnable (GL_LIGHTING);
795 glEnable (GL_DEPTH_TEST);
796 glDepthFunc (GL_LEQUAL);
799 glDepthMask (GL_FALSE);
800 glDisable (GL_CULL_FACE);
801 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
804 glDepthMask (GL_TRUE);
806 glDisable (GL_CULL_FACE);
807 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
809 glEnable (GL_CULL_FACE);
810 glCullFace (GL_BACK);
811 glPolygonMode (GL_FRONT, GL_FILL);
817 goto end_of_drawing_through_stencil;
822 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, painting_colour);
825 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, painting_colour);
827 glColor4fv (painting_colour);
828 #ifndef G4OPENGL_VERSION_2
830 glEdgeFlag (GL_TRUE);
833 fEmulate_GL_QUADS =
true;
834 glBeginVBO(GL_TRIANGLE_STRIP);
837 for (
int edgeCount = 0; edgeCount < 4; ++edgeCount) {
838 #ifndef G4OPENGL_VERSION_2
839 if (edgeFlag[edgeCount] > 0) {
840 if (fEdgeFlag !=
true) {
841 glEdgeFlag (GL_TRUE);
845 if (fEdgeFlag !=
false) {
846 glEdgeFlag (GL_FALSE);
850 glNormal3d (normals[edgeCount].x(),
851 normals[edgeCount].y(),
852 normals[edgeCount].z());
853 glVertex3d (vertex[edgeCount].x(),
854 vertex[edgeCount].y(),
855 vertex[edgeCount].z());
857 fOglVertex.push_back(vertex[edgeCount].x());
858 fOglVertex.push_back(vertex[edgeCount].y());
859 fOglVertex.push_back(vertex[edgeCount].z());
861 fOglVertex.push_back(normals[edgeCount].x());
862 fOglVertex.push_back(normals[edgeCount].y());
863 fOglVertex.push_back(normals[edgeCount].z());
867 #ifndef G4OPENGL_VERSION_2
872 end_of_drawing_through_stencil:
875 glStencilFunc (GL_ALWAYS, 0, 1);
876 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
877 glDepthFunc (GL_LEQUAL);
880 glDisable (GL_CULL_FACE);
881 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
885 glDisable (GL_CULL_FACE);
886 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
888 glEnable (GL_CULL_FACE);
889 glCullFace (GL_BACK);
890 glPolygonMode (GL_FRONT, GL_LINE);
893 glDisable (GL_LIGHTING);
894 glColor4fv (current_colour);
896 #ifndef G4OPENGL_VERSION_2
898 glEdgeFlag (GL_TRUE);
901 fEmulate_GL_QUADS =
true;
902 glBeginVBO(GL_TRIANGLE_STRIP);
904 for (
int edgeCount = 0; edgeCount < 4; ++edgeCount) {
905 #ifndef G4OPENGL_VERSION_2
906 if (edgeFlag[edgeCount] > 0) {
907 if (fEdgeFlag !=
true) {
908 glEdgeFlag (GL_TRUE);
912 if (fEdgeFlag !=
false) {
913 glEdgeFlag (GL_FALSE);
917 glNormal3d (normals[edgeCount].x(),
918 normals[edgeCount].y(),
919 normals[edgeCount].z());
920 glVertex3d (vertex[edgeCount].x(),
921 vertex[edgeCount].y(),
922 vertex[edgeCount].z());
924 fOglVertex.push_back(vertex[edgeCount].x());
925 fOglVertex.push_back(vertex[edgeCount].y());
926 fOglVertex.push_back(vertex[edgeCount].z());
928 fOglVertex.push_back(normals[edgeCount].x());
929 fOglVertex.push_back(normals[edgeCount].y());
930 fOglVertex.push_back(normals[edgeCount].z());
934 #ifndef G4OPENGL_VERSION_2
940 glDepthFunc (GL_LEQUAL);
942 #ifndef G4OPENGL_VERSION_2
944 glEdgeFlag (GL_TRUE);
950 fEmulate_GL_QUADS =
true;
951 glBeginVBO(GL_TRIANGLE_STRIP);
954 }
while (notLastFace);
956 #ifndef G4OPENGL_VERSION_2
964 GLenum oldDrawArrayType = fDrawArrayType;
966 if (dynamic_cast<const G4PolyhedronTrd2*>(&polyhedron)) {
968 }
else if (dynamic_cast<const G4PolyhedronCons*>(&polyhedron)) {
973 fDrawArrayType = oldDrawArrayType;
976 glDisable (GL_STENCIL_TEST);
977 glDepthMask (GL_TRUE);
978 #ifndef G4OPENGL_VERSION_2
979 glDisable (GL_LIGHTING);
983 void G4OpenGLSceneHandler::AddCompound(
const G4VTrajectory& traj) {
987 void G4OpenGLSceneHandler::AddCompound(
const G4VHit& hit) {
991 void G4OpenGLSceneHandler::AddCompound(
const G4VDigi& digi) {
1004 #ifdef G4OPENGL_VERSION_2
1007 void G4OpenGLSceneHandler::OptimizeVBOForTrd(){
1012 std::vector<double> vertices;
1013 vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+6*6);
1014 vertices.insert (vertices.end(),fOglVertex.begin()+9*6,fOglVertex.begin()+9*6+6);
1015 vertices.insert (vertices.end(),fOglVertex.begin()+13*6,fOglVertex.begin()+13*6+6);
1016 fOglVertex = vertices;
1019 3,2,0,1,4,5,7,6, 6,0,4,3,7,2,6,1,5
1021 fOglIndices.insert(fOglIndices.begin(), myarray, myarray+17);
1023 fDrawArrayType = GL_TRIANGLE_STRIP;
1027 void G4OpenGLSceneHandler::OptimizeVBOForCons(
G4int aNoFaces){
1051 std::vector<double> vertices;
1055 vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*4)*6,fOglVertex.begin()+(aNoFaces*4)*6+6);
1056 vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*8+1)*6,fOglVertex.begin()+(aNoFaces*8+1)*6+6);
1060 for (
G4int a = 0;
a<aNoFaces;
a++) {
1061 posInVertice =
a*4*6;
1062 vertices.insert (vertices.end(),fOglVertex.begin()+posInVertice,fOglVertex.begin()+posInVertice+1*6+6);
1064 vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+1*6*6);
1065 fOglVertex = vertices;
1071 fOglIndices.push_back(0);
1072 fOglIndices.push_back(
a*2+2);
1075 fOglIndices.push_back(0);
1076 fOglIndices.push_back(2);
1079 for (
G4int a = 0;
a<aNoFaces;
a++) {
1080 fOglIndices.push_back(
a*2+2);
1081 fOglIndices.push_back(
a*2+1+2);
1083 fOglIndices.push_back(2);
1084 fOglIndices.push_back(2+1);
1089 fOglIndices.push_back(
a*2+3);
1090 fOglIndices.push_back(1);
1093 fOglIndices.push_back(0+3);
1095 fDrawArrayType = GL_TRIANGLE_STRIP;
1096 fEmulate_GL_QUADS =
false;
1099 void G4OpenGLSceneHandler::glBeginVBO(GLenum type) {
1100 fDrawArrayType = type;
1101 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1102 glGenBuffers(1,&fVertexBufferObject);
1103 glGenBuffers(1,&fIndicesBufferObject);
1105 fVertexBufferObject = glCreateBuffer();
1106 fIndicesBufferObject = glCreateBuffer();
1111 fOglIndices.clear();
1120 void G4OpenGLSceneHandler::glEndVBO() {
1121 if (fOglIndices.size() == 0) {
1124 std::vector<double> vertices;
1126 if (fEmulate_GL_QUADS ==
true) {
1127 fEmulate_GL_QUADS =
false;
1144 for (
unsigned int a=0;
a<fOglVertex.size();
a+=6*4) {
1145 vertices.insert (vertices.end(),fOglVertex.begin()+
a,fOglVertex.begin()+
a+1*6+6);
1148 if (
a+4*6+5 < fOglVertex.size()) {
1149 if ((fOglVertex[
a+2*6+0] != fOglVertex[
a+5*6+0]) ||
1150 (fOglVertex[
a+2*6+1] != fOglVertex[
a+5*6+1]) ||
1151 (fOglVertex[
a+2*6+2] != fOglVertex[
a+5*6+2]) ||
1152 (fOglVertex[
a+2*6+3] != fOglVertex[
a+5*6+3]) ||
1153 (fOglVertex[
a+2*6+4] != fOglVertex[
a+5*6+4]) ||
1154 (fOglVertex[
a+2*6+5] != fOglVertex[
a+5*6+5]) ||
1156 (fOglVertex[
a+3*6+0] != fOglVertex[
a+4*6+0]) ||
1157 (fOglVertex[
a+3*6+1] != fOglVertex[
a+4*6+1]) ||
1158 (fOglVertex[
a+3*6+2] != fOglVertex[
a+4*6+2]) ||
1159 (fOglVertex[
a+3*6+3] != fOglVertex[
a+4*6+3]) ||
1160 (fOglVertex[
a+3*6+4] != fOglVertex[
a+4*6+4]) ||
1161 (fOglVertex[
a+3*6+5] != fOglVertex[
a+4*6+5])) {
1163 vertices.insert (vertices.end(),fOglVertex.begin()+
a+3*6,fOglVertex.begin()+
a+3*6+6);
1164 vertices.insert (vertices.end(),fOglVertex.begin()+
a+2*6,fOglVertex.begin()+
a+2*6+6);
1166 drawVBOArray(vertices);
1170 vertices.insert (vertices.end(),fOglVertex.begin()+
a+3*6,fOglVertex.begin()+
a+3*6+6);
1171 vertices.insert (vertices.end(),fOglVertex.begin()+
a+2*6,fOglVertex.begin()+
a+2*6+6);
1174 fOglVertex = vertices;
1177 drawVBOArray(fOglVertex);
1182 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1185 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1186 int sizeV = fOglVertex.size();
1189 glBufferData(GL_ARRAY_BUFFER,
sizeof(
double)*sizeV, &fOglVertex[0], GL_STATIC_DRAW);
1191 glBufferDatafv(GL_ARRAY_BUFFER, fOglVertex.begin(), fOglVertex.end(), GL_STATIC_DRAW);
1195 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1198 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1199 int sizeI = fOglIndices.size();
1200 glBufferData(GL_ELEMENT_ARRAY_BUFFER,
sizeof(
int)*sizeI, &fOglIndices[0], GL_STATIC_DRAW);
1202 glBufferDataiv(GL_ELEMENT_ARRAY_BUFFER, fOglIndices.begin(), fOglIndices.end(), GL_STATIC_DRAW, GL_UNSIGNED_BYTE);
1208 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1209 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1212 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
1214 glEnableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1216 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1228 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1229 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1231 glDrawElements(fDrawArrayType, fOglIndices.size(), GL_UNSIGNED_SHORT, 0);
1234 glDisableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1238 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1239 glDeleteBuffers(1,&fVertexBufferObject);
1241 glDeleteBuffer(fVertexBufferObject);
1246 void G4OpenGLSceneHandler::drawVBOArray(std::vector<double> vertices) {
1247 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1248 glGenBuffers(1,&fVertexBufferObject);
1249 glGenBuffers(1,&fIndicesBufferObject);
1251 fVertexBufferObject = glCreateBuffer();
1252 fIndicesBufferObject = glCreateBuffer();
1256 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1258 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1259 int s = vertices.size();
1260 glBufferData(GL_ARRAY_BUFFER,
sizeof(
double)*s, &vertices[0], GL_STATIC_DRAW);
1262 glBufferDatafv(GL_ARRAY_BUFFER, vertices.begin(), vertices.end(), GL_STATIC_DRAW);
1268 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1271 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
1273 glEnableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1283 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1284 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1294 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1306 glDrawArrays(fDrawArrayType,
1307 0, vertices.size()/6);
1309 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1310 glDisableClientState( GL_VERTEX_ARRAY );
1312 glDisableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1317 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1318 glDeleteBuffers(1,&fVertexBufferObject);
1320 glDeleteBuffer(fVertexBufferObject);
virtual G4VSolid * CreateSectionSolid()
MarkerType GetMarkerType() const
static constexpr double s
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
std::vector< ExP01TrackerHit * > a
HepGeom::Point3D< G4double > G4Point3D
HepGeom::Vector3D< G4double > G4Vector3D
const char * name(G4int ptype)
G4Point3D GetPosition() const
virtual void AddPrimitive(const G4Polyline &)=0
const G4Run * GetCurrentRun() const
static constexpr double twopi
G4GLOB_DLL std::ostream G4cout
static G4MTRunManager * GetMasterRunManager()
virtual void EndPrimitives()
G4bool IsMultithreadedApplication()
virtual void BeginPrimitives2D(const G4Transform3D &objectTransformation)
static G4RunManager * GetRunManager()
virtual void AddCompound(const G4VTrajectory &)
virtual void ProcessScene()
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
FillStyle GetFillStyle() const
static constexpr double pi
virtual void EndPrimitives2D()
G4GLOB_DLL std::ostream G4cerr
HepGeom::Normal3D< G4double > G4Normal3D