source: trunk/geant4/visualization/OpenGL/src/G4OpenGLImmediateSceneHandler.cc@ 781

Last change on this file since 781 was 754, checked in by garnier, 18 years ago

corrections pour Qt3 mises sous cvs

  • Property svn:mime-type set to text/cpp
File size: 8.1 KB
Line 
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: G4OpenGLImmediateSceneHandler.cc,v 1.29 2008/02/18 08:53:49 asaim Exp $
28// GEANT4 tag $Name: $
29//
30//
31// Andrew Walkden 10th February 1997
32// OpenGL immediate scene - draws immediately to buffer
33// (saving space on server).
34
35#ifdef G4VIS_BUILD_OPENGL_DRIVER
36
37// Included here - problems with HP compiler if not before other includes?
38#include "G4NURBS.hh"
39
40// Here follows a special for Mesa, the OpenGL emulator. Does not affect
41// other OpenGL's, as far as I'm aware. John Allison 18/9/96.
42#define CENTERLINE_CLPP /* CenterLine C++ workaround: */
43// Also seems to be required for HP's CC and AIX xlC, at least.
44
45#include "G4OpenGLImmediateSceneHandler.hh"
46
47#include "G4OpenGLTransform3D.hh"
48#include "G4Polyline.hh"
49#include "G4Polymarker.hh"
50#include "G4Text.hh"
51#include "G4Circle.hh"
52#include "G4Square.hh"
53#include "G4Scale.hh"
54#include "G4Polyhedron.hh"
55
56G4OpenGLImmediateSceneHandler::G4OpenGLImmediateSceneHandler
57(G4VGraphicsSystem& system,const G4String& name):
58 G4OpenGLSceneHandler (system, fSceneIdCount++, name)
59{}
60
61G4OpenGLImmediateSceneHandler::~G4OpenGLImmediateSceneHandler ()
62{}
63
64#include <iomanip>
65
66void G4OpenGLImmediateSceneHandler::AddPrimitivePreamble(const G4Visible& visible)
67{
68 if (fpViewer->GetViewParameters().IsPicking()) {
69 glLoadName(++fPickName);
70 fPickMap[fPickName] = 0;
71 }
72
73 const G4Colour& c = GetColour (visible);
74 glColor3d (c.GetRed (), c.GetGreen (), c.GetBlue ());
75}
76
77void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Polyline& polyline)
78{
79 AddPrimitivePreamble(polyline);
80 G4OpenGLSceneHandler::AddPrimitive(polyline);
81}
82
83void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
84{
85 AddPrimitivePreamble(polymarker);
86 G4OpenGLSceneHandler::AddPrimitive(polymarker);
87}
88
89void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Text& text)
90{
91 // Note: colour is still handled in
92 // G4OpenGLSceneHandler::AddPrimitive(const G4Text&).
93 AddPrimitivePreamble(text);
94 G4OpenGLSceneHandler::AddPrimitive(text);
95}
96
97void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Circle& circle)
98{
99 AddPrimitivePreamble(circle);
100 G4OpenGLSceneHandler::AddPrimitive(circle);
101}
102
103void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Square& square)
104{
105 AddPrimitivePreamble(square);
106 G4OpenGLSceneHandler::AddPrimitive(square);
107}
108
109void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Scale& scale)
110{
111 AddPrimitivePreamble(scale);
112 G4OpenGLSceneHandler::AddPrimitive(scale);
113}
114
115void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron)
116{
117 // Note: colour is still handled in
118 // G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&).
119 AddPrimitivePreamble(polyhedron);
120 G4OpenGLSceneHandler::AddPrimitive(polyhedron);
121}
122
123void G4OpenGLImmediateSceneHandler::AddPrimitive (const G4NURBS& nurbs)
124{
125 // Note: colour is still handled in
126 // G4OpenGLSceneHandler::AddPrimitive(const G4NURBS&).
127 AddPrimitivePreamble(nurbs);
128 G4OpenGLSceneHandler::AddPrimitive(nurbs);
129}
130
131void G4OpenGLImmediateSceneHandler::BeginPrimitives
132(const G4Transform3D& objectTransformation)
133{
134 G4OpenGLSceneHandler::BeginPrimitives (objectTransformation);
135
136 G4OpenGLTransform3D oglt (objectTransformation);
137
138 glPushMatrix();
139
140 /*************************** Check matrix.
141 const GLdouble* m = oglt.GetGLMatrix ();
142 G4cout << "G4OpenGLTransform3D matrix:";
143 for (int i = 0; i < 16; i++) {
144 if ((i % 4) == 0) G4cout << '\n';
145 G4cout << std::setw (15) << m[i];
146 }
147 G4cout << G4endl;
148 *****************************************/
149
150 glMultMatrixd (oglt.GetGLMatrix ());
151}
152
153void G4OpenGLImmediateSceneHandler::EndPrimitives ()
154{
155 glPopMatrix();
156
157 // See all primitives immediately...
158 glFlush ();
159
160 G4OpenGLSceneHandler::EndPrimitives ();
161}
162
163void G4OpenGLImmediateSceneHandler::BeginPrimitives2D
164(const G4Transform3D& objectTransformation)
165{
166 G4OpenGLSceneHandler::BeginPrimitives2D(objectTransformation);
167
168 // Push current 3D world matrices and load identity to define screen
169 // coordinates...
170 glMatrixMode (GL_PROJECTION);
171 glPushMatrix();
172 glLoadIdentity();
173////// glOrtho (-1., 1., -1., 1., -G4OPENGL_DBL_MAX, G4OPENGL_DBL_MAX);
174 glOrtho (-1., 1., -1., 1., -1., 1.);
175 glMatrixMode (GL_MODELVIEW);
176 glPushMatrix();
177 glLoadIdentity();
178 G4OpenGLTransform3D oglt (objectTransformation);
179 glMultMatrixd (oglt.GetGLMatrix ());
180}
181
182void G4OpenGLImmediateSceneHandler::EndPrimitives2D()
183{
184 // Pop current 3D world matrices back again...
185 glMatrixMode (GL_PROJECTION);
186 glPopMatrix();
187 glMatrixMode (GL_MODELVIEW);
188 glPopMatrix();
189
190 // See all primitives immediately...
191 glFlush ();
192
193 G4OpenGLSceneHandler::EndPrimitives2D ();
194}
195
196void G4OpenGLImmediateSceneHandler::BeginModeling () {
197 G4VSceneHandler::BeginModeling();
198}
199
200void G4OpenGLImmediateSceneHandler::EndModeling () {
201 G4VSceneHandler::EndModeling ();
202}
203
204void G4OpenGLImmediateSceneHandler::ClearTransientStore () {
205
206 G4VSceneHandler::ClearTransientStore ();
207
208 // Make sure screen corresponds to graphical database...
209 if (fpViewer) {
210 fpViewer -> SetView ();
211 fpViewer -> ClearView ();
212 fpViewer -> DrawView ();
213 }
214}
215
216void G4OpenGLImmediateSceneHandler::RequestPrimitives (const G4VSolid& solid)
217{
218 if (fReadyForTransients) {
219 // Always draw transient solids, e.g., hits represented as solids.
220 // (As we have no control over the order of drawing of transient
221 // objects, we cannot do anything about transparent ones, as
222 // below, so always draw them.)
223 G4VSceneHandler::RequestPrimitives (solid);
224 return;
225 }
226
227 // For non-transient (run-duration) objects, ensure transparent
228 // objects are drawn last. The problem of
229 // blending/transparency/alpha is quite a tricky one - see History
230 // of opengl-V07-01-01/2/3.
231 // Get vis attributes - pick up defaults if none.
232 const G4VisAttributes* pVA =
233 fpViewer -> GetApplicableVisAttributes(fpVisAttribs);
234 const G4Colour& c = pVA -> GetColour ();
235 G4double opacity = c.GetAlpha ();
236
237 if (!fSecondPass) {
238 G4bool transparency_enabled = true;
239 G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
240 if (pViewer) transparency_enabled = pViewer->transparency_enabled;
241 if (transparency_enabled && opacity < 1.) {
242 // On first pass, transparent objects are not drawn, but flag is set...
243 fSecondPassRequested = true;
244 return;
245 }
246 }
247
248 // On second pass, opaque objects are not drwan...
249 if (fSecondPass && opacity >= 1.) return;
250
251 // Else invoke base class method...
252 G4VSceneHandler::RequestPrimitives (solid);
253}
254
255G4int G4OpenGLImmediateSceneHandler::fSceneIdCount = 0;
256
257#endif
Note: See TracBrowser for help on using the repository browser.