| [531] | 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| [533] | 27 | // $Id: G4OpenGLImmediateQtViewer.cc,v 1.16 2007/06/25 16:38:13 $
|
|---|
| [531] | 28 | // GEANT4 tag $Name: geant4-08-02-patch-01 $
|
|---|
| 29 | //
|
|---|
| [539] | 30 | //
|
|---|
| [533] | 31 | // Class G4OpenGLImmediateQtViewer : a class derived from G4OpenGLQtViewer and
|
|---|
| [531] | 32 | // G4OpenGLImmediateViewer.
|
|---|
| 33 |
|
|---|
| [533] | 34 | #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
|
|---|
| [531] | 35 |
|
|---|
| [533] | 36 | #include "G4OpenGLImmediateQtViewer.hh"
|
|---|
| [531] | 37 |
|
|---|
| 38 | #include "G4ios.hh"
|
|---|
| 39 |
|
|---|
| [533] | 40 | G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
|
|---|
| [531] | 41 | (G4OpenGLImmediateSceneHandler& sceneHandler,
|
|---|
| 42 | const G4String& name):
|
|---|
| [550] | 43 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
|
|---|
| 44 | G4OpenGLViewer (sceneHandler),
|
|---|
| 45 | G4OpenGLQtViewer (sceneHandler),
|
|---|
| 46 | G4OpenGLImmediateViewer (sceneHandler),
|
|---|
| 47 | QGLWidget() // FIXME : gerer le pb du parent !
|
|---|
| 48 | {
|
|---|
| [557] | 49 | nbPaint =0;
|
|---|
| [531] | 50 | if (fViewId < 0) return; // In case error in base class instantiation.
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| [551] | 53 | G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {
|
|---|
| 54 | printf("GLWidget::~GLWidget \n");
|
|---|
| 55 | makeCurrent();
|
|---|
| 56 | printf("GLWidget::~GLWidget END\n");
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| [543] | 59 | void G4OpenGLImmediateQtViewer::Initialise() {
|
|---|
| [551] | 60 | printf("GLWidget::Initialise \n");
|
|---|
| [552] | 61 | printf("readyToPaint = false \n");
|
|---|
| 62 | readyToPaint = false;
|
|---|
| [551] | 63 | // printf("G4OpenGLImmediateQtViewer::Initialise () 1\n");
|
|---|
| 64 | // CreateGLQtContext ();
|
|---|
| [543] | 65 | printf("G4OpenGLImmediateQtViewer::Initialise () 2\n");
|
|---|
| [541] | 66 |
|
|---|
| [539] | 67 | CreateMainWindow (this);
|
|---|
| [543] | 68 | printf("G4OpenGLImmediateQtViewer::Initialise () 3\n");
|
|---|
| [551] | 69 |
|
|---|
| 70 | // CreateFontLists (); // FIXME Does nothing!
|
|---|
| 71 |
|
|---|
| 72 | printf("readyToPaint = true \n");
|
|---|
| [552] | 73 | readyToPaint = true;
|
|---|
| [557] | 74 |
|
|---|
| 75 | // First Draw
|
|---|
| 76 | SetView();
|
|---|
| 77 | // // printf("before ClearView\n");
|
|---|
| 78 | // // makeCurrent();
|
|---|
| 79 | // // for (int a=0;a<100000000;a++) {b = b/3.1456;}
|
|---|
| 80 | printf(" ClearView\n");
|
|---|
| 81 | ClearView (); //ok, put the background correct
|
|---|
| 82 | // DrawView2();
|
|---|
| 83 | ShowView();
|
|---|
| 84 | // printf("before ClearView\n");
|
|---|
| 85 | // ClearView (); //ok, put the background correct
|
|---|
| 86 | // // FIXME
|
|---|
| 87 | FinishView();
|
|---|
| [550] | 88 | }
|
|---|
| 89 |
|
|---|
| [551] | 90 | void G4OpenGLImmediateQtViewer::initializeGL () {
|
|---|
| [550] | 91 |
|
|---|
| [554] | 92 | InitializeGLView ();
|
|---|
| [550] | 93 |
|
|---|
| [554] | 94 | printf("G4OpenGLImmediateQtViewer::InitialiseGL () 1\n");
|
|---|
| [531] | 95 |
|
|---|
| [556] | 96 | // glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement...
|
|---|
| [554] | 97 | // clear the buffers and window.
|
|---|
| [555] | 98 | ClearView ();
|
|---|
| 99 | // printf("G4OpenGLImmediateQtViewer::InitialiseGL () 2\n");
|
|---|
| 100 | FinishView ();
|
|---|
| [531] | 101 |
|
|---|
| [554] | 102 | // If a double buffer context has been forced upon us, ignore the
|
|---|
| 103 | // back buffer for this OpenGLImmediate view.
|
|---|
| [541] | 104 |
|
|---|
| [555] | 105 |
|
|---|
| [554] | 106 | glDepthFunc (GL_LEQUAL);
|
|---|
| 107 | glDepthMask (GL_TRUE);
|
|---|
| [551] | 108 |
|
|---|
| [554] | 109 | printf("G4OpenGLImmediateQtViewer::InitialiseGL -------------------------------------------------------------------------------------\n");
|
|---|
| [531] | 110 | }
|
|---|
| 111 |
|
|---|
| [543] | 112 |
|
|---|
| [533] | 113 | void G4OpenGLImmediateQtViewer::DrawView () {
|
|---|
| [531] | 114 |
|
|---|
| [542] | 115 | printf("G4OpenGLImmediateQtViewer::DrawView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
|
|---|
| [556] | 116 | // glDraw();
|
|---|
| 117 | DrawView2();
|
|---|
| [550] | 118 | printf("G4OpenGLImmediateQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
|
|---|
| [531] | 119 |
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| [552] | 122 | void G4OpenGLImmediateQtViewer::DrawView2 () {
|
|---|
| [539] | 123 |
|
|---|
| [552] | 124 | printf("G4OpenGLImmediateQtViewer::DrawView2 %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y);
|
|---|
| [553] | 125 | // If a double buffer context has been forced upon us, ignore the
|
|---|
| 126 | // back buffer for this OpenGLImmediate view.
|
|---|
| [556] | 127 | // glDrawBuffer (GL_FRONT);
|
|---|
| [552] | 128 |
|
|---|
| [553] | 129 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle();
|
|---|
| [552] | 130 |
|
|---|
| [553] | 131 | //Make sure current viewer is attached and clean...
|
|---|
| 132 | //Qt version needed
|
|---|
| 133 | //glXMakeCurrent (dpy, win, cx);
|
|---|
| 134 | glViewport (0, 0, WinSize_x, WinSize_y);
|
|---|
| [552] | 135 |
|
|---|
| [553] | 136 | if(style!=G4ViewParameters::hlr &&
|
|---|
| 137 | haloing_enabled) {
|
|---|
| [557] | 138 | printf("G4OpenGLImmediateQtViewer::DrawView2 DANS LE IF\n");
|
|---|
| [552] | 139 |
|
|---|
| [553] | 140 | HaloingFirstPass ();
|
|---|
| 141 | NeedKernelVisit ();
|
|---|
| 142 | ProcessView ();
|
|---|
| 143 | glFlush ();
|
|---|
| [552] | 144 |
|
|---|
| [553] | 145 | HaloingSecondPass ();
|
|---|
| [552] | 146 |
|
|---|
| [553] | 147 | }
|
|---|
| [552] | 148 |
|
|---|
| [553] | 149 | NeedKernelVisit (); // Always need to visit G4 kernel.
|
|---|
| 150 | ProcessView ();
|
|---|
| 151 | FinishView ();
|
|---|
| [552] | 152 | printf("G4OpenGLImmediateQtViewer::DrawView2 %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y);
|
|---|
| [559] | 153 | readyToPaint = false;
|
|---|
| [552] | 154 | }
|
|---|
| 155 |
|
|---|
| 156 |
|
|---|
| [531] | 157 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| [533] | 158 | void G4OpenGLImmediateQtViewer::FinishView (
|
|---|
| [531] | 159 | )
|
|---|
| 160 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 161 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 162 | {
|
|---|
| [542] | 163 | printf("G4OpenGLImmediateQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n");
|
|---|
| [551] | 164 | // // if(!fHDC) return;
|
|---|
| [531] | 165 |
|
|---|
| [554] | 166 | glFlush ();
|
|---|
| [542] | 167 | printf("G4OpenGLImmediateQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| [531] | 168 |
|
|---|
| 169 | // Empty the Windows message queue :
|
|---|
| [536] | 170 | // MSG event;
|
|---|
| 171 | // while ( ::PeekMessage(&event, NULL, 0, 0, PM_REMOVE) ) {
|
|---|
| 172 | // ::TranslateMessage(&event);
|
|---|
| 173 | // ::DispatchMessage (&event);
|
|---|
| 174 | // }
|
|---|
| [531] | 175 | }
|
|---|
| 176 |
|
|---|
| [539] | 177 |
|
|---|
| 178 | void G4OpenGLImmediateQtViewer::resizeGL(
|
|---|
| 179 | int width
|
|---|
| 180 | ,int height)
|
|---|
| 181 | {
|
|---|
| [553] | 182 | printf("G4OpenGLImmediateQtViewer::resizeGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV \n");
|
|---|
| [551] | 183 |
|
|---|
| [553] | 184 | int side = qMin(width, height);
|
|---|
| 185 | glViewport((width - side) / 2, (height - side) / 2, side, side);
|
|---|
| 186 | glMatrixMode(GL_PROJECTION);
|
|---|
| 187 | glLoadIdentity();
|
|---|
| 188 | glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
|
|---|
| 189 | glMatrixMode(GL_MODELVIEW);
|
|---|
| [551] | 190 |
|
|---|
| [553] | 191 | printf("G4OpenGLImmediateQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| [539] | 192 | }
|
|---|
| 193 |
|
|---|
| [559] | 194 | void G4OpenGLImmediateQtViewer::paintEvent (
|
|---|
| 195 | QPaintEvent * event
|
|---|
| 196 | )
|
|---|
| 197 | {
|
|---|
| 198 | // printf("G4OpenGLImmediateQtViewer::paintEvent VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV \n");
|
|---|
| 199 | // printf("Type of Event %d \n",event->type());
|
|---|
| 200 | // printf("G4OpenGLImmediateQtViewer::paintEvent ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
|
|---|
| 201 | return paintGL();
|
|---|
| 202 | }
|
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| [539] | 205 | void G4OpenGLImmediateQtViewer::paintGL()
|
|---|
| 206 | {
|
|---|
| [552] | 207 | if (!readyToPaint)
|
|---|
| 208 | return;
|
|---|
| [559] | 209 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE
|
|---|
| 210 | if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) {
|
|---|
| 211 | return;
|
|---|
| 212 | }
|
|---|
| [557] | 213 | nbPaint++;
|
|---|
| 214 | printf("\n\nG4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d\n",nbPaint);
|
|---|
| [553] | 215 | WinSize_x = (G4int) width();
|
|---|
| 216 | WinSize_y = (G4int) height();
|
|---|
| [541] | 217 |
|
|---|
| [556] | 218 | glViewport (0, 0, width(), height());
|
|---|
| [541] | 219 |
|
|---|
| [556] | 220 | SetView();
|
|---|
| [551] | 221 | // // printf("before ClearView\n");
|
|---|
| 222 | // // makeCurrent();
|
|---|
| 223 | // // for (int a=0;a<100000000;a++) {b = b/3.1456;}
|
|---|
| [555] | 224 | printf(" ClearView\n");
|
|---|
| [557] | 225 | // ClearView (); //ok, put the background correct
|
|---|
| [553] | 226 | DrawView2();
|
|---|
| [559] | 227 | readyToPaint = true; // could be set to false by DrawView
|
|---|
| 228 |
|
|---|
| [557] | 229 | // INIT ok RUN nok ShowView();
|
|---|
| [555] | 230 | // printf("before ClearView\n");
|
|---|
| 231 | // ClearView (); //ok, put the background correct
|
|---|
| [551] | 232 | // // FIXME
|
|---|
| [557] | 233 | // INIT ok RUN nok FinishView();
|
|---|
| [551] | 234 | // // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|---|
| 235 | // // glLoadIdentity();
|
|---|
| 236 | // // glTranslated(0.0, 0.0, -10.0);
|
|---|
| [543] | 237 |
|
|---|
| [557] | 238 | printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n\n");
|
|---|
| [539] | 239 | }
|
|---|
| [551] | 240 |
|
|---|
| 241 |
|
|---|
| [531] | 242 | #endif
|
|---|