[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 | // |
---|
[593] | 27 | // $Id: G4OpenGLImmediateQtViewer.cc,v 1.1 2007/09/28 14:44:13 lgarnier Exp $ |
---|
| 28 | // GEANT4 tag $Name: $ |
---|
[531] | 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" |
---|
[564] | 37 | #include "G4VisManager.hh" |
---|
[531] | 38 | |
---|
| 39 | #include "G4ios.hh" |
---|
| 40 | |
---|
[533] | 41 | G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer |
---|
[531] | 42 | (G4OpenGLImmediateSceneHandler& sceneHandler, |
---|
| 43 | const G4String& name): |
---|
[550] | 44 | G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name), |
---|
| 45 | G4OpenGLViewer (sceneHandler), |
---|
| 46 | G4OpenGLQtViewer (sceneHandler), |
---|
| 47 | G4OpenGLImmediateViewer (sceneHandler), |
---|
| 48 | QGLWidget() // FIXME : gerer le pb du parent ! |
---|
| 49 | { |
---|
[557] | 50 | nbPaint =0; |
---|
[531] | 51 | if (fViewId < 0) return; // In case error in base class instantiation. |
---|
| 52 | } |
---|
| 53 | |
---|
[551] | 54 | G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() { |
---|
| 55 | printf("GLWidget::~GLWidget \n"); |
---|
| 56 | makeCurrent(); |
---|
| 57 | printf("GLWidget::~GLWidget END\n"); |
---|
| 58 | } |
---|
| 59 | |
---|
[543] | 60 | void G4OpenGLImmediateQtViewer::Initialise() { |
---|
[551] | 61 | printf("GLWidget::Initialise \n"); |
---|
[552] | 62 | printf("readyToPaint = false \n"); |
---|
| 63 | readyToPaint = false; |
---|
[564] | 64 | CreateGLQtContext (); |
---|
| 65 | printf("G4OpenGLImmediateQtViewer::Initialise () 2\n"); |
---|
[541] | 66 | |
---|
[539] | 67 | CreateMainWindow (this); |
---|
[543] | 68 | printf("G4OpenGLImmediateQtViewer::Initialise () 3\n"); |
---|
[551] | 69 | |
---|
[564] | 70 | CreateFontLists (); // FIXME Does nothing! |
---|
| 71 | |
---|
[551] | 72 | printf("readyToPaint = true \n"); |
---|
[552] | 73 | readyToPaint = true; |
---|
[564] | 74 | |
---|
[557] | 75 | // First Draw |
---|
[564] | 76 | SetView(); |
---|
| 77 | printf(" ClearView\n"); |
---|
| 78 | ClearView (); //ok, put the background correct |
---|
| 79 | ShowView(); |
---|
| 80 | FinishView(); |
---|
[550] | 81 | } |
---|
| 82 | |
---|
[551] | 83 | void G4OpenGLImmediateQtViewer::initializeGL () { |
---|
[550] | 84 | |
---|
[554] | 85 | InitializeGLView (); |
---|
[550] | 86 | |
---|
[554] | 87 | printf("G4OpenGLImmediateQtViewer::InitialiseGL () 1\n"); |
---|
[531] | 88 | |
---|
[564] | 89 | // If a double buffer context has been forced upon us, ignore the |
---|
| 90 | // back buffer for this OpenGLImmediate view. |
---|
| 91 | glDrawBuffer (GL_FRONT); // FIXME : Ne marche pas avec cette ligne, mais affiche le run correctement... |
---|
[554] | 92 | // clear the buffers and window. |
---|
[555] | 93 | ClearView (); |
---|
| 94 | // printf("G4OpenGLImmediateQtViewer::InitialiseGL () 2\n"); |
---|
| 95 | FinishView (); |
---|
[564] | 96 | |
---|
[531] | 97 | |
---|
[541] | 98 | |
---|
[554] | 99 | glDepthFunc (GL_LEQUAL); |
---|
| 100 | glDepthMask (GL_TRUE); |
---|
[551] | 101 | |
---|
[554] | 102 | printf("G4OpenGLImmediateQtViewer::InitialiseGL -------------------------------------------------------------------------------------\n"); |
---|
[531] | 103 | } |
---|
| 104 | |
---|
[543] | 105 | |
---|
[533] | 106 | void G4OpenGLImmediateQtViewer::DrawView () { |
---|
[531] | 107 | |
---|
[542] | 108 | printf("G4OpenGLImmediateQtViewer::DrawView %d %d VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n",WinSize_x, WinSize_y); |
---|
[553] | 109 | // If a double buffer context has been forced upon us, ignore the |
---|
| 110 | // back buffer for this OpenGLImmediate view. |
---|
[564] | 111 | glDrawBuffer (GL_FRONT); |
---|
[552] | 112 | |
---|
[553] | 113 | G4ViewParameters::DrawingStyle style = GetViewParameters().GetDrawingStyle(); |
---|
[552] | 114 | |
---|
[553] | 115 | //Make sure current viewer is attached and clean... |
---|
| 116 | //Qt version needed |
---|
| 117 | glViewport (0, 0, WinSize_x, WinSize_y); |
---|
[552] | 118 | |
---|
[553] | 119 | if(style!=G4ViewParameters::hlr && |
---|
| 120 | haloing_enabled) { |
---|
[564] | 121 | printf("G4OpenGLImmediateQtViewer::DrawView DANS LE IF\n"); |
---|
[552] | 122 | |
---|
[553] | 123 | HaloingFirstPass (); |
---|
| 124 | NeedKernelVisit (); |
---|
| 125 | ProcessView (); |
---|
| 126 | glFlush (); |
---|
[552] | 127 | |
---|
[553] | 128 | HaloingSecondPass (); |
---|
[552] | 129 | |
---|
[553] | 130 | } |
---|
[552] | 131 | |
---|
[553] | 132 | NeedKernelVisit (); // Always need to visit G4 kernel. |
---|
| 133 | ProcessView (); |
---|
| 134 | FinishView (); |
---|
[564] | 135 | printf("G4OpenGLImmediateQtViewer::DrawView %d %d ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n",WinSize_x, WinSize_y); |
---|
[559] | 136 | readyToPaint = false; |
---|
[552] | 137 | } |
---|
| 138 | |
---|
| 139 | |
---|
[531] | 140 | ////////////////////////////////////////////////////////////////////////////// |
---|
[533] | 141 | void G4OpenGLImmediateQtViewer::FinishView ( |
---|
[531] | 142 | ) |
---|
| 143 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 144 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 145 | { |
---|
[542] | 146 | printf("G4OpenGLImmediateQtViewer::FinishView VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV\n"); |
---|
[531] | 147 | |
---|
[554] | 148 | glFlush (); |
---|
[542] | 149 | printf("G4OpenGLImmediateQtViewer::FinishView ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[531] | 150 | |
---|
| 151 | } |
---|
| 152 | |
---|
[539] | 153 | |
---|
[564] | 154 | /** |
---|
| 155 | - Lors du resize de la fenetre, on doit non pas redessiner le detecteur, mais aussi les evenements |
---|
| 156 | */ |
---|
[539] | 157 | void G4OpenGLImmediateQtViewer::resizeGL( |
---|
| 158 | int width |
---|
| 159 | ,int height) |
---|
[564] | 160 | { |
---|
[553] | 161 | int side = qMin(width, height); |
---|
| 162 | glViewport((width - side) / 2, (height - side) / 2, side, side); |
---|
| 163 | glMatrixMode(GL_PROJECTION); |
---|
| 164 | glLoadIdentity(); |
---|
| 165 | glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); |
---|
| 166 | glMatrixMode(GL_MODELVIEW); |
---|
| 167 | printf("G4OpenGLImmediateQtViewer::resizeGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n"); |
---|
[539] | 168 | } |
---|
| 169 | |
---|
[559] | 170 | |
---|
[539] | 171 | void G4OpenGLImmediateQtViewer::paintGL() |
---|
| 172 | { |
---|
[564] | 173 | if (!readyToPaint) { |
---|
| 174 | readyToPaint= true; |
---|
[552] | 175 | return; |
---|
[564] | 176 | } |
---|
[559] | 177 | // DO NOT RESIZE IF SIZE HAS NOT CHANGE |
---|
| 178 | if (((WinSize_x == (G4int)width())) &&(WinSize_y == (G4int) height())) { |
---|
| 179 | return; |
---|
| 180 | } |
---|
[557] | 181 | nbPaint++; |
---|
[564] | 182 | printf("\n\nG4OpenGLImmediateQtViewer::paintGL VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV %d ready %d\n",nbPaint,readyToPaint); |
---|
[553] | 183 | WinSize_x = (G4int) width(); |
---|
| 184 | WinSize_y = (G4int) height(); |
---|
[541] | 185 | |
---|
[556] | 186 | glViewport (0, 0, width(), height()); |
---|
[541] | 187 | |
---|
[556] | 188 | SetView(); |
---|
[551] | 189 | // // printf("before ClearView\n"); |
---|
[555] | 190 | printf(" ClearView\n"); |
---|
[564] | 191 | |
---|
| 192 | ClearView (); //ok, put the background correct |
---|
| 193 | DrawView(); |
---|
[559] | 194 | readyToPaint = true; // could be set to false by DrawView |
---|
| 195 | |
---|
[543] | 196 | |
---|
[564] | 197 | printf("G4OpenGLImmediateQtViewer::paintGL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ %d ready %d\n\n\n",nbPaint,readyToPaint); |
---|
[539] | 198 | } |
---|
[551] | 199 | |
---|
[564] | 200 | void G4OpenGLImmediateQtViewer::updateQWidget() { |
---|
| 201 | updateGL(); |
---|
| 202 | } |
---|
[551] | 203 | |
---|
[531] | 204 | #endif |
---|