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) {
135 fpModel->GetModelingParameters();
136 if (!modelingParameters) {
148 #ifdef G4MULTITHREADED
163 switch (fFlushAction) {
167 if (!fpScene->GetRefreshAtEndOfEvent()) {
172 static G4int lastEventID = 0;
173 if (thisEventID != lastEventID) {
175 lastEventID = thisEventID;
182 if (!fpScene->GetRefreshAtEndOfRun()) {
186 static G4int lastRunID = 0;
187 if (thisRunID != lastRunID) {
189 lastRunID = thisRunID;
195 fEntitiesFlushInterval = 1;
199 static G4int primitivesWaitingToBeFlushed = 0;
200 primitivesWaitingToBeFlushed++;
201 if (primitivesWaitingToBeFlushed < fEntitiesFlushInterval)
return;
203 primitivesWaitingToBeFlushed = 0;
209 if (!fpScene->GetRefreshAtEndOfEvent()) {
211 static G4int lastEventID = 0;
212 if (thisEventID != lastEventID) {
213 static G4int eventsWaitingToBeFlushed = 0;
214 eventsWaitingToBeFlushed++;
215 if (eventsWaitingToBeFlushed < fEntitiesFlushInterval)
return;
217 eventsWaitingToBeFlushed = 0;
218 lastEventID = thisEventID;
242 switch (fFlushAction) {
249 fEntitiesFlushInterval = 1;
253 static G4int primitivesWaitingToBeFlushed = 0;
254 primitivesWaitingToBeFlushed++;
255 if (primitivesWaitingToBeFlushed < fEntitiesFlushInterval)
return;
257 primitivesWaitingToBeFlushed = 0;
271 void G4OpenGLSceneHandler::ProcessScene()
273 fThreePassCapable =
true;
278 if (fSecondPassForTransparencyRequested) {
279 fSecondPassForTransparency =
true;
281 fSecondPassForTransparency =
false;
282 fSecondPassForTransparencyRequested =
false;
286 if (fThirdPassForNonHiddenMarkersRequested) {
287 fThirdPassForNonHiddenMarkers =
true;
289 fThirdPassForNonHiddenMarkers =
false;
290 fThirdPassForNonHiddenMarkersRequested =
false;
293 fThreePassCapable =
false;
296 void G4OpenGLSceneHandler::PreAddSolid
303 void G4OpenGLSceneHandler::BeginPrimitives
309 void G4OpenGLSceneHandler::EndPrimitives ()
314 void G4OpenGLSceneHandler::BeginPrimitives2D
320 void G4OpenGLSceneHandler::EndPrimitives2D ()
325 G4VSolid* G4OpenGLSceneHandler::CreateSectionSolid ()
332 G4VSolid* G4OpenGLSceneHandler::CreateCutawaySolid ()
340 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polyline& line)
342 G4int nPoints = line.size ();
343 if (nPoints <= 0)
return;
347 #ifndef G4OPENGL_VERSION_2
348 glDisable (GL_LIGHTING);
351 G4double lineWidth = GetLineWidth(fpVisAttribs);
356 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
357 if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth);
360 #ifndef G4OPENGL_VERSION_2
361 glBegin (GL_LINE_STRIP);
366 for (
G4int iPoint = 0; iPoint < nPoints; iPoint++) {
368 x = line[iPoint].x();
369 y = line[iPoint].y();
370 z = line[iPoint].z();
371 glVertex3d (x, y, z);
375 glBeginVBO(GL_LINE_STRIP);
377 for (
G4int iPoint = 0; iPoint < nPoints; iPoint++) {
378 fOglVertex.push_back(line[iPoint].x());
379 fOglVertex.push_back(line[iPoint].y());
380 fOglVertex.push_back(line[iPoint].z());
382 fOglVertex.push_back(0);
383 fOglVertex.push_back(0);
384 fOglVertex.push_back(1);
391 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polymarker& polymarker)
393 if (polymarker.size() == 0) {
399 #ifndef G4OPENGL_VERSION_2
400 glDisable (GL_LIGHTING);
403 MarkerSizeType sizeType;
404 G4double size = GetMarkerSize(polymarker, sizeType);
410 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
411 if (!pGLViewer)
return;
413 if (sizeType == world) {
414 G4double lineWidth = GetLineWidth(fpVisAttribs);
415 pGLViewer->ChangeLineWidth(lineWidth);
420 static G4bool hashedWarned =
false;
424 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
425 glEdgeFlag (GL_TRUE);
430 G4cout <<
"Hashed fill style in G4OpenGLSceneHandler."
431 <<
"\n Not implemented. Using G4VMarker::filled."
439 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
446 if (sizeType == world) {
456 nSides = GetNoOfSides(fpVisAttribs);
466 fpViewer -> GetViewParameters().GetViewpointDirection();
467 const G4Vector3D& up = fpViewer->GetViewParameters().GetUpVector();
473 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
475 #ifndef G4OPENGL_VERSION_2
476 glBegin (GL_POLYGON);
477 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
480 glVertex3d (p.
x(), p.
y(), p.
z());
484 glBeginVBO (GL_TRIANGLE_STRIP);
485 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
489 fOglVertex.push_back(p.
x());
490 fOglVertex.push_back(p.
y());
491 fOglVertex.push_back(p.
z());
493 fOglVertex.push_back(0);
494 fOglVertex.push_back(0);
495 fOglVertex.push_back(1);
503 pGLViewer->ChangePointSize(size);
506 #ifndef G4OPENGL_VERSION_2
511 glEnable (GL_POINT_SMOOTH);
break;
513 glDisable (GL_POINT_SMOOTH);
break;
516 #ifndef G4OPENGL_VERSION_2
518 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
520 glVertex3d(centre.
x(),centre.
y(),centre.
z());
524 glBeginVBO(GL_POINTS);
526 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
527 fOglVertex.push_back(polymarker[iPoint].x());
528 fOglVertex.push_back(polymarker[iPoint].y());
529 fOglVertex.push_back(polymarker[iPoint].z());
530 fOglVertex.push_back(0);
531 fOglVertex.push_back(0);
532 fOglVertex.push_back(1);
539 void G4OpenGLSceneHandler::AddPrimitive (
const G4Text& text) {
542 #ifdef G4OPENGL_VERSION_2
545 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
546 if (pGLViewer) pGLViewer->DrawText(text);
549 void G4OpenGLSceneHandler::AddPrimitive (
const G4Circle& circle) {
554 G4OpenGLSceneHandler::AddPrimitive(oneCircle);
557 void G4OpenGLSceneHandler::AddPrimitive (
const G4Square& square) {
562 G4OpenGLSceneHandler::AddPrimitive(oneSquare);
565 void G4OpenGLSceneHandler::AddPrimitive (
const G4Scale& scale)
571 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polyhedron& polyhedron) {
580 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
581 if (!pGLViewer)
return;
591 GLfloat* painting_colour;
592 GLfloat current_colour [4];
593 glGetFloatv (GL_CURRENT_COLOR, current_colour);
595 G4bool isTransparent =
false;
596 if (current_colour[3] < 1.) {
597 isTransparent =
true;
603 GLfloat clear_colour[4];
604 glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_colour);
605 painting_colour = clear_colour;
607 painting_colour = current_colour;
610 G4double lineWidth = GetLineWidth(fpVisAttribs);
611 pGLViewer->ChangeLineWidth(lineWidth);
613 G4bool isAuxEdgeVisible = GetAuxEdgeVisible (fpVisAttribs);
615 G4bool clipping = pGLViewer->fVP.IsSection() || pGLViewer->fVP.IsCutaway();
618 #ifndef G4OPENGL_VERSION_2
619 glDisable (GL_LIGHTING);
622 switch (drawing_style) {
626 glEnable (GL_STENCIL_TEST);
629 glStencilFunc (GL_ALWAYS, 0, 1);
630 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
631 glEnable (GL_DEPTH_TEST);
632 glDepthFunc (GL_LEQUAL);
635 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
636 glEnable(GL_COLOR_MATERIAL);
637 glDisable (GL_CULL_FACE);
638 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
642 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
643 glEnable(GL_COLOR_MATERIAL);
644 glDisable (GL_CULL_FACE);
645 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
647 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
648 glEnable(GL_COLOR_MATERIAL);
649 glEnable (GL_CULL_FACE);
650 glCullFace (GL_BACK);
651 glPolygonMode (GL_FRONT, GL_LINE);
656 glEnable (GL_DEPTH_TEST);
657 glDepthFunc (GL_LEQUAL);
660 glDepthMask (GL_FALSE);
661 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
662 #ifndef G4OPENGL_VERSION_2
663 glEnable(GL_COLOR_MATERIAL);
665 glDisable (GL_CULL_FACE);
666 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
669 glDepthMask (GL_TRUE);
671 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
672 glEnable(GL_COLOR_MATERIAL);
673 glDisable (GL_CULL_FACE);
674 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
676 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
677 #ifndef G4OPENGL_VERSION_2
678 glEnable(GL_COLOR_MATERIAL);
680 glEnable (GL_CULL_FACE);
681 glCullFace (GL_BACK);
682 glPolygonMode (GL_FRONT, GL_FILL);
685 #ifndef G4OPENGL_VERSION_2
686 if (!fProcessing2D) glEnable (GL_LIGHTING);
691 glEnable (GL_DEPTH_TEST);
692 glDepthFunc (GL_LEQUAL);
693 glDisable (GL_CULL_FACE);
694 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
700 #ifndef G4OPENGL_VERSION_2
702 glEdgeFlag (GL_TRUE);
704 fEmulate_GL_QUADS =
true;
705 glBeginVBO(GL_TRIANGLE_STRIP);
715 notLastFace = polyhedron.
GetNextFacet(nEdges, vertex, edgeFlag, normals);
718 for(
G4int edgeCount = 0; edgeCount < nEdges; ++edgeCount) {
720 if (isAuxEdgeVisible) {
721 edgeFlag[edgeCount] = 1;
723 #ifndef G4OPENGL_VERSION_2
724 if (edgeFlag[edgeCount] > 0) {
725 if (fEdgeFlag !=
true) {
726 glEdgeFlag (GL_TRUE);
730 if (fEdgeFlag !=
false) {
731 glEdgeFlag (GL_FALSE);
735 glNormal3d (normals[edgeCount].x(),
736 normals[edgeCount].y(),
737 normals[edgeCount].z());
738 glVertex3d (vertex[edgeCount].x(),
739 vertex[edgeCount].y(),
740 vertex[edgeCount].z());
743 fOglVertex.push_back(vertex[edgeCount].x());
744 fOglVertex.push_back(vertex[edgeCount].y());
745 fOglVertex.push_back(vertex[edgeCount].z());
747 fOglVertex.push_back(normals[edgeCount].x());
748 fOglVertex.push_back(normals[edgeCount].y());
749 fOglVertex.push_back(normals[edgeCount].z());
759 normals[edgeCount] = normals[0];
760 vertex[edgeCount] = vertex[0];
761 #ifndef G4OPENGL_VERSION_2
762 edgeFlag[edgeCount] = -1;
763 if (fEdgeFlag !=
false) {
764 glEdgeFlag (GL_FALSE);
768 glNormal3d (normals[edgeCount].x(),
769 normals[edgeCount].y(),
770 normals[edgeCount].z());
771 glVertex3d (vertex[edgeCount].x(),
772 vertex[edgeCount].y(),
773 vertex[edgeCount].z());
775 fOglVertex.push_back(vertex[edgeCount].x());
776 fOglVertex.push_back(vertex[edgeCount].y());
777 fOglVertex.push_back(vertex[edgeCount].z());
779 fOglVertex.push_back(normals[edgeCount].x());
780 fOglVertex.push_back(normals[edgeCount].y());
781 fOglVertex.push_back(normals[edgeCount].z());
788 "G4OpenGLSceneHandler::AddPrimitive(G4Polyhedron): WARNING"
789 "\n G4Polyhedron facet with " << nEdges <<
" edges" <<
G4endl;
797 #ifndef G4OPENGL_VERSION_2
798 glDisable(GL_COLOR_MATERIAL);
801 #ifndef G4OPENGL_VERSION_2
811 glDisable (GL_LIGHTING);
814 glStencilFunc (GL_EQUAL, 0, 1);
815 glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
817 if (!fProcessing2D) glEnable (GL_LIGHTING);
819 glEnable (GL_DEPTH_TEST);
820 glDepthFunc (GL_LEQUAL);
823 glDepthMask (GL_FALSE);
824 glDisable (GL_CULL_FACE);
825 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
828 glDepthMask (GL_TRUE);
830 glDisable (GL_CULL_FACE);
831 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
833 glEnable (GL_CULL_FACE);
834 glCullFace (GL_BACK);
835 glPolygonMode (GL_FRONT, GL_FILL);
841 goto end_of_drawing_through_stencil;
846 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, painting_colour);
849 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, painting_colour);
851 glColor4fv (painting_colour);
852 #ifndef G4OPENGL_VERSION_2
854 glEdgeFlag (GL_TRUE);
857 fEmulate_GL_QUADS =
true;
858 glBeginVBO(GL_TRIANGLE_STRIP);
861 for (
int edgeCount = 0; edgeCount < 4; ++edgeCount) {
862 #ifndef G4OPENGL_VERSION_2
863 if (edgeFlag[edgeCount] > 0) {
864 if (fEdgeFlag !=
true) {
865 glEdgeFlag (GL_TRUE);
869 if (fEdgeFlag !=
false) {
870 glEdgeFlag (GL_FALSE);
874 glNormal3d (normals[edgeCount].x(),
875 normals[edgeCount].y(),
876 normals[edgeCount].z());
877 glVertex3d (vertex[edgeCount].x(),
878 vertex[edgeCount].y(),
879 vertex[edgeCount].z());
881 fOglVertex.push_back(vertex[edgeCount].x());
882 fOglVertex.push_back(vertex[edgeCount].y());
883 fOglVertex.push_back(vertex[edgeCount].z());
885 fOglVertex.push_back(normals[edgeCount].x());
886 fOglVertex.push_back(normals[edgeCount].y());
887 fOglVertex.push_back(normals[edgeCount].z());
891 #ifndef G4OPENGL_VERSION_2
896 end_of_drawing_through_stencil:
899 glStencilFunc (GL_ALWAYS, 0, 1);
900 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
901 glDepthFunc (GL_LEQUAL);
904 glDisable (GL_CULL_FACE);
905 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
909 glDisable (GL_CULL_FACE);
910 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
912 glEnable (GL_CULL_FACE);
913 glCullFace (GL_BACK);
914 glPolygonMode (GL_FRONT, GL_LINE);
917 glDisable (GL_LIGHTING);
918 glColor4fv (current_colour);
920 #ifndef G4OPENGL_VERSION_2
922 glEdgeFlag (GL_TRUE);
925 fEmulate_GL_QUADS =
true;
926 glBeginVBO(GL_TRIANGLE_STRIP);
928 for (
int edgeCount = 0; edgeCount < 4; ++edgeCount) {
929 #ifndef G4OPENGL_VERSION_2
930 if (edgeFlag[edgeCount] > 0) {
931 if (fEdgeFlag !=
true) {
932 glEdgeFlag (GL_TRUE);
936 if (fEdgeFlag !=
false) {
937 glEdgeFlag (GL_FALSE);
941 glNormal3d (normals[edgeCount].x(),
942 normals[edgeCount].y(),
943 normals[edgeCount].z());
944 glVertex3d (vertex[edgeCount].x(),
945 vertex[edgeCount].y(),
946 vertex[edgeCount].z());
948 fOglVertex.push_back(vertex[edgeCount].x());
949 fOglVertex.push_back(vertex[edgeCount].y());
950 fOglVertex.push_back(vertex[edgeCount].z());
952 fOglVertex.push_back(normals[edgeCount].x());
953 fOglVertex.push_back(normals[edgeCount].y());
954 fOglVertex.push_back(normals[edgeCount].z());
958 #ifndef G4OPENGL_VERSION_2
964 glDepthFunc (GL_LEQUAL);
966 #ifndef G4OPENGL_VERSION_2
968 glEdgeFlag (GL_TRUE);
974 fEmulate_GL_QUADS =
true;
975 glBeginVBO(GL_TRIANGLE_STRIP);
978 }
while (notLastFace);
980 #ifndef G4OPENGL_VERSION_2
988 GLenum oldDrawArrayType = fDrawArrayType;
990 if (dynamic_cast<const G4PolyhedronTrd2*>(&polyhedron)) {
992 }
else if (dynamic_cast<const G4PolyhedronCons*>(&polyhedron)) {
997 fDrawArrayType = oldDrawArrayType;
1000 glDisable (GL_STENCIL_TEST);
1001 glDepthMask (GL_TRUE);
1002 #ifndef G4OPENGL_VERSION_2
1003 glDisable (GL_LIGHTING);
1007 void G4OpenGLSceneHandler::AddCompound(
const G4VTrajectory& traj) {
1011 void G4OpenGLSceneHandler::AddCompound(
const G4VHit& hit) {
1015 void G4OpenGLSceneHandler::AddCompound(
const G4VDigi& digi) {
1028 #ifdef G4OPENGL_VERSION_2
1031 void G4OpenGLSceneHandler::OptimizeVBOForTrd(){
1036 std::vector<double> vertices;
1037 vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+6*6);
1038 vertices.insert (vertices.end(),fOglVertex.begin()+9*6,fOglVertex.begin()+9*6+6);
1039 vertices.insert (vertices.end(),fOglVertex.begin()+13*6,fOglVertex.begin()+13*6+6);
1040 fOglVertex = vertices;
1043 3,2,0,1,4,5,7,6, 6,0,4,3,7,2,6,1,5
1045 fOglIndices.insert(fOglIndices.begin(), myarray, myarray+17);
1047 fDrawArrayType = GL_TRIANGLE_STRIP;
1051 void G4OpenGLSceneHandler::OptimizeVBOForCons(
G4int aNoFaces){
1075 std::vector<double> vertices;
1079 vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*4)*6,fOglVertex.begin()+(aNoFaces*4)*6+6);
1080 vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*8+1)*6,fOglVertex.begin()+(aNoFaces*8+1)*6+6);
1084 for (
G4int a = 0; a<aNoFaces; a++) {
1085 posInVertice = a*4*6;
1086 vertices.insert (vertices.end(),fOglVertex.begin()+posInVertice,fOglVertex.begin()+posInVertice+1*6+6);
1088 vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+1*6*6);
1089 fOglVertex = vertices;
1094 for (
G4int a=0; a<aNoFaces; a++) {
1095 fOglIndices.push_back(0);
1096 fOglIndices.push_back(a*2+2);
1099 fOglIndices.push_back(0);
1100 fOglIndices.push_back(2);
1103 for (
G4int a = 0; a<aNoFaces; a++) {
1104 fOglIndices.push_back(a*2+2);
1105 fOglIndices.push_back(a*2+1+2);
1107 fOglIndices.push_back(2);
1108 fOglIndices.push_back(2+1);
1112 for (
G4int a=0; a<aNoFaces; a++) {
1113 fOglIndices.push_back(a*2+3);
1114 fOglIndices.push_back(1);
1117 fOglIndices.push_back(0+3);
1119 fDrawArrayType = GL_TRIANGLE_STRIP;
1120 fEmulate_GL_QUADS =
false;
1123 void G4OpenGLSceneHandler::glBeginVBO(GLenum type) {
1124 fDrawArrayType = type;
1125 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1126 glGenBuffers(1,&fVertexBufferObject);
1127 glGenBuffers(1,&fIndicesBufferObject);
1129 fVertexBufferObject = glCreateBuffer();
1130 fIndicesBufferObject = glCreateBuffer();
1135 fOglIndices.clear();
1144 void G4OpenGLSceneHandler::glEndVBO() {
1145 if (fOglIndices.size() == 0) {
1148 std::vector<double> vertices;
1150 if (fEmulate_GL_QUADS ==
true) {
1151 fEmulate_GL_QUADS =
false;
1168 for (
unsigned int a=0; a<fOglVertex.size(); a+=6*4) {
1169 vertices.insert (vertices.end(),fOglVertex.begin()+a,fOglVertex.begin()+a+1*6+6);
1172 if (a+4*6+5 < fOglVertex.size()) {
1173 if ((fOglVertex[a+2*6+0] != fOglVertex[a+5*6+0]) ||
1174 (fOglVertex[a+2*6+1] != fOglVertex[a+5*6+1]) ||
1175 (fOglVertex[a+2*6+2] != fOglVertex[a+5*6+2]) ||
1176 (fOglVertex[a+2*6+3] != fOglVertex[a+5*6+3]) ||
1177 (fOglVertex[a+2*6+4] != fOglVertex[a+5*6+4]) ||
1178 (fOglVertex[a+2*6+5] != fOglVertex[a+5*6+5]) ||
1180 (fOglVertex[a+3*6+0] != fOglVertex[a+4*6+0]) ||
1181 (fOglVertex[a+3*6+1] != fOglVertex[a+4*6+1]) ||
1182 (fOglVertex[a+3*6+2] != fOglVertex[a+4*6+2]) ||
1183 (fOglVertex[a+3*6+3] != fOglVertex[a+4*6+3]) ||
1184 (fOglVertex[a+3*6+4] != fOglVertex[a+4*6+4]) ||
1185 (fOglVertex[a+3*6+5] != fOglVertex[a+4*6+5])) {
1187 vertices.insert (vertices.end(),fOglVertex.begin()+a+3*6,fOglVertex.begin()+a+3*6+6);
1188 vertices.insert (vertices.end(),fOglVertex.begin()+a+2*6,fOglVertex.begin()+a+2*6+6);
1190 drawVBOArray(vertices);
1194 vertices.insert (vertices.end(),fOglVertex.begin()+a+3*6,fOglVertex.begin()+a+3*6+6);
1195 vertices.insert (vertices.end(),fOglVertex.begin()+a+2*6,fOglVertex.begin()+a+2*6+6);
1198 fOglVertex = vertices;
1201 drawVBOArray(fOglVertex);
1206 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1209 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1210 int sizeV = fOglVertex.size();
1213 glBufferData(GL_ARRAY_BUFFER,
sizeof(
double)*sizeV, &fOglVertex[0], GL_STATIC_DRAW);
1215 glBufferDatafv(GL_ARRAY_BUFFER, fOglVertex.begin(), fOglVertex.end(), GL_STATIC_DRAW);
1219 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1222 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1223 int sizeI = fOglIndices.size();
1224 glBufferData(GL_ELEMENT_ARRAY_BUFFER,
sizeof(
int)*sizeI, &fOglIndices[0], GL_STATIC_DRAW);
1226 glBufferDataiv(GL_ELEMENT_ARRAY_BUFFER, fOglIndices.begin(), fOglIndices.end(), GL_STATIC_DRAW, GL_UNSIGNED_BYTE);
1232 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1233 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1236 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
1238 glEnableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1240 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1252 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1253 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1255 glDrawElements(fDrawArrayType, fOglIndices.size(), GL_UNSIGNED_SHORT, 0);
1258 glDisableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1262 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1263 glDeleteBuffers(1,&fVertexBufferObject);
1265 glDeleteBuffer(fVertexBufferObject);
1270 void G4OpenGLSceneHandler::drawVBOArray(std::vector<double> vertices) {
1271 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1272 glGenBuffers(1,&fVertexBufferObject);
1273 glGenBuffers(1,&fIndicesBufferObject);
1275 fVertexBufferObject = glCreateBuffer();
1276 fIndicesBufferObject = glCreateBuffer();
1280 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1282 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1283 int s = vertices.size();
1284 glBufferData(GL_ARRAY_BUFFER,
sizeof(
double)*s, &vertices[0], GL_STATIC_DRAW);
1286 glBufferDatafv(GL_ARRAY_BUFFER, vertices.begin(), vertices.end(), GL_STATIC_DRAW);
1292 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1295 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
1297 glEnableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1307 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1308 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1318 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1330 glDrawArrays(fDrawArrayType,
1331 0, vertices.size()/6);
1333 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1334 glDisableClientState( GL_VERTEX_ARRAY );
1336 glDisableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1341 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1342 glDeleteBuffers(1,&fVertexBufferObject);
1344 glDeleteBuffer(fVertexBufferObject);
BasicVector3D< T > & rotate(T a, const BasicVector3D< T > &v)
virtual G4VSolid * CreateSectionSolid()
MarkerType GetMarkerType() const
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
G4Point3D GetPosition() const
virtual void AddPrimitive(const G4Polyline &)=0
const G4Run * GetCurrentRun() const
static constexpr double twopi
G4GLOB_DLL std::ostream G4cout
const G4Event * GetEvent() const
static G4MTRunManager * GetMasterRunManager()
virtual void EndPrimitives()
G4bool IsMultithreadedApplication()
G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=0, G4Normal3D *normals=0) const
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
G4int GetNoFacets() const
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
virtual void EndPrimitives2D()
G4GLOB_DLL std::ostream G4cerr