33 #ifdef G4VIS_BUILD_OPENGLWT_DRIVER
40 G4OpenGLImmediateWtViewer::G4OpenGLImmediateWtViewer
41 (G4OpenGLImmediateSceneHandler& sceneHandler,
42 Wt::WContainerWidget* aParent,
44 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
45 G4OpenGLViewer (sceneHandler),
46 G4OpenGLWtViewer (sceneHandler),
47 G4OpenGLImmediateViewer (sceneHandler),
48 Wt::WGLWidget(aParent)
52 fWtDrawer =
new G4OpenGLWtDrawer(
this);
55 setWtDrawer(fWtDrawer);
58 aParent->addWidget(
this);
60 fHasToRepaint =
false;
61 fIsRepainting =
false;
63 #ifdef G4DEBUG_VIS_OGL
64 printf(
"G4OpenGLImmediateWtViewer INIT\n");
68 if (fViewId < 0)
return;
71 G4OpenGLImmediateWtViewer::~G4OpenGLImmediateWtViewer() {
74 void G4OpenGLImmediateWtViewer::Initialise() {
75 #ifdef G4DEBUG_VIS_OGL
76 printf(
"G4OpenGLImmediateWtViewer::Initialise \n");
78 fReadyToPaint =
false;
79 CreateMainWindow (
this,Wt::WString(
fName));
85 void G4OpenGLImmediateWtViewer::initializeGL () {
93 if (fSceneHandler.GetScene() == 0) {
105 Wt::WMatrix4x4 worldTransform;
106 worldTransform.lookAt(
114 jsMatrix_ = createJavaScriptMatrix4();
115 setJavaScriptMatrix4(jsMatrix_, worldTransform);
121 setClientSideLookAtHandler(jsMatrix_,
131 glClearColor(0, 0, 0, 0);
135 glEnable(DEPTH_TEST);
137 #ifdef G4DEBUG_VIS_OGL
138 printf(
"G4OpenGLWtViewer initializeGL END\n");
146 void G4OpenGLImmediateWtViewer::DrawView() {
151 void G4OpenGLImmediateWtViewer::ComputeView () {
153 #ifdef G4DEBUG_VIS_OGL
154 printf(
"G4OpenGLWtViewer::ComputeView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",getWinWidth(), getWinHeight());
170 #ifdef G4DEBUG_VIS_OGL
171 printf(
"G4OpenGLWtViewer::ComputeView First ProcessView ok\n");
173 HaloingSecondPass ();
186 #ifdef G4DEBUG_VIS_OGL
187 printf(
"G4OpenGLWtViewer::ComputeView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",getWinWidth(), getWinHeight());
189 fHasToRepaint =
true;
195 void G4OpenGLImmediateWtViewer::resizeGL(
199 #ifdef G4DEBUG_VIS_OGL
200 printf(
"G4OpenGLImmediateWtViewer resizeGL %d %d\n",width,height);
202 G4OpenGLWtViewer::resizeGL(width,height);
205 glViewport(0, 0, width, height);
209 proj.perspective(45, ((
double)width)/height, 1, 40);
210 glUniformMatrix4(pMatrixUniform_, proj);
215 void G4OpenGLImmediateWtViewer::paintGL() {
217 glClearColor(0.1234, 0.1234, 0.1234, 0.1234);
222 if (!fReadyToPaint) {
226 if ((getWinWidth() == 0) && (getWinHeight() == 0)) {
231 if ( !fHasToRepaint) {
235 sw =
width().value();
236 sh = height().value();
241 if ((getWinWidth() == sw) &&(getWinHeight() == sh)) {
244 }
else if ((sw == 0) && (sh == 0)) {
245 if (((getWinWidth() ==
width().
value())) &&(getWinHeight() == height().
value())) {
250 #ifdef G4DEBUG_VIS_OGL
251 printf(
"G4OpenGLImmediateWtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV ready %d\n",fReadyToPaint);
261 fHasToRepaint =
false;
263 #ifdef G4DEBUG_VIS_OGL
264 printf(
"G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ready %d\n\n\n",fReadyToPaint);
266 fIsRepainting =
false;
268 glClearColor(0.1234, 0.1234, 0.1234, 0.1234);
272 void G4OpenGLImmediateWtViewer::mousePressEvent(Wt::WMouseEvent *event)
275 G4MousePressEvent(event);
278 void G4OpenGLImmediateWtViewer::keyPressEvent (Wt::WKeyEvent *event)
280 G4keyPressEvent(event);
295 void G4OpenGLImmediateWtViewer::mouseDoubleClickEvent(Wt::WMouseEvent *)
297 G4MouseDoubleClickEvent();
301 void G4OpenGLImmediateWtViewer::mouseReleaseEvent(Wt::WMouseEvent )
303 G4MouseReleaseEvent();
307 void G4OpenGLImmediateWtViewer::mouseMoveEvent(Wt::WMouseEvent *event)
309 G4MouseMoveEvent(event);
320 void G4OpenGLImmediateWtViewer::paintEvent(Wt::WPaintDevice * ) {
321 if ( fHasToRepaint) {
328 void G4OpenGLImmediateWtViewer::FinishView()
330 #ifdef G4DEBUG_VIS_OGL
331 printf(
"G4OpenGLWtViewer::FinishView() \n");
340 void G4OpenGLImmediateWtViewer::SetView () {
342 if (!fSceneHandler.GetScene()) {
389 #ifdef G4DEBUG_VIS_OGL
390 printf(
"G4OpenGLWtViewer::SetView() resize viewport to %d %d\n",getWinWidth(),getWinHeight());
392 glViewport(0, 0, getWinWidth(),getWinHeight());
459 const G4Planes& cutaways = fVP.GetCutawayPlanes();
460 size_t nPlanes = cutaways.size();
461 if (fVP.IsCutaway() &&
465 a[0] = cutaways[0].a();
466 a[1] = cutaways[0].b();
467 a[2] = cutaways[0].c();
468 a[3] = cutaways[0].d();
472 a[0] = cutaways[1].a();
473 a[1] = cutaways[1].b();
474 a[2] = cutaways[1].c();
475 a[3] = cutaways[1].d();
480 a[0] = cutaways[2].a();
481 a[1] = cutaways[2].b();
482 a[2] = cutaways[2].c();
483 a[3] = cutaways[2].d();
494 background = fVP.GetBackgroundColour ();
499 void G4OpenGLImmediateWtViewer::popMatrix() {
502 void G4OpenGLImmediateWtViewer::pushMatrix() {
505 void G4OpenGLImmediateWtViewer::multMatrixd(
const GLdouble* ) {
509 void G4OpenGLImmediateWtViewer::loadIdentity() {
510 mMatrix.setToIdentity ();
514 void G4OpenGLImmediateWtViewer::setMatrixUniforms() {
524 void G4OpenGLImmediateWtViewer::wtDrawArrays(GLenum mode,
int first,
int nPoints, std::vector<double> a_vertices){
525 std::vector<double> data2;
526 for (
int a=0; a< nPoints*3; a+=3) {
527 data2.push_back(a_vertices[a]);
528 data2.push_back(a_vertices[a+1]);
529 data2.push_back(a_vertices[a+2]);
540 Buffer objBuffer_2 = glCreateBuffer();
542 VBO_Buffer.push_back(objBuffer_2);
545 glBindBuffer(GL_ARRAY_BUFFER, objBuffer_2);
548 glBufferDatafv(GL_ARRAY_BUFFER, data2.begin(), data2.end(), GL_STATIC_DRAW);
554 glBindBuffer(GL_ARRAY_BUFFER, objBuffer_2);
557 vertexAttribPointer(vertexPositionAttribute_,
568 glDrawArrays(mode, first, data2.size()/6);
572 void G4OpenGLImmediateWtViewer::ShowView (
577 #ifdef G4DEBUG_VIS_OGL
578 printf(
"G4OpenGLImmediateWtViewer ShowView\n");
585 void G4OpenGLImmediateWtViewer::updateWWidget() {
586 #ifdef G4DEBUG_VIS_OGL
587 printf(
"G4OpenGLImmediateWtViewer updateWWidget\n");
591 repaintGL(PAINT_GL | RESIZE_GL);
593 fHasToRepaint=
false;
594 #ifdef G4DEBUG_VIS_OGL
595 printf(
"G4OpenGLImmediateWtViewer updateWWidget END\n");
599 void G4OpenGLImmediateWtViewer::drawScene()
602 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
608 glUniformMatrix4(cMatrixUniform_, jsMatrix_);
611 Wt::WMatrix4x4 modelMatrix;
612 glUniformMatrix4(mvMatrixUniform_, modelMatrix);
623 glUniformMatrix4(nMatrixUniform_, (jsMatrix_ * modelMatrix).inverted().transposed());
640 std::vector<double> vertices;
641 vertices.push_back(0);
642 vertices.push_back(0);
643 vertices.push_back(0);
644 vertices.push_back(10.);
645 vertices.push_back(0);
646 vertices.push_back(0);
647 vertices.push_back(0);
648 vertices.push_back(0);
649 vertices.push_back(0);
650 vertices.push_back(0);
651 vertices.push_back(10.);
652 vertices.push_back(0);
653 vertices.push_back(0);
654 vertices.push_back(0);
655 vertices.push_back(0);
656 vertices.push_back(0);
657 vertices.push_back(0);
658 vertices.push_back(10.);
659 wtDrawArrays(GL_LINES,0,6,vertices);
661 #ifdef G4DEBUG_VIS_OGL
662 printf(
"G4OpenGLWtViewer drawScene Call ComputeView\n");
std::vector< G4Plane3D > G4Planes
const XML_Char int const XML_Char * value
printf("%d Experimental points found\n", nlines)