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

Last change on this file since 908 was 877, checked in by garnier, 16 years ago

OpenGL Qt improvments. See History file

  • 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.30 2008/04/04 13:32:22 allison 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_FLT_BIG, G4OPENGL_FLT_BIG);
174  glMatrixMode (GL_MODELVIEW);
175  glPushMatrix();
176  glLoadIdentity();
177  G4OpenGLTransform3D oglt (objectTransformation);
178  glMultMatrixd (oglt.GetGLMatrix ());
179}
180
181void G4OpenGLImmediateSceneHandler::EndPrimitives2D()
182{
183  // Pop current 3D world matrices back again...
184  glMatrixMode (GL_PROJECTION);
185  glPopMatrix();
186  glMatrixMode (GL_MODELVIEW);
187  glPopMatrix();
188
189  // See all primitives immediately...
190  glFlush ();
191
192  G4OpenGLSceneHandler::EndPrimitives2D ();
193}
194
195void G4OpenGLImmediateSceneHandler::BeginModeling () {
196  G4VSceneHandler::BeginModeling();
197}
198
199void G4OpenGLImmediateSceneHandler::EndModeling () {
200  G4VSceneHandler::EndModeling ();
201}
202
203void G4OpenGLImmediateSceneHandler::ClearTransientStore () {
204
205  G4VSceneHandler::ClearTransientStore ();
206
207  // Make sure screen corresponds to graphical database...
208  if (fpViewer) {
209    fpViewer -> SetView ();
210    fpViewer -> ClearView ();
211    fpViewer -> DrawView ();
212  }
213}
214
215void G4OpenGLImmediateSceneHandler::RequestPrimitives (const G4VSolid& solid)
216{
217  if (fReadyForTransients) {
218    // Always draw transient solids, e.g., hits represented as solids.
219    // (As we have no control over the order of drawing of transient
220    // objects, we cannot do anything about transparent ones, as
221    // below, so always draw them.)
222    G4VSceneHandler::RequestPrimitives (solid);
223    return;
224  }
225
226  // For non-transient (run-duration) objects, ensure transparent
227  // objects are drawn last.  The problem of
228  // blending/transparency/alpha is quite a tricky one - see History
229  // of opengl-V07-01-01/2/3.
230  // Get vis attributes - pick up defaults if none.
231  const G4VisAttributes* pVA =
232    fpViewer -> GetApplicableVisAttributes(fpVisAttribs);
233  const G4Colour& c = pVA -> GetColour ();
234  G4double opacity = c.GetAlpha ();
235
236  if (!fSecondPass) {
237    G4bool transparency_enabled = true;
238    G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
239    if (pViewer) transparency_enabled = pViewer->transparency_enabled;
240    if (transparency_enabled && opacity < 1.) {
241      // On first pass, transparent objects are not drawn, but flag is set...
242      fSecondPassRequested = true;
243      return;
244    }
245  }
246
247  // On second pass, opaque objects are not drwan...
248  if (fSecondPass && opacity >= 1.) return;
249
250  // Else invoke base class method...
251  G4VSceneHandler::RequestPrimitives (solid);
252}
253
254G4int G4OpenGLImmediateSceneHandler::fSceneIdCount = 0;
255
256#endif
Note: See TracBrowser for help on using the repository browser.