source: trunk/source/visualization/OpenGL/src/G4OpenGLImmediateSceneHandler.cc@ 1121

Last change on this file since 1121 was 1049, checked in by garnier, 17 years ago

update pas dans CVS

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