Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLRnrCtx.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Matevz Tadel, Feb 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TString.h"
13
14#include "TGLRnrCtx.h"
15#include "TGLSceneInfo.h"
16#include "TGLSelectBuffer.h"
17#include "TGLIncludes.h"
18#include "TGLUtil.h"
19#include "TGLCamera.h"
20#include "TGLFontManager.h"
21#include "TGLContext.h"
22
23#include "TError.h"
24#include "TMathBase.h"
25#include "TMath.h"
26
27#include <list>
28#include <algorithm>
29#include <cassert>
30
31/** \class TGLRnrCtx
32\ingroup opengl
33The TGLRnrCtx class aggregates data for a given redering context as
34needed by various parts of the ROOT's OpenGL infrastructure. It
35serves as a connecting point between the steering part of the
36infrastructure (viewer, scene) and concrete rendering classes
37(logical, physical shape). It is just a data-holder, there is no
38functionality in it.
39
40Development notes:
41
42One RnrCtx is created by each viewer and it is just an extension of
43the viewer context that changes along the render
44descend. Separating this also has some abstract benefit of hiding
45viewer implementation from those that do not need to know it.
46
47Current scene / scene-info part is always initialized by viewer,
48scenes can assume they're ok.
49*/
50
52
53////////////////////////////////////////////////////////////////////////////////
54
56 fViewer (viewer),
57 fCamera (nullptr),
58 fSceneInfo (nullptr),
59
60 fViewerLOD (kLODUndef),
61 fSceneLOD (kLODUndef),
62 fCombiLOD (kLODUndef),
63 fShapeLOD (kLODUndef),
64 fShapePixSize (0),
65
66 fViewerStyle (kStyleUndef),
67 fSceneStyle (kStyleUndef),
68
69 fViewerWFLineW (0),
70 fSceneWFLineW (0),
71 fViewerOLLineW (0),
72 fSceneOLLineW (0),
73
74 fViewerClip (nullptr),
75 fSceneClip (nullptr),
76 fClip (nullptr),
77 fDrawPass (kPassUndef),
78
79 fStopwatch (),
80 fRenderTimeOut(0.0),
81 fIsRunning (kFALSE),
82 fHasTimedOut (kFALSE),
83
84 fHighlight (kFALSE), fHighlightOutline (kFALSE),
85 fSelection (kFALSE), fSecSelection (kFALSE),
86 fSelectTransparents (kIfNoOpaques),
87 fPickRadius (0),
88 fPickRectangle(nullptr),
89 fSelectBuffer (nullptr),
90
91 fColorSetStack(nullptr),
92 fRenderScale (1),
93
94 fEventKeySym (0),
95
96 fDLCaptureOpen (kFALSE),
97 fGLCtxIdentity (nullptr),
98 fQuadric (nullptr),
99
100 fGrabImage (kFALSE),
101 fGrabBuffer (-1),
102 fGrabbedImage (nullptr)
103{
104 // Constructor.
105
107 fColorSetStack->push_back(nullptr);
108
110 if (fViewer == nullptr)
111 {
112 // Assume external usage, initialize for highest quality.
116 }
117}
118
119////////////////////////////////////////////////////////////////////////////////
120/// Destructor.
121
123{
124 gluDeleteQuadric(fQuadric);
125 delete fPickRectangle;
126 delete fSelectBuffer;
127 delete fColorSetStack;
128}
129
130////////////////////////////////////////////////////////////////////////////////
131/// Return current scene (based on scene-info data).
132
134{
135 return fSceneInfo->GetScene();
136}
137
138////////////////////////////////////////////////////////////////////////////////
139/// Return current scene (based on scene-info data).
140
142{
143 return *fSceneInfo->GetScene();
144}
145
146/**************************************************************************/
147
148////////////////////////////////////////////////////////////////////////////////
149/// Returns true if current render-pass uses filled polygon style.
150
152{
154}
155
156
157/******************************************************************************/
158// Stopwatch
159/******************************************************************************/
160
161////////////////////////////////////////////////////////////////////////////////
162/// Start the stopwatch.
163
165{
166 if (fIsRunning)
167 return;
168
172}
173
174////////////////////////////////////////////////////////////////////////////////
175/// Stop the stopwatch.
176
178{
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Check if the stopwatch went beyond the render time limit.
185
187{
188 if (fHasTimedOut) return kTRUE;
191 return fHasTimedOut;
192}
193
194
195/******************************************************************************/
196// Selection & picking
197/******************************************************************************/
198
199////////////////////////////////////////////////////////////////////////////////
200/// Setup context for running selection.
201/// x and y are in window coordinates.
202
204{
207 fPickRadius = r;
209 fPickRectangle->Set(x, y, r, r);
210
211 glSelectBuffer(fSelectBuffer->GetBufSize(), fSelectBuffer->GetBuf());
212}
213
214////////////////////////////////////////////////////////////////////////////////
215/// End selection.
216
218{
221 fPickRadius = 0;
222 delete fPickRectangle; fPickRectangle = nullptr;
223
224 if (glResult < 0)
225 {
226 if (fSelectBuffer->CanGrow())
227 {
228 Warning("TGLRnrCtx::EndSelection",
229 "Select buffer size (%d) insufficient, doubling it.",
232 }
233 else
234 {
235 Warning("TGLRnrCtx::EndSelection",
236 "Select buffer size (%d) insufficient. This is maximum.",
238 }
239 }
240 fSelectBuffer->ProcessResult(glResult);
241}
242
243////////////////////////////////////////////////////////////////////////////////
244/// Return current pick rectangle. This is *zero* when
245/// selection is not set.
246
248{
249 return fPickRectangle;
250}
251
252////////////////////////////////////////////////////////////////////////////////
253/// Return pick radius. If selection is not active it returns 0.
254
256{
257 return fPickRadius;
258}
259
260
261/**************************************************************************/
262// ColorSet access & management
263/******************************************************************************/
264
265////////////////////////////////////////////////////////////////////////////////
266/// Create copy of current color-set on the top of the stack.
267
269{
270 fColorSetStack->push_back(new TGLColorSet(*fColorSetStack->back()));
271}
272
273////////////////////////////////////////////////////////////////////////////////
274/// Return reference to current color-set (top of the stack).
275
277{
278 return * fColorSetStack->back();
279}
280
281////////////////////////////////////////////////////////////////////////////////
282/// Pops the top-most color-set.
283/// If only one entry is available, error is printed and the entry remains.
284
286{
287 if (fColorSetStack->size() >= 2)
288 {
289 delete fColorSetStack->back();
290 fColorSetStack->pop_back();
291 }
292 else
293 {
294 Error("PopColorSet()", "Attempting to remove the last entry.");
295 }
296}
297
298////////////////////////////////////////////////////////////////////////////////
299/// Change the default/bottom color-set.
300/// Returns the previous color-set.
301
303{
304 TGLColorSet* old = fColorSetStack->front();
305 fColorSetStack->front() = set;
306 return old;
307}
308
309////////////////////////////////////////////////////////////////////////////////
310/// Returns the current base color-set.
311
313{
314 return fColorSetStack->front();
315}
316
317////////////////////////////////////////////////////////////////////////////////
318/// Set col if it is different from background, otherwise use
319/// current foreground color.
320
322{
323 if (fColorSetStack->back()->Background().GetColorIndex() == col)
324 TGLUtil::Color(fColorSetStack->back()->Foreground());
325 else
326 TGLUtil::Color(col);
327}
328
329/**************************************************************************/
330// Display-list state
331/******************************************************************************/
332
333////////////////////////////////////////////////////////////////////////////////
334/// Start display-list capture.
335
337{
338 assert(fDLCaptureOpen == kFALSE);
340}
341
342////////////////////////////////////////////////////////////////////////////////
343/// End display list capture.
344
346{
347 assert(fDLCaptureOpen == kTRUE);
349}
350
351/******************************************************************************/
352// TGLFont interface
353/******************************************************************************/
354////////////////////////////////////////////////////////////////////////////////
355/// Release font in the GL rendering context.
356
358{
360}
361
362////////////////////////////////////////////////////////////////////////////////
363/// Get font in the GL rendering context.
364
366{
368}
369
370////////////////////////////////////////////////////////////////////////////////
371/// Get font in the GL rendering context.
372
374{
376}
377
378////////////////////////////////////////////////////////////////////////////////
379/// Get font in the GL rendering context.
380/// The font is scaled relative to current render scale.
381
383{
385}
386
387////////////////////////////////////////////////////////////////////////////////
388/// Get font in the GL rendering context.
389/// The font is scaled relative to current render scale.
390
392{
394}
395
396/******************************************************************************/
397// fQuadric's initialization.
398/******************************************************************************/
399
400////////////////////////////////////////////////////////////////////////////////
401/// Initialize fQuadric.
402
404{
405 if (!fQuadric) {
406 if ((fQuadric = gluNewQuadric())) {
407 gluQuadricOrientation(fQuadric, (GLenum)GLU_OUTSIDE);
408 gluQuadricNormals(fQuadric, (GLenum)GLU_SMOOTH);
409 } else
410 Error("TGLRnrCtx::GetGluQuadric", "gluNewQuadric failed");
411 }
412
413 return fQuadric;
414}
415
416
417/******************************************************************************/
418// Matrix manipulation helpers
419/******************************************************************************/
420
422{
423 glMatrixMode(GL_PROJECTION);
424 glPushMatrix();
425 glLoadIdentity();
426 if (Selection())
427 {
430 gluPickMatrix(rect.X(), rect.Y(), rect.Width(), rect.Height(),
431 (Int_t*) GetCamera()->RefViewport().CArr());
432 }
433 glMatrixMode(GL_MODELVIEW);
434}
435
437{
438 glMatrixMode(GL_PROJECTION);
439 glPopMatrix();
440 glMatrixMode(GL_MODELVIEW);
441}
442
443
444/**************************************************************************/
445// Static helpers
446/**************************************************************************/
447
448////////////////////////////////////////////////////////////////////////////////
449/// Return string describing the style.
450
452{
453 switch (style)
454 {
455 case TGLRnrCtx::kFill: return "Filled Polys";
456 case TGLRnrCtx::kWireFrame: return "Wireframe";
457 case TGLRnrCtx::kOutline: return "Outline";
458 default: return "Oogaa-dooga style";
459 }
460}
#define GLU_OUTSIDE
Definition GL_glu.h:203
#define GLU_SMOOTH
Definition GL_glu.h:198
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
short Color_t
Definition RtypesCore.h:85
short Short_t
Definition RtypesCore.h:39
constexpr Bool_t kFALSE
Definition RtypesCore.h:94
constexpr Bool_t kTRUE
Definition RtypesCore.h:93
#define ClassImp(name)
Definition Rtypes.h:382
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:229
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t rect
Option_t Option_t TPoint TPoint const char mode
Option_t Option_t style
char name[80]
Definition TGX11.cxx:110
void WindowToViewport(Int_t &, Int_t &y) const
Definition TGLCamera.h:198
Class encapsulating a set of colors used throughout standard rendering.
Definition TGLUtil.h:836
TGLFontManager * GetFontManager()
Get the free-type font-manager associated with this context-identity.
void RegisterFont(Int_t size, Int_t file, TGLFont::EMode mode, TGLFont &out)
Provide font with given size, file and FTGL class.
void ReleaseFont(TGLFont &font)
Release font with given attributes.
A wrapper class for FTFont.
Viewport (pixel base) 2D rectangle class.
Definition TGLUtil.h:422
void Set(Int_t x, Int_t y, Int_t width, Int_t height)
Definition TGLUtil.h:471
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
Definition TGLRnrCtx.h:41
TGLColorSet * ChangeBaseColorSet(TGLColorSet *set)
Change the default/bottom color-set.
Bool_t fSecSelection
Definition TGLRnrCtx.h:127
TGLViewerBase * fViewer
Definition TGLRnrCtx.h:94
std::list< TGLColorSet * > lpTGLColorSet_t
Definition TGLRnrCtx.h:91
void BeginSelection(Int_t x, Int_t y, Int_t r=3)
Setup context for running selection.
TGLSceneInfo * fSceneInfo
Definition TGLRnrCtx.h:96
void PopColorSet()
Pops the top-most color-set.
Int_t fPickRadius
Definition TGLRnrCtx.h:129
TGLRect * fPickRectangle
Definition TGLRnrCtx.h:130
Int_t GetPickRadius()
Return pick radius. If selection is not active it returns 0.
Short_t fShapeLOD
Definition TGLRnrCtx.h:101
TGLColorSet * GetBaseColorSet()
Returns the current base color-set.
GLUquadric * fQuadric
Current GL context identity.
Definition TGLRnrCtx.h:142
void ReleaseFont(TGLFont &font)
Release font in the GL rendering context.
TGLSceneBase * GetScene()
Return current scene (based on scene-info data).
void PushColorSet()
Create copy of current color-set on the top of the stack.
TGLStopwatch fStopwatch
Definition TGLRnrCtx.h:118
TGLRect * GetPickRectangle()
Return current pick rectangle.
GLUquadric * GetGluQuadric()
Initialize fQuadric.
void RegisterFontNoScale(Int_t size, Int_t file, Int_t mode, TGLFont &out)
Get font in the GL rendering context.
void CloseDLCapture()
End display list capture.
lpTGLColorSet_t * fColorSetStack
Definition TGLRnrCtx.h:133
Bool_t IsDrawPassFilled() const
Returns true if current render-pass uses filled polygon style.
Short_t fSceneLOD
Definition TGLRnrCtx.h:99
TGLSceneBase & RefScene()
Return current scene (based on scene-info data).
TGLColorSet & ColorSet()
Return reference to current color-set (top of the stack).
Bool_t fHasTimedOut
Definition TGLRnrCtx.h:121
virtual ~TGLRnrCtx()
Destructor.
void StartStopwatch()
Start the stopwatch.
void RegisterFont(Int_t size, Int_t file, Int_t mode, TGLFont &out)
Get font in the GL rendering context.
void StopStopwatch()
Stop the stopwatch.
Double_t fRenderTimeOut
Definition TGLRnrCtx.h:119
void EndSelection(Int_t glResult)
End selection.
Bool_t fSelection
Definition TGLRnrCtx.h:126
Bool_t fDLCaptureOpen
Definition TGLRnrCtx.h:139
void ProjectionMatrixPushIdentity()
Short_t fDrawPass
Definition TGLRnrCtx.h:116
Bool_t HasStopwatchTimedOut()
Check if the stopwatch went beyond the render time limit.
TGLRnrCtx(const TGLRnrCtx &)=delete
void ColorOrForeground(Color_t col)
Set col if it is different from background, otherwise use current foreground color.
TGLSelectBuffer * fSelectBuffer
Definition TGLRnrCtx.h:131
void ProjectionMatrixPop()
TGLContextIdentity * fGLCtxIdentity
DL-capture currently open.
Definition TGLRnrCtx.h:140
Short_t fCombiLOD
Definition TGLRnrCtx.h:100
TGLCamera * GetCamera()
Definition TGLRnrCtx.h:156
static const char * StyleName(Short_t style)
Return string describing the style.
void OpenDLCapture()
Start display-list capture.
Bool_t fIsRunning
Definition TGLRnrCtx.h:120
Short_t fSceneStyle
Definition TGLRnrCtx.h:105
@ kPassOutlineFill
Definition TGLRnrCtx.h:56
Float_t fRenderScale
Definition TGLRnrCtx.h:134
Bool_t Selection() const
Definition TGLRnrCtx.h:222
Short_t fViewerStyle
Definition TGLRnrCtx.h:104
Short_t fViewerLOD
Definition TGLRnrCtx.h:98
Scene base-class – provides basic interface expected by the TGLViewer or its sub-classes:
TGLSceneBase * GetScene() const
Encapsulates OpenGL select buffer.
void ProcessResult(Int_t glResult)
Process result of GL-selection: sort the hits by their minimum z-coordinate.
void Grow()
Increase size of the select buffer.
Bool_t CanGrow()
static: return true if current buffer is smaller than the max buffer size
Int_t GetBufSize() const
UInt_t * GetBuf() const
void Start()
Start timing.
Double_t Lap() const
Return lap time since Start(), in milliseconds.
Double_t End()
End timing, return total time since Start(), in milliseconds.
static void Color(const TGLColor &color)
Set color from TGLColor.
Definition TGLUtil.cxx:1697
Base class for GL viewers.
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition TMath.h:693