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