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)
80 G4OpenGLSceneHandler::~G4OpenGLSceneHandler ()
85 const GLubyte G4OpenGLSceneHandler::fStippleMaskHashed [128] = {
86 0x55,0x55,0x55,0x55,0x55,0x55,0x55,0x55,
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
104 void G4OpenGLSceneHandler::ClearAndDestroyAtts()
106 std::map<GLuint, G4AttHolder*>::iterator i;
107 for (i = fPickMap.begin(); i != fPickMap.end(); ++i)
delete i->second;
111 void G4OpenGLSceneHandler::ScaledFlush()
113 fEventsWaitingToBeFlushed++;
114 if (fEventsWaitingToBeFlushed < fEventsDrawInterval)
return;
116 fEventsWaitingToBeFlushed = 0;
119 void G4OpenGLSceneHandler::ProcessScene()
121 fThreePassCapable =
true;
126 if (fSecondPassForTransparencyRequested) {
127 fSecondPassForTransparency =
true;
129 fSecondPassForTransparency =
false;
130 fSecondPassForTransparencyRequested =
false;
134 if (fThirdPassForNonHiddenMarkersRequested) {
135 fThirdPassForNonHiddenMarkers =
true;
137 fThirdPassForNonHiddenMarkers =
false;
138 fThirdPassForNonHiddenMarkersRequested =
false;
141 fThreePassCapable =
false;
144 void G4OpenGLSceneHandler::PreAddSolid
151 void G4OpenGLSceneHandler::BeginPrimitives
157 void G4OpenGLSceneHandler::EndPrimitives ()
162 void G4OpenGLSceneHandler::BeginPrimitives2D
168 void G4OpenGLSceneHandler::EndPrimitives2D ()
173 G4VSolid* G4OpenGLSceneHandler::CreateSectionSolid ()
184 G4VSolid* G4OpenGLSceneHandler::CreateCutawaySolid ()
193 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polyline& line)
195 G4int nPoints = line.size ();
196 if (nPoints <= 0)
return;
200 glDisable (GL_LIGHTING);
206 G4double lineWidth = GetLineWidth(pVA);
211 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
212 if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth);
214 #ifndef G4OPENGL_VERSION_2
215 glBegin (GL_LINE_STRIP);
216 for (
G4int iPoint = 0; iPoint < nPoints; iPoint++) {
218 x = line[iPoint].x();
219 y = line[iPoint].y();
220 z = line[iPoint].z();
221 glVertex3d (x, y, z);
225 glBeginVBO(GL_LINE_STRIP);
227 for (
G4int iPoint = 0; iPoint < nPoints; iPoint++) {
228 fOglVertex.push_back(line[iPoint].
x());
229 fOglVertex.push_back(line[iPoint].
y());
230 fOglVertex.push_back(line[iPoint].
z());
232 fOglVertex.push_back(0);
233 fOglVertex.push_back(0);
234 fOglVertex.push_back(1);
241 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polymarker& polymarker)
243 if (polymarker.size() == 0) {
249 glDisable (GL_LIGHTING);
255 G4double lineWidth = GetLineWidth(pVA);
260 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
261 if (!pGLViewer)
return;
262 pGLViewer->ChangeLineWidth(lineWidth);
267 static G4bool hashedWarned =
false;
271 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
276 G4cout <<
"Hashed fill style in G4OpenGLSceneHandler."
277 <<
"\n Not implemented. Using G4VMarker::filled."
285 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
290 MarkerSizeType sizeType;
291 G4double size = GetMarkerSize(polymarker, sizeType);
294 if (sizeType == world) {
304 nSides = GetNoOfSides(pVA);
314 fpViewer -> GetViewParameters().GetViewpointDirection();
315 const G4Vector3D& up = fpViewer->GetViewParameters().GetUpVector();
321 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
322 #ifndef G4OPENGL_VERSION_2
323 glBegin (GL_POLYGON);
324 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
327 glVertex3d (p.
x(), p.
y(), p.
z());
331 glBeginVBO (GL_TRIANGLE_STRIP);
332 for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
336 #ifdef G4DEBUG_VIS_OGL
337 printf(
".....G4OpenGLSceneHandler::AddPrimitive polyhedron QUADS VBO 5\n");
339 fOglVertex.push_back(p.
x());
340 fOglVertex.push_back(p.
y());
341 fOglVertex.push_back(p.
z());
343 fOglVertex.push_back(0);
344 fOglVertex.push_back(0);
345 fOglVertex.push_back(1);
353 pGLViewer->ChangePointSize(size);
360 glEnable (GL_POINT_SMOOTH);
break;
362 glDisable (GL_POINT_SMOOTH);
break;
364 #ifndef G4OPENGL_VERSION_2
366 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
368 glVertex3d(centre.
x(),centre.
y(),centre.
z());
372 glBeginVBO(GL_POINTS);
374 for (
size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
375 fOglVertex.push_back(polymarker[iPoint].
x());
376 fOglVertex.push_back(polymarker[iPoint].
y());
377 fOglVertex.push_back(polymarker[iPoint].
z());
378 fOglVertex.push_back(0);
379 fOglVertex.push_back(0);
380 fOglVertex.push_back(1);
387 void G4OpenGLSceneHandler::AddPrimitive (
const G4Text& text) {
390 #ifdef G4OPENGL_VERSION_2
393 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
394 if (pGLViewer) pGLViewer->DrawText(text);
397 void G4OpenGLSceneHandler::AddPrimitive (
const G4Circle& circle) {
402 G4OpenGLSceneHandler::AddPrimitive(oneCircle);
405 void G4OpenGLSceneHandler::AddPrimitive (
const G4Square& square) {
410 G4OpenGLSceneHandler::AddPrimitive(oneSquare);
413 void G4OpenGLSceneHandler::AddPrimitive (
const G4Scale&
scale)
419 void G4OpenGLSceneHandler::AddPrimitive (
const G4Polyhedron& polyhedron) {
428 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
429 if (!pGLViewer)
return;
443 GLfloat current_colour [4];
444 glGetFloatv (GL_CURRENT_COLOR, current_colour);
446 G4bool isTransparent =
false;
447 if (current_colour[3] < 1.) {
448 isTransparent =
true;
452 GLfloat clear_colour[4];
453 glGetFloatv (GL_COLOR_CLEAR_VALUE, clear_colour);
455 G4double lineWidth = GetLineWidth(pVA);
456 pGLViewer->ChangeLineWidth(lineWidth);
458 G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA);
460 G4bool clipping = pGLViewer->fVP.IsSection() || pGLViewer->fVP.IsCutaway();
463 glDisable (GL_LIGHTING);
465 switch (drawing_style) {
469 glEnable (GL_STENCIL_TEST);
472 glStencilFunc (GL_ALWAYS, 0, 1);
473 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
474 glEnable (GL_DEPTH_TEST);
475 glDepthFunc (GL_LEQUAL);
478 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
479 glEnable(GL_COLOR_MATERIAL);
480 glDisable (GL_CULL_FACE);
481 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
485 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
486 glEnable(GL_COLOR_MATERIAL);
487 glDisable (GL_CULL_FACE);
488 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
490 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
491 glEnable(GL_COLOR_MATERIAL);
492 glEnable (GL_CULL_FACE);
493 glCullFace (GL_BACK);
494 glPolygonMode (GL_FRONT, GL_LINE);
499 glEnable (GL_DEPTH_TEST);
500 glDepthFunc (GL_LEQUAL);
503 glDepthMask (GL_FALSE);
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_FILL);
510 glDepthMask (GL_TRUE);
512 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
513 glEnable(GL_COLOR_MATERIAL);
514 glDisable (GL_CULL_FACE);
515 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
517 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
518 glEnable(GL_COLOR_MATERIAL);
519 glEnable (GL_CULL_FACE);
520 glCullFace (GL_BACK);
521 glPolygonMode (GL_FRONT, GL_FILL);
524 if (!fProcessing2D) glEnable (GL_LIGHTING);
528 glEnable (GL_DEPTH_TEST);
529 glDepthFunc (GL_LEQUAL);
530 glDisable (GL_CULL_FACE);
531 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
536 #ifndef G4OPENGL_VERSION_2
539 fEmulate_GL_QUADS =
true;
540 glBeginVBO(GL_TRIANGLE_STRIP);
550 notLastFace = polyhedron.
GetNextFacet(nEdges, vertex, edgeFlag, normals);
553 for(
G4int edgeCount = 0; edgeCount < nEdges; ++edgeCount) {
555 if (isAuxEdgeVisible) {
556 edgeFlag[edgeCount] = 1;
558 if (edgeFlag[edgeCount] > 0) {
559 glEdgeFlag (GL_TRUE);
561 glEdgeFlag (GL_FALSE);
563 #ifndef G4OPENGL_VERSION_2
564 glNormal3d (normals[edgeCount].
x(),
565 normals[edgeCount].
y(),
566 normals[edgeCount].
z());
567 glVertex3d (vertex[edgeCount].
x(),
568 vertex[edgeCount].
y(),
569 vertex[edgeCount].
z());
572 fOglVertex.push_back(vertex[edgeCount].
x());
573 fOglVertex.push_back(vertex[edgeCount].
y());
574 fOglVertex.push_back(vertex[edgeCount].
z());
576 fOglVertex.push_back(normals[edgeCount].
x());
577 fOglVertex.push_back(normals[edgeCount].
y());
578 fOglVertex.push_back(normals[edgeCount].
z());
588 normals[edgeCount] = normals[0];
589 vertex[edgeCount] = vertex[0];
590 edgeFlag[edgeCount] = -1;
591 glEdgeFlag (GL_FALSE);
593 #ifndef G4OPENGL_VERSION_2
594 glNormal3d (normals[edgeCount].
x(),
595 normals[edgeCount].
y(),
596 normals[edgeCount].
z());
597 glVertex3d (vertex[edgeCount].
x(),
598 vertex[edgeCount].
y(),
599 vertex[edgeCount].
z());
601 fOglVertex.push_back(vertex[edgeCount].
x());
602 fOglVertex.push_back(vertex[edgeCount].
y());
603 fOglVertex.push_back(vertex[edgeCount].
z());
605 fOglVertex.push_back(normals[edgeCount].
x());
606 fOglVertex.push_back(normals[edgeCount].
y());
607 fOglVertex.push_back(normals[edgeCount].
z());
614 "G4OpenGLSceneHandler::AddPrimitive(G4Polyhedron): WARNING"
615 "\n G4Polyhedron facet with " << nEdges <<
" edges" <<
G4endl;
618 glDisable(GL_COLOR_MATERIAL);
624 #ifndef G4OPENGL_VERSION_2
634 glDisable (GL_LIGHTING);
637 glStencilFunc (GL_EQUAL, 0, 1);
638 glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
640 if (!fProcessing2D) glEnable (GL_LIGHTING);
642 glEnable (GL_DEPTH_TEST);
643 glDepthFunc (GL_LEQUAL);
646 glDepthMask (GL_FALSE);
647 glDisable (GL_CULL_FACE);
648 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
651 glDepthMask (GL_TRUE);
653 glDisable (GL_CULL_FACE);
654 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
656 glEnable (GL_CULL_FACE);
657 glCullFace (GL_BACK);
658 glPolygonMode (GL_FRONT, GL_FILL);
661 GLfloat* painting_colour;
665 goto end_of_drawing_through_stencil;
667 painting_colour = clear_colour;
669 painting_colour = current_colour;
673 glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, painting_colour);
676 glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, painting_colour);
678 glColor4fv (painting_colour);
679 #ifndef G4OPENGL_VERSION_2
682 fEmulate_GL_QUADS =
true;
683 glBeginVBO(GL_TRIANGLE_STRIP);
686 for (
int edgeCount = 0; edgeCount < 4; ++edgeCount) {
687 if (edgeFlag[edgeCount] > 0) {
688 glEdgeFlag (GL_TRUE);
690 glEdgeFlag (GL_FALSE);
692 #ifndef G4OPENGL_VERSION_2
693 glNormal3d (normals[edgeCount].
x(),
694 normals[edgeCount].
y(),
695 normals[edgeCount].
z());
696 glVertex3d (vertex[edgeCount].
x(),
697 vertex[edgeCount].
y(),
698 vertex[edgeCount].
z());
700 #ifdef G4DEBUG_VIS_OGL
701 printf(
".....G4OpenGLSceneHandler::AddPrimitive polyhedron QUADS VBO 2\n");
703 fOglVertex.push_back(vertex[edgeCount].
x());
704 fOglVertex.push_back(vertex[edgeCount].
y());
705 fOglVertex.push_back(vertex[edgeCount].
z());
707 fOglVertex.push_back(normals[edgeCount].
x());
708 fOglVertex.push_back(normals[edgeCount].
y());
709 fOglVertex.push_back(normals[edgeCount].
z());
713 #ifndef G4OPENGL_VERSION_2
718 end_of_drawing_through_stencil:
721 glStencilFunc (GL_ALWAYS, 0, 1);
722 glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT);
723 glDepthFunc (GL_LEQUAL);
726 glDisable (GL_CULL_FACE);
727 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
731 glDisable (GL_CULL_FACE);
732 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
734 glEnable (GL_CULL_FACE);
735 glCullFace (GL_BACK);
736 glPolygonMode (GL_FRONT, GL_LINE);
739 glDisable (GL_LIGHTING);
740 glColor4fv (current_colour);
741 #ifndef G4OPENGL_VERSION_2
744 fEmulate_GL_QUADS =
true;
745 glBeginVBO(GL_TRIANGLE_STRIP);
747 for (
int edgeCount = 0; edgeCount < 4; ++edgeCount) {
748 if (edgeFlag[edgeCount] > 0) {
749 glEdgeFlag (GL_TRUE);
751 glEdgeFlag (GL_FALSE);
753 #ifndef G4OPENGL_VERSION_2
754 glNormal3d (normals[edgeCount].
x(),
755 normals[edgeCount].
y(),
756 normals[edgeCount].
z());
757 glVertex3d (vertex[edgeCount].
x(),
758 vertex[edgeCount].
y(),
759 vertex[edgeCount].
z());
761 #ifdef G4DEBUG_VIS_OGL
762 printf(
".....G4OpenGLSceneHandler::AddPrimitive polyhedron QUADS VBO 3\n");
764 fOglVertex.push_back(vertex[edgeCount].
x());
765 fOglVertex.push_back(vertex[edgeCount].
y());
766 fOglVertex.push_back(vertex[edgeCount].
z());
768 fOglVertex.push_back(normals[edgeCount].
x());
769 fOglVertex.push_back(normals[edgeCount].
y());
770 fOglVertex.push_back(normals[edgeCount].
z());
774 #ifndef G4OPENGL_VERSION_2
780 glDepthFunc (GL_LEQUAL);
781 #ifndef G4OPENGL_VERSION_2
787 fEmulate_GL_QUADS =
true;
788 glBeginVBO(GL_TRIANGLE_STRIP);
791 }
while (notLastFace);
793 #ifndef G4OPENGL_VERSION_2
801 GLenum oldDrawArrayType = fDrawArrayType;
803 if (dynamic_cast<const G4PolyhedronTrd2*>(&polyhedron)) {
805 }
else if (dynamic_cast<const G4PolyhedronCons*>(&polyhedron)) {
810 fDrawArrayType = oldDrawArrayType;
813 glDisable (GL_STENCIL_TEST);
814 glDepthMask (GL_TRUE);
815 glDisable (GL_LIGHTING);
818 void G4OpenGLSceneHandler::AddCompound(
const G4VTrajectory& traj) {
822 void G4OpenGLSceneHandler::AddCompound(
const G4VHit& hit) {
826 void G4OpenGLSceneHandler::AddCompound(
const G4VDigi& digi) {
835 #ifdef G4OPENGL_VERSION_2
838 void G4OpenGLSceneHandler::OptimizeVBOForTrd(){
843 std::vector<double> vertices;
844 vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+6*6);
845 vertices.insert (vertices.end(),fOglVertex.begin()+9*6,fOglVertex.begin()+9*6+6);
846 vertices.insert (vertices.end(),fOglVertex.begin()+13*6,fOglVertex.begin()+13*6+6);
847 fOglVertex = vertices;
850 3,2,0,1,4,5,7,6, 6,0,4,3,7,2,6,1,5
852 fOglIndices.insert(fOglIndices.begin(), myarray, myarray+17);
854 fDrawArrayType = GL_TRIANGLE_STRIP;
858 void G4OpenGLSceneHandler::OptimizeVBOForCons(
G4int aNoFaces){
882 std::vector<double> vertices;
886 vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*4)*6,fOglVertex.begin()+(aNoFaces*4)*6+6);
887 vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*8+1)*6,fOglVertex.begin()+(aNoFaces*8+1)*6+6);
891 for (
G4int a = 0;
a<aNoFaces;
a++) {
892 posInVertice =
a*4*6;
893 vertices.insert (vertices.end(),fOglVertex.begin()+posInVertice,fOglVertex.begin()+posInVertice+1*6+6);
895 vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+1*6*6);
896 fOglVertex = vertices;
902 fOglIndices.push_back(0);
903 fOglIndices.push_back(
a*2+2);
906 fOglIndices.push_back(0);
907 fOglIndices.push_back(2);
910 for (
G4int a = 0;
a<aNoFaces;
a++) {
911 fOglIndices.push_back(
a*2+2);
912 fOglIndices.push_back(
a*2+1+2);
914 fOglIndices.push_back(2);
915 fOglIndices.push_back(2+1);
920 fOglIndices.push_back(
a*2+3);
921 fOglIndices.push_back(1);
924 fOglIndices.push_back(0+3);
926 fDrawArrayType = GL_TRIANGLE_STRIP;
927 fEmulate_GL_QUADS =
false;
930 void G4OpenGLSceneHandler::glBeginVBO(GLenum type) {
931 fDrawArrayType = type;
932 #ifdef G4DEBUG_VIS_OGL
933 printf(
"G4OpenGLSceneHandler::glBeginVBO %d\n",type);
935 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
936 glGenBuffers(1,&fVertexBufferObject);
937 glGenBuffers(1,&fIndicesBufferObject);
939 fVertexBufferObject = glCreateBuffer();
940 fIndicesBufferObject = glCreateBuffer();
954 void G4OpenGLSceneHandler::glEndVBO() {
955 if (fOglIndices.size() == 0) {
958 std::vector<double> vertices;
960 if (fEmulate_GL_QUADS ==
true) {
961 fEmulate_GL_QUADS =
false;
978 for (
unsigned int a=0;
a<fOglVertex.size();
a+=6*4) {
979 vertices.insert (vertices.end(),fOglVertex.begin()+
a,fOglVertex.begin()+
a+1*6+6);
982 if (
a+4*6+5 < fOglVertex.size()) {
983 if ((fOglVertex[
a+2*6+0] != fOglVertex[
a+5*6+0]) ||
984 (fOglVertex[
a+2*6+1] != fOglVertex[
a+5*6+1]) ||
985 (fOglVertex[
a+2*6+2] != fOglVertex[
a+5*6+2]) ||
986 (fOglVertex[
a+2*6+3] != fOglVertex[
a+5*6+3]) ||
987 (fOglVertex[
a+2*6+4] != fOglVertex[
a+5*6+4]) ||
988 (fOglVertex[
a+2*6+5] != fOglVertex[
a+5*6+5]) ||
990 (fOglVertex[
a+3*6+0] != fOglVertex[
a+4*6+0]) ||
991 (fOglVertex[
a+3*6+1] != fOglVertex[
a+4*6+1]) ||
992 (fOglVertex[
a+3*6+2] != fOglVertex[
a+4*6+2]) ||
993 (fOglVertex[
a+3*6+3] != fOglVertex[
a+4*6+3]) ||
994 (fOglVertex[
a+3*6+4] != fOglVertex[
a+4*6+4]) ||
995 (fOglVertex[
a+3*6+5] != fOglVertex[
a+4*6+5])) {
997 vertices.insert (vertices.end(),fOglVertex.begin()+
a+3*6,fOglVertex.begin()+
a+3*6+6);
998 vertices.insert (vertices.end(),fOglVertex.begin()+
a+2*6,fOglVertex.begin()+
a+2*6+6);
1000 drawVBOArray(vertices);
1004 vertices.insert (vertices.end(),fOglVertex.begin()+
a+3*6,fOglVertex.begin()+
a+3*6+6);
1005 vertices.insert (vertices.end(),fOglVertex.begin()+
a+2*6,fOglVertex.begin()+
a+2*6+6);
1008 fOglVertex = vertices;
1011 drawVBOArray(fOglVertex);
1016 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1019 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1020 int sizeV = fOglVertex.size();
1023 glBufferSubData(GL_ARRAY_BUFFER, 0,
sizeof(
double)*sizeV, &fOglVertex[0]);
1025 glBufferDatafv(GL_ARRAY_BUFFER, fOglVertex.begin(), fOglVertex.end(), GL_STATIC_DRAW);
1029 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1032 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1033 int sizeI = fOglIndices.size();
1034 glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0,
sizeof(
int)*sizeI, &fOglIndices[0]);
1036 glBufferDataiv(GL_ELEMENT_ARRAY_BUFFER, fOglIndices.begin(), fOglIndices.end(), GL_STATIC_DRAW);
1042 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1043 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1045 #ifdef G4DEBUG_VIS_OGL
1046 printf(
"G4OpenGLSceneHandler::glEndVBO() To DrawElements:%d vertex and %d indices\n",fOglVertex.size()/6,fOglIndices.size());
1050 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
1052 glEnableVertexAttribArray(pGLViewer->vertexPositionAttribute_);
1054 glVertexAttribPointer(pGLViewer->vertexPositionAttribute_,
1069 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1070 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
1072 glDrawElements(fDrawArrayType, fOglIndices.size(), GL_UNSIGNED_SHORT, 0);
1075 glDisableVertexAttribArray(pGLViewer->vertexPositionAttribute_);
1079 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1080 glDeleteBuffers(1,&fVertexBufferObject);
1082 glDeleteBuffer(fVertexBufferObject);
1087 void G4OpenGLSceneHandler::drawVBOArray(std::vector<double> vertices) {
1088 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1089 glGenBuffers(1,&fVertexBufferObject);
1090 glGenBuffers(1,&fIndicesBufferObject);
1092 fVertexBufferObject = glCreateBuffer();
1093 fIndicesBufferObject = glCreateBuffer();
1097 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1099 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1100 int s = vertices.size();
1101 glBufferSubData(GL_ARRAY_BUFFER, 0,
sizeof(
double)*s, &vertices[0]);
1104 glBufferDatafv(GL_ARRAY_BUFFER, vertices.begin(), vertices.end(), GL_STATIC_DRAW);
1110 glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
1112 #ifdef G4DEBUG_VIS_OGL
1113 printf(
"G4OpenGLSceneHandler::drawVBOArray To DrawArray:%d\n",vertices.size()/6);
1117 G4OpenGLViewer* pGLViewer =
dynamic_cast<G4OpenGLViewer*
>(fpViewer);
1119 glEnableVertexAttribArray(pGLViewer->vertexPositionAttribute_);
1121 glVertexAttribPointer(pGLViewer->vertexPositionAttribute_,
1132 glDrawArrays(fDrawArrayType,
1133 0, vertices.size()/6);
1135 glDisableVertexAttribArray(pGLViewer->vertexPositionAttribute_);
1139 #ifndef G4VIS_BUILD_OPENGLWT_DRIVER
1140 glDeleteBuffers(1,&fVertexBufferObject);
1142 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
const G4VisAttributes * GetVisAttributes() const
virtual void AddPrimitive(const G4Polyline &)=0
virtual G4VSolid * CreateCutawaySolid()
G4GLOB_DLL std::ostream G4cout
virtual void EndPrimitives()
G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=0, G4Normal3D *normals=0) const
G4int GetNoVertices() const
virtual void BeginPrimitives2D(const G4Transform3D &objectTransformation)
virtual void AddCompound(const G4VTrajectory &)
virtual void ProcessScene()
system("rm -rf dna.root")
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
FillStyle GetFillStyle() const
printf("%d Experimental points found\n", nlines)
G4int GetNoFacets() const
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
virtual void EndPrimitives2D()
G4GLOB_DLL std::ostream G4cerr