34#ifdef G4VIS_BUILD_OPENGL_DRIVER
62const GLubyte G4OpenGLSceneHandler::fStippleMaskHashed [128] = {
63 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
64 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
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
85#ifdef G4OPENGL_VERSION_2
86fEmulate_GL_QUADS(false),
89fThreePassCapable(false),
90fSecondPassForTransparencyRequested(false),
91fSecondPassForTransparency(false),
92fThirdPassForNonHiddenMarkersRequested(false),
93fThirdPassForNonHiddenMarkers(false),
98G4OpenGLSceneHandler::~G4OpenGLSceneHandler ()
103void G4OpenGLSceneHandler::ClearAndDestroyAtts()
105 std::map<GLuint, G4AttHolder*>::iterator i;
106 for (i = fPickMap.begin(); i != fPickMap.end(); ++i)
delete i->second;
110G4int G4OpenGLSceneHandler::fEntitiesFlushInterval = 100;
111G4OpenGLSceneHandler::FlushAction
112G4OpenGLSceneHandler::fFlushAction = G4OpenGLSceneHandler::NthEvent;
114void G4OpenGLSceneHandler::ScaledFlush()
116 if (fReadyForTransients) {
132 fpModel->GetModelingParameters();
133 if (!modelingParameters) {
141 if (fFlushAction == endOfEvent) {
142 fFlushAction = endOfRun;
143 }
else if (fFlushAction == NthEvent) {
144 fFlushAction = NthPrimitive;
156 if (fFlushAction == endOfRun) {
157 fFlushAction = NthPrimitive;
158 }
else if (fFlushAction == NthEvent) {
159 fFlushAction = NthPrimitive;
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;
271void 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;
296void G4OpenGLSceneHandler::PreAddSolid
303void G4OpenGLSceneHandler::BeginPrimitives
309void G4OpenGLSceneHandler::EndPrimitives ()
314void G4OpenGLSceneHandler::BeginPrimitives2D
320void G4OpenGLSceneHandler::EndPrimitives2D ()
343void G4OpenGLSceneHandler::AddPrimitive (
const G4Polyline& line)
345 G4int nPoints = line.size ();
346 if (nPoints <= 0)
return;
350#ifndef G4OPENGL_VERSION_2
351 glDisable (GL_LIGHTING);
354 G4double lineWidth = GetLineWidth(fpVisAttribs);
359 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
360 if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth);
363#ifndef G4OPENGL_VERSION_2
364 glBegin (GL_LINE_STRIP);
369 for (
G4int iPoint = 0; iPoint < nPoints; iPoint++) {
371 x = line[iPoint].x();
372 y = line[iPoint].y();
373 z = line[iPoint].z();
374 glVertex3d (x, y, z);
378 glBeginVBO(GL_LINE_STRIP);
380 for (
G4int iPoint = 0; iPoint < nPoints; iPoint++) {
381 fOglVertex.push_back(line[iPoint].x());
382 fOglVertex.push_back(line[iPoint].y());
383 fOglVertex.push_back(line[iPoint].z());
385 fOglVertex.push_back(0);
386 fOglVertex.push_back(0);
387 fOglVertex.push_back(1);
394void G4OpenGLSceneHandler::AddPrimitive (
const G4Polymarker& polymarker)
396 if (polymarker.size() == 0) {
402#ifndef G4OPENGL_VERSION_2
403 glDisable (GL_LIGHTING);
406 MarkerSizeType sizeType;
407 G4double size = GetMarkerSize(polymarker, sizeType);
413 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
414 if (!pGLViewer)
return;
416 if (sizeType == world) {
417 G4double lineWidth = GetLineWidth(fpVisAttribs);
418 pGLViewer->ChangeLineWidth(lineWidth);
423 static G4bool hashedWarned =
false;
427 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
428 glEdgeFlag (GL_TRUE);
433 G4cout <<
"Hashed fill style in G4OpenGLSceneHandler."
434 <<
"\n Not implemented. Using G4VMarker::filled."
442 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
449 if (sizeType == world) {
459 nSides = GetNoOfSides(fpVisAttribs);
469 fpViewer -> GetViewParameters().GetViewpointDirection();
470 const G4Vector3D& up = fpViewer->GetViewParameters().GetUpVector();
471 const G4double dPhi = twopi / nSides;
476 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
478#ifndef G4OPENGL_VERSION_2
479 glBegin (GL_POLYGON);
480 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
483 glVertex3d (p.
x(), p.
y(), p.
z());
487 glBeginVBO (GL_TRIANGLE_STRIP);
488 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
492 fOglVertex.push_back(p.
x());
493 fOglVertex.push_back(p.
y());
494 fOglVertex.push_back(p.
z());
496 fOglVertex.push_back(0);
497 fOglVertex.push_back(0);
498 fOglVertex.push_back(1);
506 pGLViewer->ChangePointSize(size);
509#ifndef G4OPENGL_VERSION_2
514 glEnable (GL_POINT_SMOOTH);
break;
516 glDisable (GL_POINT_SMOOTH);
break;
519#ifndef G4OPENGL_VERSION_2
521 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
523 glVertex3d(centre.
x(),centre.
y(),centre.
z());
527 glBeginVBO(GL_POINTS);
529 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
530 fOglVertex.push_back(polymarker[iPoint].x());
531 fOglVertex.push_back(polymarker[iPoint].y());
532 fOglVertex.push_back(polymarker[iPoint].z());
533 fOglVertex.push_back(0);
534 fOglVertex.push_back(0);
535 fOglVertex.push_back(1);
542void G4OpenGLSceneHandler::AddPrimitive (
const G4Text& text) {
545#ifdef G4OPENGL_VERSION_2
548 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
549 if (pGLViewer) pGLViewer->DrawText(text);
552void G4OpenGLSceneHandler::AddPrimitive (
const G4Circle& circle) {
557 G4OpenGLSceneHandler::AddPrimitive(oneCircle);
560void G4OpenGLSceneHandler::AddPrimitive (
const G4Square& square) {
565 G4OpenGLSceneHandler::AddPrimitive(oneSquare);
568void G4OpenGLSceneHandler::AddPrimitive (
const G4Scale& scale)
574void G4OpenGLSceneHandler::AddPrimitive (
const G4Polyhedron& polyhedron) {
583 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
584 if (!pGLViewer)
return;
594 GLfloat* painting_colour;
595 GLfloat clear_colour[4];
596 GLfloat current_colour[4];
597 glGetFloatv (GL_CURRENT_COLOR, current_colour);
599 G4bool isTransparent =
false;
600 if (current_colour[3] < 1.) {
601 isTransparent =
true;
606 glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_colour);
607 painting_colour = clear_colour;
609 painting_colour = current_colour;
612 G4double lineWidth = GetLineWidth(fpVisAttribs);
613 pGLViewer->ChangeLineWidth(lineWidth);
615 G4bool isAuxEdgeVisible = GetAuxEdgeVisible (fpVisAttribs);
617 G4bool clipping = pGLViewer->fVP.IsSection() || pGLViewer->fVP.IsCutaway();
620#ifndef G4OPENGL_VERSION_2
621 glDisable (GL_LIGHTING);
624 switch (drawing_style) {
628 glEnable (GL_STENCIL_TEST);
631 glStencilFunc (GL_ALWAYS, 0, 1);
632 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
633 glEnable (GL_DEPTH_TEST);
634 glDepthFunc (GL_LEQUAL);
637 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
638 glEnable(GL_COLOR_MATERIAL);
639 glDisable (GL_CULL_FACE);
640 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
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);
649 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
650 glEnable(GL_COLOR_MATERIAL);
651 glEnable (GL_CULL_FACE);
652 glCullFace (GL_BACK);
653 glPolygonMode (GL_FRONT, GL_LINE);
658 glEnable (GL_DEPTH_TEST);
659 glDepthFunc (GL_LEQUAL);
662 glDepthMask (GL_FALSE);
663 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
664#ifndef G4OPENGL_VERSION_2
665 glEnable(GL_COLOR_MATERIAL);
667 glDisable (GL_CULL_FACE);
668 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
671 glDepthMask (GL_TRUE);
673 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
674 glEnable(GL_COLOR_MATERIAL);
675 glDisable (GL_CULL_FACE);
676 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
678 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
679#ifndef G4OPENGL_VERSION_2
680 glEnable(GL_COLOR_MATERIAL);
682 glEnable (GL_CULL_FACE);
683 glCullFace (GL_BACK);
684 glPolygonMode (GL_FRONT, GL_FILL);
687#ifndef G4OPENGL_VERSION_2
688 if (!fProcessing2D) glEnable (GL_LIGHTING);
693 glEnable (GL_DEPTH_TEST);
694 glDepthFunc (GL_LEQUAL);
695 glDisable (GL_CULL_FACE);
696 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
702#ifndef G4OPENGL_VERSION_2
704 glEdgeFlag (GL_TRUE);
706 fEmulate_GL_QUADS =
true;
707 glBeginVBO(GL_TRIANGLE_STRIP);
717 notLastFace = polyhedron.
GetNextFacet(nEdges, vertex, edgeFlag, normals);
720 for(
G4int edgeCount = 0; edgeCount < nEdges; ++edgeCount) {
722 if (isAuxEdgeVisible) {
723 edgeFlag[edgeCount] = 1;
725#ifndef G4OPENGL_VERSION_2
726 if (edgeFlag[edgeCount] > 0) {
727 if (fEdgeFlag !=
true) {
728 glEdgeFlag (GL_TRUE);
732 if (fEdgeFlag !=
false) {
733 glEdgeFlag (GL_FALSE);
737 glNormal3d (normals[edgeCount].x(),
738 normals[edgeCount].y(),
739 normals[edgeCount].z());
740 glVertex3d (vertex[edgeCount].x(),
741 vertex[edgeCount].y(),
742 vertex[edgeCount].z());
745 fOglVertex.push_back(vertex[edgeCount].x());
746 fOglVertex.push_back(vertex[edgeCount].y());
747 fOglVertex.push_back(vertex[edgeCount].z());
749 fOglVertex.push_back(normals[edgeCount].x());
750 fOglVertex.push_back(normals[edgeCount].y());
751 fOglVertex.push_back(normals[edgeCount].z());
761 normals[edgeCount] = normals[0];
762 vertex[edgeCount] = vertex[0];
763#ifndef G4OPENGL_VERSION_2
764 edgeFlag[edgeCount] = -1;
765 if (fEdgeFlag !=
false) {
766 glEdgeFlag (GL_FALSE);
770 glNormal3d (normals[edgeCount].x(),
771 normals[edgeCount].y(),
772 normals[edgeCount].z());
773 glVertex3d (vertex[edgeCount].x(),
774 vertex[edgeCount].y(),
775 vertex[edgeCount].z());
777 fOglVertex.push_back(vertex[edgeCount].x());
778 fOglVertex.push_back(vertex[edgeCount].y());
779 fOglVertex.push_back(vertex[edgeCount].z());
781 fOglVertex.push_back(normals[edgeCount].x());
782 fOglVertex.push_back(normals[edgeCount].y());
783 fOglVertex.push_back(normals[edgeCount].z());
790 "G4OpenGLSceneHandler::AddPrimitive(G4Polyhedron): WARNING"
791 "\n G4Polyhedron facet with " << nEdges <<
" edges" <<
G4endl;
799#ifndef G4OPENGL_VERSION_2
800 glDisable(GL_COLOR_MATERIAL);
803#ifndef G4OPENGL_VERSION_2
813 glDisable (GL_LIGHTING);
816 glStencilFunc (GL_EQUAL, 0, 1);
817 glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
819 if (!fProcessing2D) glEnable (GL_LIGHTING);
821 glEnable (GL_DEPTH_TEST);
822 glDepthFunc (GL_LEQUAL);
825 glDepthMask (GL_FALSE);
826 glDisable (GL_CULL_FACE);
827 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
830 glDepthMask (GL_TRUE);
832 glDisable (GL_CULL_FACE);
833 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
835 glEnable (GL_CULL_FACE);
836 glCullFace (GL_BACK);
837 glPolygonMode (GL_FRONT, GL_FILL);
843 goto end_of_drawing_through_stencil;
848 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, painting_colour);
851 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, painting_colour);
853 glColor4fv (painting_colour);
854#ifndef G4OPENGL_VERSION_2
856 glEdgeFlag (GL_TRUE);
859 fEmulate_GL_QUADS =
true;
860 glBeginVBO(GL_TRIANGLE_STRIP);
863 for (
int edgeCount = 0; edgeCount < 4; ++edgeCount) {
864#ifndef G4OPENGL_VERSION_2
865 if (edgeFlag[edgeCount] > 0) {
866 if (fEdgeFlag !=
true) {
867 glEdgeFlag (GL_TRUE);
871 if (fEdgeFlag !=
false) {
872 glEdgeFlag (GL_FALSE);
876 glNormal3d (normals[edgeCount].x(),
877 normals[edgeCount].y(),
878 normals[edgeCount].z());
879 glVertex3d (vertex[edgeCount].x(),
880 vertex[edgeCount].y(),
881 vertex[edgeCount].z());
883 fOglVertex.push_back(vertex[edgeCount].x());
884 fOglVertex.push_back(vertex[edgeCount].y());
885 fOglVertex.push_back(vertex[edgeCount].z());
887 fOglVertex.push_back(normals[edgeCount].x());
888 fOglVertex.push_back(normals[edgeCount].y());
889 fOglVertex.push_back(normals[edgeCount].z());
893#ifndef G4OPENGL_VERSION_2
898 end_of_drawing_through_stencil:
901 glStencilFunc (GL_ALWAYS, 0, 1);
902 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
903 glDepthFunc (GL_LEQUAL);
906 glDisable (GL_CULL_FACE);
907 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
911 glDisable (GL_CULL_FACE);
912 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
914 glEnable (GL_CULL_FACE);
915 glCullFace (GL_BACK);
916 glPolygonMode (GL_FRONT, GL_LINE);
919 glDisable (GL_LIGHTING);
920 glColor4fv (current_colour);
922#ifndef G4OPENGL_VERSION_2
924 glEdgeFlag (GL_TRUE);
927 fEmulate_GL_QUADS =
true;
928 glBeginVBO(GL_TRIANGLE_STRIP);
930 for (
int edgeCount = 0; edgeCount < 4; ++edgeCount) {
931#ifndef G4OPENGL_VERSION_2
932 if (edgeFlag[edgeCount] > 0) {
933 if (fEdgeFlag !=
true) {
934 glEdgeFlag (GL_TRUE);
938 if (fEdgeFlag !=
false) {
939 glEdgeFlag (GL_FALSE);
943 glNormal3d (normals[edgeCount].x(),
944 normals[edgeCount].y(),
945 normals[edgeCount].z());
946 glVertex3d (vertex[edgeCount].x(),
947 vertex[edgeCount].y(),
948 vertex[edgeCount].z());
950 fOglVertex.push_back(vertex[edgeCount].x());
951 fOglVertex.push_back(vertex[edgeCount].y());
952 fOglVertex.push_back(vertex[edgeCount].z());
954 fOglVertex.push_back(normals[edgeCount].x());
955 fOglVertex.push_back(normals[edgeCount].y());
956 fOglVertex.push_back(normals[edgeCount].z());
960#ifndef G4OPENGL_VERSION_2
966 glDepthFunc (GL_LEQUAL);
968#ifndef G4OPENGL_VERSION_2
970 glEdgeFlag (GL_TRUE);
976 fEmulate_GL_QUADS =
true;
977 glBeginVBO(GL_TRIANGLE_STRIP);
980 }
while (notLastFace);
982#ifndef G4OPENGL_VERSION_2
990 GLenum oldDrawArrayType = fDrawArrayType;
999 fDrawArrayType = oldDrawArrayType;
1002 glDisable (GL_STENCIL_TEST);
1003 glDepthMask (GL_TRUE);
1004#ifndef G4OPENGL_VERSION_2
1005 glDisable (GL_LIGHTING);
1009void G4OpenGLSceneHandler::AddCompound(
const G4VTrajectory& traj) {
1013void G4OpenGLSceneHandler::AddCompound(
const G4VHit& hit) {
1017void G4OpenGLSceneHandler::AddCompound(
const G4VDigi& digi) {
1030#ifdef G4OPENGL_VERSION_2
1033void G4OpenGLSceneHandler::OptimizeVBOForTrd(){
1038 std::vector<double> vertices;
1039 vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+6*6);
1040 vertices.insert (vertices.end(),fOglVertex.begin()+9*6,fOglVertex.begin()+9*6+6);
1041 vertices.insert (vertices.end(),fOglVertex.begin()+13*6,fOglVertex.begin()+13*6+6);
1042 fOglVertex = vertices;
1045 3,2,0,1,4,5,7,6, 6,0,4,3,7,2,6,1,5
1047 fOglIndices.insert(fOglIndices.begin(), myarray, myarray+17);
1049 fDrawArrayType = GL_TRIANGLE_STRIP;
1053void G4OpenGLSceneHandler::OptimizeVBOForCons(
G4int aNoFaces){
1077 std::vector<double> vertices;
1081 vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*4)*6,fOglVertex.begin()+(aNoFaces*4)*6+6);
1082 vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*8+1)*6,fOglVertex.begin()+(aNoFaces*8+1)*6+6);
1086 for (
G4int a = 0; a<aNoFaces; a++) {
1087 posInVertice = a*4*6;
1088 vertices.insert (vertices.end(),fOglVertex.begin()+posInVertice,fOglVertex.begin()+posInVertice+1*6+6);
1090 vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+1*6*6);
1091 fOglVertex = vertices;
1096 for (
G4int a=0; a<aNoFaces; a++) {
1097 fOglIndices.push_back(0);
1098 fOglIndices.push_back(a*2+2);
1101 fOglIndices.push_back(0);
1102 fOglIndices.push_back(2);
1105 for (
G4int a = 0; a<aNoFaces; a++) {
1106 fOglIndices.push_back(a*2+2);
1107 fOglIndices.push_back(a*2+1+2);
1109 fOglIndices.push_back(2);
1110 fOglIndices.push_back(2+1);
1114 for (
G4int a=0; a<aNoFaces; a++) {
1115 fOglIndices.push_back(a*2+3);
1116 fOglIndices.push_back(1);
1119 fOglIndices.push_back(0+3);
1121 fDrawArrayType = GL_TRIANGLE_STRIP;
1122 fEmulate_GL_QUADS =
false;
1125void G4OpenGLSceneHandler::glBeginVBO(GLenum type) {
1126 fDrawArrayType = type;
1127#ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1128 glGenBuffers(1,&fVertexBufferObject);
1129 glGenBuffers(1,&fIndicesBufferObject);
1131 fVertexBufferObject = glCreateBuffer();
1132 fIndicesBufferObject = glCreateBuffer();
1137 fOglIndices.clear();
1146void G4OpenGLSceneHandler::glEndVBO() {
1147 if (fOglIndices.size() == 0) {
1150 std::vector<double> vertices;
1152 if (fEmulate_GL_QUADS ==
true) {
1153 fEmulate_GL_QUADS =
false;
1170 for (
unsigned int a=0; a<fOglVertex.size(); a+=6*4) {
1171 vertices.insert (vertices.end(),fOglVertex.begin()+a,fOglVertex.begin()+a+1*6+6);
1174 if (a+4*6+5 < fOglVertex.size()) {
1175 if ((fOglVertex[a+2*6+0] != fOglVertex[a+5*6+0]) ||
1176 (fOglVertex[a+2*6+1] != fOglVertex[a+5*6+1]) ||
1177 (fOglVertex[a+2*6+2] != fOglVertex[a+5*6+2]) ||
1178 (fOglVertex[a+2*6+3] != fOglVertex[a+5*6+3]) ||
1179 (fOglVertex[a+2*6+4] != fOglVertex[a+5*6+4]) ||
1180 (fOglVertex[a+2*6+5] != fOglVertex[a+5*6+5]) ||
1182 (fOglVertex[a+3*6+0] != fOglVertex[a+4*6+0]) ||
1183 (fOglVertex[a+3*6+1] != fOglVertex[a+4*6+1]) ||
1184 (fOglVertex[a+3*6+2] != fOglVertex[a+4*6+2]) ||
1185 (fOglVertex[a+3*6+3] != fOglVertex[a+4*6+3]) ||
1186 (fOglVertex[a+3*6+4] != fOglVertex[a+4*6+4]) ||
1187 (fOglVertex[a+3*6+5] != fOglVertex[a+4*6+5])) {
1189 vertices.insert (vertices.end(),fOglVertex.begin()+a+3*6,fOglVertex.begin()+a+3*6+6);
1190 vertices.insert (vertices.end(),fOglVertex.begin()+a+2*6,fOglVertex.begin()+a+2*6+6);
1192 drawVBOArray(vertices);
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);
1200 fOglVertex = vertices;
1203 drawVBOArray(fOglVertex);
1208 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1211#ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1212 int sizeV = fOglVertex.size();
1215 glBufferData(GL_ARRAY_BUFFER,
sizeof(
double)*sizeV, &fOglVertex[0], GL_STATIC_DRAW);
1217 glBufferDatafv(GL_ARRAY_BUFFER, fOglVertex.begin(), fOglVertex.end(), GL_STATIC_DRAW);
1221 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1224#ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1225 int sizeI = fOglIndices.size();
1226 glBufferData(GL_ELEMENT_ARRAY_BUFFER,
sizeof(
int)*sizeI, &fOglIndices[0], GL_STATIC_DRAW);
1228 glBufferDataiv(GL_ELEMENT_ARRAY_BUFFER, fOglIndices.begin(), fOglIndices.end(), GL_STATIC_DRAW, GL_UNSIGNED_BYTE);
1234 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1235 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1238 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
1240 glEnableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1242 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1254 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1255 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1257 glDrawElements(fDrawArrayType, fOglIndices.size(), GL_UNSIGNED_SHORT, 0);
1260 glDisableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1264#ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1265 glDeleteBuffers(1,&fVertexBufferObject);
1267 glDeleteBuffer(fVertexBufferObject);
1272void G4OpenGLSceneHandler::drawVBOArray(std::vector<double> vertices) {
1273#ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1274 glGenBuffers(1,&fVertexBufferObject);
1275 glGenBuffers(1,&fIndicesBufferObject);
1277 fVertexBufferObject = glCreateBuffer();
1278 fIndicesBufferObject = glCreateBuffer();
1282 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1284#ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1285 int s = vertices.size();
1286 glBufferData(GL_ARRAY_BUFFER,
sizeof(
double)*s, &vertices[0], GL_STATIC_DRAW);
1288 glBufferDatafv(GL_ARRAY_BUFFER, vertices.begin(), vertices.end(), GL_STATIC_DRAW);
1294 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1297 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
1299 glEnableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1309#ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1310 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1320 glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
1332 glDrawArrays(fDrawArrayType,
1333 0, vertices.size()/6);
1335#ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1336 glDisableClientState( GL_VERTEX_ARRAY );
1338 glDisableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
1343#ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1344 glDeleteBuffers(1,&fVertexBufferObject);
1346 glDeleteBuffer(fVertexBufferObject);
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
const G4Event * GetEvent() const
MarkerType GetMarkerType() const
static G4RunManager * GetMasterRunManager()
const G4Run * GetCurrentRun() const
FillStyle GetFillStyle() const
G4Point3D GetPosition() const
virtual void EndPrimitives()
virtual G4DisplacedSolid * CreateSectionSolid()
virtual void ProcessScene()
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
virtual void EndPrimitives2D()
virtual void BeginPrimitives2D(const G4Transform3D &objectTransformation=G4Transform3D())
virtual void BeginPrimitives(const G4Transform3D &objectTransformation=G4Transform3D())
virtual void AddCompound(const G4VTrajectory &)
virtual void AddPrimitive(const G4Polyline &)=0
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
BasicVector3D< T > & rotate(T a, const BasicVector3D< T > &v)
G4int GetNoFacets() const
G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=0, G4Normal3D *normals=0) const
const char * name(G4int ptype)