34 #ifdef G4VIS_BUILD_OPENGL_DRIVER
59 #ifdef G4MULTITHREADED
64 const GLubyte G4OpenGLSceneHandler::fStippleMaskHashed [128] = {
65 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
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
87 #ifdef G4OPENGL_VERSION_2
88 fEmulate_GL_QUADS(
false),
91 fThreePassCapable(
false),
92 fSecondPassForTransparencyRequested(
false),
93 fSecondPassForTransparency(
false),
94 fThirdPassForNonHiddenMarkersRequested(
false),
95 fThirdPassForNonHiddenMarkers(
false),
100 G4OpenGLSceneHandler::~G4OpenGLSceneHandler ()
105 void G4OpenGLSceneHandler::ClearAndDestroyAtts()
107 std::map<GLuint, G4AttHolder*>::iterator i;
108 for (i = fPickMap.begin(); i != fPickMap.end(); ++i)
delete i->second;
112 G4int G4OpenGLSceneHandler::fEntitiesFlushInterval = 100;
113 G4OpenGLSceneHandler::FlushAction
114 G4OpenGLSceneHandler::fFlushAction = G4OpenGLSceneHandler::NthEvent;
116 void G4OpenGLSceneHandler::ScaledFlush()
118 if (fReadyForTransients) {
134 fpModel->GetModelingParameters();
135 if (!modelingParameters) {
143 if (fFlushAction == endOfEvent) {
144 fFlushAction = endOfRun;
145 }
else if (fFlushAction == NthEvent) {
146 fFlushAction = NthPrimitive;
150 #ifdef G4MULTITHREADED
163 if (fFlushAction == endOfRun) {
164 fFlushAction = NthPrimitive;
165 }
else if (fFlushAction == NthEvent) {
166 fFlushAction = NthPrimitive;
170 switch (fFlushAction) {
174 if (!fpScene->GetRefreshAtEndOfEvent()) {
179 static G4int lastEventID = 0;
180 if (thisEventID != lastEventID) {
182 lastEventID = thisEventID;
189 if (!fpScene->GetRefreshAtEndOfRun()) {
193 static G4int lastRunID = 0;
194 if (thisRunID != lastRunID) {
196 lastRunID = thisRunID;
202 fEntitiesFlushInterval = 1;
206 static G4int primitivesWaitingToBeFlushed = 0;
207 primitivesWaitingToBeFlushed++;
208 if (primitivesWaitingToBeFlushed < fEntitiesFlushInterval)
return;
210 primitivesWaitingToBeFlushed = 0;
216 if (!fpScene->GetRefreshAtEndOfEvent()) {
218 static G4int lastEventID = 0;
219 if (thisEventID != lastEventID) {
220 static G4int eventsWaitingToBeFlushed = 0;
221 eventsWaitingToBeFlushed++;
222 if (eventsWaitingToBeFlushed < fEntitiesFlushInterval)
return;
224 eventsWaitingToBeFlushed = 0;
225 lastEventID = thisEventID;
249 switch (fFlushAction) {
256 fEntitiesFlushInterval = 1;
260 static G4int primitivesWaitingToBeFlushed = 0;
261 primitivesWaitingToBeFlushed++;
262 if (primitivesWaitingToBeFlushed < fEntitiesFlushInterval)
return;
264 primitivesWaitingToBeFlushed = 0;
278 void G4OpenGLSceneHandler::ProcessScene()
280 fThreePassCapable =
true;
285 if (fSecondPassForTransparencyRequested) {
286 fSecondPassForTransparency =
true;
288 fSecondPassForTransparency =
false;
289 fSecondPassForTransparencyRequested =
false;
293 if (fThirdPassForNonHiddenMarkersRequested) {
294 fThirdPassForNonHiddenMarkers =
true;
296 fThirdPassForNonHiddenMarkers =
false;
297 fThirdPassForNonHiddenMarkersRequested =
false;
300 fThreePassCapable =
false;
303 void G4OpenGLSceneHandler::PreAddSolid
310 void G4OpenGLSceneHandler::BeginPrimitives
316 void G4OpenGLSceneHandler::EndPrimitives ()
321 void G4OpenGLSceneHandler::BeginPrimitives2D
327 void G4OpenGLSceneHandler::EndPrimitives2D ()
350 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polyline& line)
352 G4int nPoints = line.size ();
353 if (nPoints <= 0)
return;
357 #ifndef G4OPENGL_VERSION_2
358 glDisable (GL_LIGHTING);
361 G4double lineWidth = GetLineWidth(fpVisAttribs);
366 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
367 if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth);
370 #ifndef G4OPENGL_VERSION_2
371 glBegin (GL_LINE_STRIP);
376 for (
G4int iPoint = 0; iPoint < nPoints; iPoint++) {
378 x = line[iPoint].x();
379 y = line[iPoint].y();
380 z = line[iPoint].z();
381 glVertex3d (x, y, z);
385 glBeginVBO(GL_LINE_STRIP);
387 for (
G4int iPoint = 0; iPoint < nPoints; iPoint++) {
388 fOglVertex.push_back(line[iPoint].
x());
389 fOglVertex.push_back(line[iPoint].
y());
390 fOglVertex.push_back(line[iPoint].
z());
392 fOglVertex.push_back(0);
393 fOglVertex.push_back(0);
394 fOglVertex.push_back(1);
401 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polymarker& polymarker)
403 if (polymarker.size() == 0) {
409 #ifndef G4OPENGL_VERSION_2
410 glDisable (GL_LIGHTING);
413 MarkerSizeType sizeType;
414 G4double size = GetMarkerSize(polymarker, sizeType);
420 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
421 if (!pGLViewer)
return;
423 if (sizeType ==
world) {
424 G4double lineWidth = GetLineWidth(fpVisAttribs);
425 pGLViewer->ChangeLineWidth(lineWidth);
430 static G4bool hashedWarned =
false;
434 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
435 glEdgeFlag (GL_TRUE);
440 G4cout <<
"Hashed fill style in G4OpenGLSceneHandler."
441 <<
"\n Not implemented. Using G4VMarker::filled."
449 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
456 if (sizeType ==
world) {
466 nSides = GetNoOfSides(fpVisAttribs);
476 fpViewer -> GetViewParameters().GetViewpointDirection();
477 const G4Vector3D& up = fpViewer->GetViewParameters().GetUpVector();
483 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
485 #ifndef G4OPENGL_VERSION_2
486 glBegin (GL_POLYGON);
487 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
490 glVertex3d (p.
x(), p.
y(), p.
z());
494 glBeginVBO (GL_TRIANGLE_STRIP);
495 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
499 fOglVertex.push_back(p.
x());
500 fOglVertex.push_back(p.
y());
501 fOglVertex.push_back(p.
z());
503 fOglVertex.push_back(0);
504 fOglVertex.push_back(0);
505 fOglVertex.push_back(1);
513 pGLViewer->ChangePointSize(size);
516 #ifndef G4OPENGL_VERSION_2
521 glEnable (GL_POINT_SMOOTH);
break;
523 glDisable (GL_POINT_SMOOTH);
break;
526 #ifndef G4OPENGL_VERSION_2
528 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
530 glVertex3d(centre.
x(),centre.
y(),centre.
z());
534 glBeginVBO(GL_POINTS);
536 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
537 fOglVertex.push_back(polymarker[iPoint].
x());
538 fOglVertex.push_back(polymarker[iPoint].
y());
539 fOglVertex.push_back(polymarker[iPoint].
z());
540 fOglVertex.push_back(0);
541 fOglVertex.push_back(0);
542 fOglVertex.push_back(1);
549 void G4OpenGLSceneHandler::AddPrimitive (
const G4Text& text) {
552 #ifdef G4OPENGL_VERSION_2
555 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
556 if (pGLViewer) pGLViewer->DrawText(text);
559 void G4OpenGLSceneHandler::AddPrimitive (
const G4Circle& circle) {
564 G4OpenGLSceneHandler::AddPrimitive(oneCircle);
567 void G4OpenGLSceneHandler::AddPrimitive (
const G4Square&
square) {
572 G4OpenGLSceneHandler::AddPrimitive(oneSquare);
575 void G4OpenGLSceneHandler::AddPrimitive (
const G4Scale&
scale)
581 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polyhedron& polyhedron) {
590 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
591 if (!pGLViewer)
return;
601 GLfloat* painting_colour;
602 GLfloat clear_colour[4];
603 GLfloat current_colour[4];
604 glGetFloatv (GL_CURRENT_COLOR, current_colour);
606 G4bool isTransparent =
false;
607 if (current_colour[3] < 1.) {
608 isTransparent =
true;
613 glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_colour);
614 painting_colour = clear_colour;
616 painting_colour = current_colour;
619 G4double lineWidth = GetLineWidth(fpVisAttribs);
620 pGLViewer->ChangeLineWidth(lineWidth);
622 G4bool isAuxEdgeVisible = GetAuxEdgeVisible (fpVisAttribs);
624 G4bool clipping = pGLViewer->fVP.IsSection() || pGLViewer->fVP.IsCutaway();
627 #ifndef G4OPENGL_VERSION_2
628 glDisable (GL_LIGHTING);
631 switch (drawing_style) {
635 glEnable (GL_STENCIL_TEST);
638 glStencilFunc (GL_ALWAYS, 0, 1);
639 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
640 glEnable (GL_DEPTH_TEST);
641 glDepthFunc (GL_LEQUAL);
644 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
645 glEnable(GL_COLOR_MATERIAL);
646 glDisable (GL_CULL_FACE);
647 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
651 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
652 glEnable(GL_COLOR_MATERIAL);
653 glDisable (GL_CULL_FACE);
654 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
656 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
657 glEnable(GL_COLOR_MATERIAL);
658 glEnable (GL_CULL_FACE);
659 glCullFace (GL_BACK);
660 glPolygonMode (GL_FRONT, GL_LINE);
665 glEnable (GL_DEPTH_TEST);
666 glDepthFunc (GL_LEQUAL);
669 glDepthMask (GL_FALSE);
670 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
671 #ifndef G4OPENGL_VERSION_2
672 glEnable(GL_COLOR_MATERIAL);
674 glDisable (GL_CULL_FACE);
675 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
678 glDepthMask (GL_TRUE);
680 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
681 glEnable(GL_COLOR_MATERIAL);
682 glDisable (GL_CULL_FACE);
683 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
685 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
686 #ifndef G4OPENGL_VERSION_2
687 glEnable(GL_COLOR_MATERIAL);
689 glEnable (GL_CULL_FACE);
690 glCullFace (GL_BACK);
691 glPolygonMode (GL_FRONT, GL_FILL);
694 #ifndef G4OPENGL_VERSION_2
695 if (!fProcessing2D) glEnable (GL_LIGHTING);
700 glEnable (GL_DEPTH_TEST);
701 glDepthFunc (GL_LEQUAL);
702 glDisable (GL_CULL_FACE);
703 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
709 #ifndef G4OPENGL_VERSION_2
711 glEdgeFlag (GL_TRUE);
713 fEmulate_GL_QUADS =
true;
714 glBeginVBO(GL_TRIANGLE_STRIP);
724 notLastFace = polyhedron.
GetNextFacet(nEdges, vertex, edgeFlag, normals);
727 for(
G4int edgeCount = 0; edgeCount < nEdges; ++edgeCount) {
729 if (isAuxEdgeVisible) {
730 edgeFlag[edgeCount] = 1;
732 #ifndef G4OPENGL_VERSION_2
733 if (edgeFlag[edgeCount] > 0) {
734 if (fEdgeFlag !=
true) {
735 glEdgeFlag (GL_TRUE);
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());
752 fOglVertex.push_back(vertex[edgeCount].
x());
753 fOglVertex.push_back(vertex[edgeCount].
y());
754 fOglVertex.push_back(vertex[edgeCount].
z());
756 fOglVertex.push_back(normals[edgeCount].
x());
757 fOglVertex.push_back(normals[edgeCount].
y());
758 fOglVertex.push_back(normals[edgeCount].
z());
768 normals[edgeCount] = normals[0];
769 vertex[edgeCount] = vertex[0];
770 #ifndef G4OPENGL_VERSION_2
771 edgeFlag[edgeCount] = -1;
772 if (fEdgeFlag !=
false) {
773 glEdgeFlag (GL_FALSE);
777 glNormal3d (normals[edgeCount].
x(),
778 normals[edgeCount].
y(),
779 normals[edgeCount].
z());
780 glVertex3d (vertex[edgeCount].
x(),
781 vertex[edgeCount].
y(),
782 vertex[edgeCount].
z());
784 fOglVertex.push_back(vertex[edgeCount].
x());
785 fOglVertex.push_back(vertex[edgeCount].
y());
786 fOglVertex.push_back(vertex[edgeCount].
z());
788 fOglVertex.push_back(normals[edgeCount].
x());
789 fOglVertex.push_back(normals[edgeCount].
y());
790 fOglVertex.push_back(normals[edgeCount].
z());
797 "G4OpenGLSceneHandler::AddPrimitive(G4Polyhedron): WARNING"
798 "\n G4Polyhedron facet with " << nEdges <<
" edges" <<
G4endl;
806 #ifndef G4OPENGL_VERSION_2
807 glDisable(GL_COLOR_MATERIAL);
810 #ifndef G4OPENGL_VERSION_2
820 glDisable (GL_LIGHTING);
823 glStencilFunc (GL_EQUAL, 0, 1);
824 glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
826 if (!fProcessing2D) glEnable (GL_LIGHTING);
828 glEnable (GL_DEPTH_TEST);
829 glDepthFunc (GL_LEQUAL);
832 glDepthMask (GL_FALSE);
833 glDisable (GL_CULL_FACE);
834 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
837 glDepthMask (GL_TRUE);
839 glDisable (GL_CULL_FACE);
840 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
842 glEnable (GL_CULL_FACE);
843 glCullFace (GL_BACK);
844 glPolygonMode (GL_FRONT, GL_FILL);
850 goto end_of_drawing_through_stencil;
855 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, painting_colour);
858 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, painting_colour);
860 glColor4fv (painting_colour);
861 #ifndef G4OPENGL_VERSION_2
863 glEdgeFlag (GL_TRUE);
866 fEmulate_GL_QUADS =
true;
867 glBeginVBO(GL_TRIANGLE_STRIP);
870 for (
int edgeCount = 0; edgeCount < 4; ++edgeCount) {
871 #ifndef G4OPENGL_VERSION_2
872 if (edgeFlag[edgeCount] > 0) {
873 if (fEdgeFlag !=
true) {
874 glEdgeFlag (GL_TRUE);
878 if (fEdgeFlag !=
false) {
879 glEdgeFlag (GL_FALSE);
883 glNormal3d (normals[edgeCount].
x(),
884 normals[edgeCount].
y(),
885 normals[edgeCount].
z());
886 glVertex3d (vertex[edgeCount].
x(),
887 vertex[edgeCount].
y(),
888 vertex[edgeCount].
z());
890 fOglVertex.push_back(vertex[edgeCount].
x());
891 fOglVertex.push_back(vertex[edgeCount].
y());
892 fOglVertex.push_back(vertex[edgeCount].
z());
894 fOglVertex.push_back(normals[edgeCount].
x());
895 fOglVertex.push_back(normals[edgeCount].
y());
896 fOglVertex.push_back(normals[edgeCount].
z());
900 #ifndef G4OPENGL_VERSION_2
905 end_of_drawing_through_stencil:
908 glStencilFunc (GL_ALWAYS, 0, 1);
909 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
910 glDepthFunc (GL_LEQUAL);
913 glDisable (GL_CULL_FACE);
914 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
918 glDisable (GL_CULL_FACE);
919 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
921 glEnable (GL_CULL_FACE);
922 glCullFace (GL_BACK);
923 glPolygonMode (GL_FRONT, GL_LINE);
926 glDisable (GL_LIGHTING);
927 glColor4fv (current_colour);
929 #ifndef G4OPENGL_VERSION_2
931 glEdgeFlag (GL_TRUE);
934 fEmulate_GL_QUADS =
true;
935 glBeginVBO(GL_TRIANGLE_STRIP);
937 for (
int edgeCount = 0; edgeCount < 4; ++edgeCount) {
938 #ifndef G4OPENGL_VERSION_2
939 if (edgeFlag[edgeCount] > 0) {
940 if (fEdgeFlag !=
true) {
941 glEdgeFlag (GL_TRUE);
945 if (fEdgeFlag !=
false) {
946 glEdgeFlag (GL_FALSE);
950 glNormal3d (normals[edgeCount].
x(),
951 normals[edgeCount].
y(),
952 normals[edgeCount].
z());
953 glVertex3d (vertex[edgeCount].
x(),
954 vertex[edgeCount].
y(),
955 vertex[edgeCount].
z());
957 fOglVertex.push_back(vertex[edgeCount].
x());
958 fOglVertex.push_back(vertex[edgeCount].
y());
959 fOglVertex.push_back(vertex[edgeCount].
z());
961 fOglVertex.push_back(normals[edgeCount].
x());
962 fOglVertex.push_back(normals[edgeCount].
y());
963 fOglVertex.push_back(normals[edgeCount].
z());
967 #ifndef G4OPENGL_VERSION_2
973 glDepthFunc (GL_LEQUAL);
975 #ifndef G4OPENGL_VERSION_2
977 glEdgeFlag (GL_TRUE);
983 fEmulate_GL_QUADS =
true;
984 glBeginVBO(GL_TRIANGLE_STRIP);
987 }
while (notLastFace);
989 #ifndef G4OPENGL_VERSION_2
997 GLenum oldDrawArrayType = fDrawArrayType;
999 if (dynamic_cast<const G4PolyhedronTrd2*>(&polyhedron)) {
1001 }
else if (dynamic_cast<const G4PolyhedronCons*>(&polyhedron)) {
1006 fDrawArrayType = oldDrawArrayType;
1009 glDisable (GL_STENCIL_TEST);
1010 glDepthMask (GL_TRUE);
1011 #ifndef G4OPENGL_VERSION_2
1012 glDisable (GL_LIGHTING);
1016 void G4OpenGLSceneHandler::AddCompound(
const G4VTrajectory& traj) {
1020 void G4OpenGLSceneHandler::AddCompound(
const G4VHit& hit) {
1024 void G4OpenGLSceneHandler::AddCompound(
const G4VDigi& digi) {
1037 #ifdef G4OPENGL_VERSION_2
1040 void G4OpenGLSceneHandler::OptimizeVBOForTrd(){
1045 std::vector<double> vertices;
1046 vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+6*6);
1047 vertices.insert (vertices.end(),fOglVertex.begin()+9*6,fOglVertex.begin()+9*6+6);
1048 vertices.insert (vertices.end(),fOglVertex.begin()+13*6,fOglVertex.begin()+13*6+6);
1049 fOglVertex = vertices;
1052 3,2,0,1,4,5,7,6, 6,0,4,3,7,2,6,1,5
1054 fOglIndices.insert(fOglIndices.begin(), myarray, myarray+17);
1056 fDrawArrayType = GL_TRIANGLE_STRIP;
1060 void G4OpenGLSceneHandler::OptimizeVBOForCons(
G4int aNoFaces){
1084 std::vector<double> vertices;
1088 vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*4)*6,fOglVertex.begin()+(aNoFaces*4)*6+6);
1089 vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*8+1)*6,fOglVertex.begin()+(aNoFaces*8+1)*6+6);
1093 for (
G4int a = 0;
a<aNoFaces;
a++) {
1094 posInVertice =
a*4*6;
1095 vertices.insert (vertices.end(),fOglVertex.begin()+posInVertice,fOglVertex.begin()+posInVertice+1*6+6);
1097 vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+1*6*6);
1098 fOglVertex = vertices;
1104 fOglIndices.push_back(0);
1105 fOglIndices.push_back(
a*2+2);
1108 fOglIndices.push_back(0);
1109 fOglIndices.push_back(2);
1112 for (
G4int a = 0;
a<aNoFaces;
a++) {
1113 fOglIndices.push_back(
a*2+2);
1114 fOglIndices.push_back(
a*2+1+2);
1116 fOglIndices.push_back(2);
1117 fOglIndices.push_back(2+1);
1122 fOglIndices.push_back(
a*2+3);
1123 fOglIndices.push_back(1);
1126 fOglIndices.push_back(0+3);
1128 fDrawArrayType = GL_TRIANGLE_STRIP;
1129 fEmulate_GL_QUADS =
false;
1132 void G4OpenGLSceneHandler::glBeginVBO(GLenum type) {
1133 fDrawArrayType = type;
1134 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1135 glGenBuffers(1,&fVertexBufferObject);
1136 glGenBuffers(1,&fIndicesBufferObject);
1138 fVertexBufferObject = glCreateBuffer();
1139 fIndicesBufferObject = glCreateBuffer();
1144 fOglIndices.clear();
1153 void G4OpenGLSceneHandler::glEndVBO() {
1154 if (fOglIndices.size() == 0) {
1157 std::vector<double> vertices;
1159 if (fEmulate_GL_QUADS ==
true) {
1160 fEmulate_GL_QUADS =
false;
1177 for (
unsigned int a=0;
a<fOglVertex.size();
a+=6*4) {
1178 vertices.insert (vertices.end(),fOglVertex.begin()+
a,fOglVertex.begin()+
a+1*6+6);
1181 if (
a+4*6+5 < fOglVertex.size()) {
1182 if ((fOglVertex[
a+2*6+0] != fOglVertex[
a+5*6+0]) ||
1183 (fOglVertex[
a+2*6+1] != fOglVertex[
a+5*6+1]) ||
1184 (fOglVertex[
a+2*6+2] != fOglVertex[
a+5*6+2]) ||
1185 (fOglVertex[
a+2*6+3] != fOglVertex[
a+5*6+3]) ||
1186 (fOglVertex[
a+2*6+4] != fOglVertex[
a+5*6+4]) ||
1187 (fOglVertex[
a+2*6+5] != fOglVertex[
a+5*6+5]) ||
1189 (fOglVertex[
a+3*6+0] != fOglVertex[
a+4*6+0]) ||
1190 (fOglVertex[
a+3*6+1] != fOglVertex[
a+4*6+1]) ||
1191 (fOglVertex[
a+3*6+2] != fOglVertex[
a+4*6+2]) ||
1192 (fOglVertex[
a+3*6+3] != fOglVertex[
a+4*6+3]) ||
1193 (fOglVertex[
a+3*6+4] != fOglVertex[
a+4*6+4]) ||
1194 (fOglVertex[
a+3*6+5] != fOglVertex[
a+4*6+5])) {
1196 vertices.insert (vertices.end(),fOglVertex.begin()+
a+3*6,fOglVertex.begin()+
a+3*6+6);
1197 vertices.insert (vertices.end(),fOglVertex.begin()+
a+2*6,fOglVertex.begin()+
a+2*6+6);
1199 drawVBOArray(vertices);
1203 vertices.insert (vertices.end(),fOglVertex.begin()+
a+3*6,fOglVertex.begin()+
a+3*6+6);
1204 vertices.insert (vertices.end(),fOglVertex.begin()+
a+2*6,fOglVertex.begin()+
a+2*6+6);
1207 fOglVertex = vertices;
1210 drawVBOArray(fOglVertex);
1215 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1218 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1219 int sizeV = fOglVertex.size();
1222 glBufferData(GL_ARRAY_BUFFER,
sizeof(
double)*sizeV, &fOglVertex[0], GL_STATIC_DRAW);
1224 glBufferDatafv(GL_ARRAY_BUFFER, fOglVertex.begin(), fOglVertex.end(), GL_STATIC_DRAW);
1228 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1231 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1232 int sizeI = fOglIndices.size();
1233 glBufferData(GL_ELEMENT_ARRAY_BUFFER,
sizeof(
int)*sizeI, &fOglIndices[0], GL_STATIC_DRAW);
1235 glBufferDataiv(GL_ELEMENT_ARRAY_BUFFER, fOglIndices.begin(), fOglIndices.end(), GL_STATIC_DRAW, GL_UNSIGNED_BYTE);
1241 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1242 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1245 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
1247 glEnableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1249 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1261 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1262 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1264 glDrawElements(fDrawArrayType, fOglIndices.size(), GL_UNSIGNED_SHORT, 0);
1267 glDisableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1271 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1272 glDeleteBuffers(1,&fVertexBufferObject);
1274 glDeleteBuffer(fVertexBufferObject);
1279 void G4OpenGLSceneHandler::drawVBOArray(std::vector<double> vertices) {
1280 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1281 glGenBuffers(1,&fVertexBufferObject);
1282 glGenBuffers(1,&fIndicesBufferObject);
1284 fVertexBufferObject = glCreateBuffer();
1285 fIndicesBufferObject = glCreateBuffer();
1289 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1291 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1292 int s = vertices.size();
1293 glBufferData(GL_ARRAY_BUFFER,
sizeof(
double)*s, &vertices[0], GL_STATIC_DRAW);
1295 glBufferDatafv(GL_ARRAY_BUFFER, vertices.begin(), vertices.end(), GL_STATIC_DRAW);
1301 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1304 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
1306 glEnableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1316 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1317 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1327 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1339 glDrawArrays(fDrawArrayType,
1340 0, vertices.size()/6);
1342 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1343 glDisableClientState( GL_VERTEX_ARRAY );
1345 glDisableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1350 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1351 glDeleteBuffers(1,&fVertexBufferObject);
1353 glDeleteBuffer(fVertexBufferObject);