Geant4-11
G4OpenGLImmediateSceneHandler.cc
Go to the documentation of this file.
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//
28//
29// Andrew Walkden 10th February 1997
30// OpenGL immediate scene - draws immediately to buffer
31// (saving space on server).
32
34
35#include "G4OpenGLViewer.hh"
37#include "G4Polyline.hh"
38#include "G4Polymarker.hh"
39#include "G4Text.hh"
40#include "G4Circle.hh"
41#include "G4Square.hh"
42#include "G4Polyhedron.hh"
43#include "G4AttHolder.hh"
44
45#include <typeinfo>
46
48(G4VGraphicsSystem& system,const G4String& name):
49 G4OpenGLSceneHandler (system, fSceneIdCount++, name)
50{}
51
53{}
54
55#include <iomanip>
56
58{
59 return AddPrimitivePreambleInternal(visible, true, false);
60}
62{
63 return AddPrimitivePreambleInternal(visible, false, true);
64}
66{
67 return AddPrimitivePreambleInternal(visible, false, false);
68}
69
71{
72 // Get applicable vis attributes for all primitives.
74 const G4Colour& c = GetColour ();
75 G4double opacity = c.GetAlpha ();
76
77 G4bool transparency_enabled = true;
78 G4bool isMarkerNotHidden = true;
79 G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
80 if (pViewer) {
81 transparency_enabled = pViewer->transparency_enabled;
82 isMarkerNotHidden = pViewer->fVP.IsMarkerNotHidden();
83 }
84
85 G4bool isMarkerOrPolyline = isMarker || isPolyline;
86 G4bool treatAsTransparent = transparency_enabled && opacity < 1.;
87 G4bool treatAsNotHidden = isMarkerNotHidden && (isMarker || isPolyline);
88
89 if (fProcessing2D) glDisable (GL_DEPTH_TEST);
90 else {
91 if (isMarkerOrPolyline && isMarkerNotHidden)
92 glDisable (GL_DEPTH_TEST);
93 else {glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);}
94 }
95
97
98 // Ensure transparent objects are drawn opaque ones and before
99 // non-hidden markers. The problem of blending/transparency/alpha
100 // is quite a tricky one - see History of opengl-V07-01-01/2/3.
102 // First pass...
103 if (treatAsTransparent) { // Request pass for transparent objects...
105 }
106 if (treatAsNotHidden) { // Request pass for non-hidden markers...
108 }
109 // On first pass, transparent objects and non-hidden markers are not drawn...
110 if (treatAsTransparent || treatAsNotHidden) {
111 return false;
112 }
113 }
114
115 // On second pass, only transparent objects are drawn...
117 if (!treatAsTransparent) {
118 return false;
119 }
120 }
121
122 // On third pass, only non-hidden markers are drawn...
124 if (!treatAsNotHidden) {
125 return false;
126 }
127 }
128 } // fThreePassCapable
129
130 // Loads G4Atts for picking...
132 glLoadName(++fPickName);
133 G4AttHolder* holder = new G4AttHolder;
134 LoadAtts(visible, holder);
135 fPickMap[fPickName] = holder;
136 }
137
138 if (transparency_enabled) {
139 glColor4d(c.GetRed(),c.GetGreen(),c.GetBlue(),c.GetAlpha());
140 } else {
141 glColor3d(c.GetRed(),c.GetGreen(),c.GetBlue());
142 }
143
144 return true;
145}
146
148{
149 G4bool furtherprocessing = AddPrimitivePreamble(polyline);
150 if (furtherprocessing) {
152 }
153}
154
156{
157 G4bool furtherprocessing = AddPrimitivePreamble(polymarker);
158 if (furtherprocessing) {
160 }
161}
162
164{
165 // Note: colour is still handled in
166 // G4OpenGLSceneHandler::AddPrimitive(const G4Text&).
167 G4bool furtherprocessing = AddPrimitivePreamble(text);
168 if (furtherprocessing) {
170 }
171}
172
174{
175 G4bool furtherprocessing = AddPrimitivePreamble(circle);
176 if (furtherprocessing) {
178 }
179}
180
182{
183 G4bool furtherprocessing = AddPrimitivePreamble(square);
184 if (furtherprocessing) {
186 }
187}
188
190{
191 // Note: colour is still handled in
192 // G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&).
193 G4bool furtherprocessing = AddPrimitivePreamble(polyhedron);
194 if (furtherprocessing) {
196 }
197}
198
200(const G4Transform3D& objectTransformation)
201{
202 G4OpenGLSceneHandler::BeginPrimitives (objectTransformation);
203
204 G4OpenGLTransform3D oglt (objectTransformation);
205
206 glPushMatrix();
207
208 /*************************** Check matrix.
209 const GLdouble* m = oglt.GetGLMatrix ();
210 G4cout << "G4OpenGLTransform3D matrix:";
211 for (int i = 0; i < 16; i++) {
212 if ((i % 4) == 0) G4cout << '\n';
213 G4cout << std::setw (15) << m[i];
214 }
215 G4cout << G4endl;
216 *****************************************/
217
218 glMultMatrixd (oglt.GetGLMatrix ());
219}
220
222{
223 glPopMatrix();
224
225 // See all primitives immediately... At least soon...
226 ScaledFlush();
227
229}
230
232(const G4Transform3D& objectTransformation)
233{
234 G4OpenGLSceneHandler::BeginPrimitives2D(objectTransformation);
235
236 // Push current 3D world matrices and load identity to define screen
237 // coordinates...
238 glMatrixMode (GL_PROJECTION);
239 glPushMatrix();
240 glLoadIdentity();
241 G4OpenGLViewer* pViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
242 if (pViewer) {
243 pViewer->g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
244 }
245 glMatrixMode (GL_MODELVIEW);
246 glPushMatrix();
247 glLoadIdentity();
248 G4OpenGLTransform3D oglt (objectTransformation);
249 glMultMatrixd (oglt.GetGLMatrix ());
250 glDisable(GL_DEPTH_TEST); // But see parent scene handler!! In
251#ifndef G4OPENGL_VERSION_2
252 glDisable (GL_LIGHTING); // some cases, we need to re-iterate this.
253#endif
254}
255
257{
258 // Pop current 3D world matrices back again...
259 glMatrixMode (GL_PROJECTION);
260 glPopMatrix();
261 glMatrixMode (GL_MODELVIEW);
262 glPopMatrix();
263
264 // See all primitives immediately... At least soon...
265 ScaledFlush();
266
268}
269
272}
273
276}
277
279{
280 // Nothing to do except redraw the scene ready for the next event.
281 if (fpViewer) {
282 fpViewer -> SetView ();
283 fpViewer -> ClearView ();
284 fpViewer -> DrawView ();
285 }
286}
287
#define G4OPENGL_FLT_BIG
Definition: G4OpenGL.hh:89
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4double GetBlue() const
Definition: G4Colour.hh:154
G4double GetAlpha() const
Definition: G4Colour.hh:155
G4double GetRed() const
Definition: G4Colour.hh:152
G4double GetGreen() const
Definition: G4Colour.hh:153
void BeginPrimitives(const G4Transform3D &objectTransformation)
void BeginPrimitives2D(const G4Transform3D &objectTransformation)
bool AddPrimitivePreambleInternal(const G4Visible &visible, bool isMarker, bool isPolyline)
G4bool AddPrimitivePreamble(const G4VMarker &visible)
G4OpenGLImmediateSceneHandler(G4VGraphicsSystem &system, const G4String &name)
virtual void BeginPrimitives2D(const G4Transform3D &objectTransformation)
void AddPrimitive(const G4Polyline &)
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
std::map< GLuint, G4AttHolder * > fPickMap
const GLdouble * GetGLMatrix()
G4bool transparency_enabled
void g4GlOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far)
Definition: G4Text.hh:72
virtual void BeginModeling()
void LoadAtts(const G4Visible &, G4AttHolder *)
const G4Colour & GetColour()
virtual void EndModeling()
G4VViewer * fpViewer
const G4VisAttributes * fpVisAttribs
const G4VisAttributes * GetApplicableVisAttributes(const G4VisAttributes *) const
const G4ViewParameters & GetViewParameters() const
G4ViewParameters fVP
Definition: G4VViewer.hh:219
G4bool IsMarkerNotHidden() const
G4bool IsPicking() const
const G4VisAttributes * GetVisAttributes() const
const char * name(G4int ptype)