Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLRnrCtx.h
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 #ifndef ROOT_TGLRnrCtx
13 #define ROOT_TGLRnrCtx
14 
15 #include "Rtypes.h"
16 #include "TGLStopwatch.h"
17 
18 #include <list>
19 
20 class TGLViewerBase;
21 class TGLCamera;
22 class TGLSceneBase;
23 class TGLSceneInfo;
24 
25 class TGLColorSet;
26 class TGLFont;
27 class TGLContextIdentity;
28 
29 class TGLClip;
30 class TGLSelectBuffer;
31 
32 class TGLRect;
33 
34 class GLUquadric;
35 
36 /**************************************************************************/
37 // TGLRnrCtx
38 /**************************************************************************/
39 
40 class TGLRnrCtx
41 {
42 public:
43  enum EStyle
44  {
45  kStyleUndef = -1,
46  kFill,
47  kOutline,
48  kWireFrame
49  };
50  static const char* StyleName(Short_t style);
51 
52  enum EPass
53  {
54  kPassUndef = -1,
55  kPassFill,
56  kPassOutlineFill,
57  kPassOutlineLine,
58  kPassWireFrame
59  };
60 
61  enum ELODPresets
62  {
63  kLODUndef = -1,
64  kLODPixel = 0, // Projected size pixel or less
65  kLODLow = 20,
66  kLODMed = 50,
67  kLODHigh = 100
68  };
69 
70  enum EShapeSelectionLevel
71  {
72  kSSLNotSelected,
73  kSSLSelected,
74  kSSLImpliedSelected,
75  kSSLHighlighted,
76  kSSLImpliedHighlighted,
77  kSSLEnd
78  };
79 
80  enum ESelectabilityOfTransparents
81  {
82  kIfNoOpaques = 0,
83  kIfClosest,
84  kNever
85  };
86 
87 private:
88  TGLRnrCtx(const TGLRnrCtx&); // Not implemented
89  TGLRnrCtx& operator=(const TGLRnrCtx&); // Not implemented
90 
91  typedef std::list<TGLColorSet*> lpTGLColorSet_t;
92 
93 protected:
94  TGLViewerBase *fViewer;
95  TGLCamera *fCamera;
96  TGLSceneInfo *fSceneInfo;
97 
98  Short_t fViewerLOD;
99  Short_t fSceneLOD;
100  Short_t fCombiLOD; // Combined viewer/scene lod.
101  Short_t fShapeLOD; // LOD calculated for current shape.
102  Float_t fShapePixSize; // Only relevant when not using display lists.
103 
104  Short_t fViewerStyle;
105  Short_t fSceneStyle;
106 
107  Float_t fViewerWFLineW;
108  Float_t fSceneWFLineW;
109  Float_t fViewerOLLineW;
110  Float_t fSceneOLLineW;
111 
112  TGLClip *fViewerClip;
113  TGLClip *fSceneClip;
114  TGLClip *fClip;
115 
116  Short_t fDrawPass;
117 
118  TGLStopwatch fStopwatch;
119  Double_t fRenderTimeOut;
120  Bool_t fIsRunning;
121  Bool_t fHasTimedOut;
122 
123  // Highlight / Selection stuff
124  Bool_t fHighlight; // True when in highlight.
125  Bool_t fHighlightOutline; // True when in highlight-outline.
126  Bool_t fSelection; // True when in selection.
127  Bool_t fSecSelection; // True when in secondary selection.
128  Short_t fSelectTransparents;
129  Int_t fPickRadius;
130  TGLRect *fPickRectangle;
131  TGLSelectBuffer*fSelectBuffer;
132 
133  lpTGLColorSet_t*fColorSetStack;
134  Float_t fRenderScale;
135 
136  UInt_t fEventKeySym;
137 
138  // GL state
139  Bool_t fDLCaptureOpen; //! DL-capture currently open
140  TGLContextIdentity *fGLCtxIdentity; //! Current GL context identity
141 
142  GLUquadric *fQuadric;
143 
144  // Picture grabbing
145  Bool_t fGrabImage; // Set to true to store the image.
146  Int_t fGrabBuffer; // Which buffer to grab after render.
147  UChar_t *fGrabbedImage; // Buffer where image was stored after rendering.
148 
149 public:
150  TGLRnrCtx(TGLViewerBase* viewer);
151  virtual ~TGLRnrCtx();
152 
153  // Central objects
154  TGLViewerBase * GetViewer() { return fViewer; }
155  TGLViewerBase & RefViewer() { return *fViewer; }
156  TGLCamera * GetCamera() { return fCamera; }
157  TGLCamera & RefCamera() { return *fCamera; }
158  TGLSceneInfo * GetSceneInfo() { return fSceneInfo; }
159  TGLSceneInfo & RefSceneInfo() { return *fSceneInfo; }
160  TGLSceneBase * GetScene();
161  TGLSceneBase & RefScene();
162 
163  const TGLCamera & RefCamera() const { return *fCamera; }
164  const TGLCamera * GetCamera() const { return fCamera; }
165 
166  // void SetViewer (TGLViewerBase* v) { fViewer = v; }
167  void SetCamera (TGLCamera* c) { fCamera = c; }
168  void SetSceneInfo(TGLSceneInfo* si) { fSceneInfo = si; }
169 
170  // Draw LOD, style, clip, rnr-pass
171  Short_t ViewerLOD() const { return fViewerLOD; }
172  void SetViewerLOD(Short_t LOD) { fViewerLOD = LOD; }
173  Short_t SceneLOD() const { return fSceneLOD; }
174  void SetSceneLOD(Short_t LOD) { fSceneLOD = LOD; }
175  Short_t CombiLOD() const { return fCombiLOD; }
176  void SetCombiLOD(Short_t LOD) { fCombiLOD = LOD; }
177  Short_t ShapeLOD() const { return fShapeLOD; }
178  void SetShapeLOD(Short_t LOD) { fShapeLOD = LOD; }
179  Float_t ShapePixSize() const { return fShapePixSize; }
180  void SetShapePixSize(Float_t ps) { fShapePixSize = ps; }
181 
182  Short_t ViewerStyle() const { return fViewerStyle; }
183  void SetViewerStyle(Short_t sty) { fViewerStyle = sty; }
184  Short_t SceneStyle() const { return fSceneStyle; }
185  void SetSceneStyle(Short_t sty) { fSceneStyle = sty; }
186 
187  Float_t ViewerWFLineW() const { return fViewerWFLineW; }
188  void SetViewerWFLineW(Float_t w) { fViewerWFLineW = w; }
189  Float_t SceneWFLineW() const { return fSceneWFLineW; }
190  void SetSceneWFLineW(Float_t w) { fSceneWFLineW = w; }
191  Float_t ViewerOLLineW() const { return fViewerOLLineW; }
192  void SetViewerOLLineW(Float_t w) { fViewerOLLineW = w; }
193  Float_t SceneOLLineW() const { return fSceneOLLineW; }
194  void SetSceneOLLineW(Float_t w) { fSceneOLLineW = w; }
195 
196  TGLClip* ViewerClip() const { return fViewerClip; }
197  void SetViewerClip(TGLClip *p) { fViewerClip = p; }
198  TGLClip* SceneClip() const { return fSceneClip; }
199  void SetSceneClip(TGLClip *p) { fSceneClip = p; }
200  TGLClip* Clip() const { return fClip; }
201  void SetClip(TGLClip *p) { fClip = p; }
202  Bool_t HasClip() const { return fClip != 0; }
203 
204  Short_t DrawPass() const { return fDrawPass; }
205  void SetDrawPass(Short_t dpass) { fDrawPass = dpass; }
206  Bool_t IsDrawPassFilled() const;
207  Bool_t IsDrawPassOutlineLine() const { return fDrawPass == kPassOutlineLine; }
208 
209  // Render time-out
210  Double_t RenderTimeOut() const { return fRenderTimeOut; }
211  void SetRenderTimeOut(Double_t tout) { fRenderTimeOut = tout; }
212  void StartStopwatch();
213  void StopStopwatch();
214  Bool_t IsStopwatchRunning() const { return fIsRunning; }
215  Bool_t HasStopwatchTimedOut();
216 
217  // Highlight / Selection state during rendering
218  Bool_t Highlight() const { return fHighlight; }
219  void SetHighlight(Bool_t hil) { fHighlight = hil; }
220  Bool_t HighlightOutline() const { return fHighlightOutline; }
221  void SetHighlightOutline(Bool_t ho) { fHighlightOutline = ho; }
222  Bool_t Selection() const { return fSelection; }
223  void SetSelection(Bool_t sel) { fSelection = sel; }
224  Bool_t SecSelection() const { return fSecSelection; }
225  void SetSecSelection(Bool_t secSel) { fSecSelection = secSel; }
226  // Highlight / selection parameters
227  Short_t SelectTransparents() const { return fSelectTransparents; }
228  void SetSelectTransparents(Short_t st) { fSelectTransparents = st; }
229  TGLRect * GetPickRectangle();
230  Int_t GetPickRadius();
231  TGLSelectBuffer * GetSelectBuffer() const { return fSelectBuffer; }
232  // Selection setup / end
233  void BeginSelection(Int_t x, Int_t y, Int_t r=3);
234  void EndSelection (Int_t glResult);
235 
236  void PushColorSet();
237  TGLColorSet& ColorSet();
238  void PopColorSet();
239  TGLColorSet* ChangeBaseColorSet(TGLColorSet* set);
240  TGLColorSet* GetBaseColorSet();
241 
242  void ColorOrForeground(Color_t col);
243 
244  Float_t GetRenderScale() const { return fRenderScale; }
245  void SetRenderScale(Float_t s) { fRenderScale = s; }
246 
247  UInt_t GetEventKeySym() const { return fEventKeySym; }
248  void SetEventKeySym(UInt_t k) { fEventKeySym = k; }
249 
250  Bool_t IsDLCaptureOpen() const { return fDLCaptureOpen; }
251  void OpenDLCapture();
252  void CloseDLCapture();
253 
254  TGLContextIdentity* GetGLCtxIdentity() const { return fGLCtxIdentity; }
255  void SetGLCtxIdentity(TGLContextIdentity* cid) { fGLCtxIdentity = cid; }
256 
257  void RegisterFont(Int_t size, Int_t file, Int_t mode, TGLFont& out);
258  void RegisterFont(Int_t size, const char* name, Int_t mode, TGLFont& out);
259  void RegisterFontNoScale(Int_t size, Int_t file, Int_t mode, TGLFont& out);
260  void RegisterFontNoScale(Int_t size, const char* name, Int_t mode, TGLFont& out);
261  void ReleaseFont(TGLFont& font);
262 
263  GLUquadric* GetGluQuadric();
264 
265  // Picture grabbing
266  void SetGrabImage(Bool_t gi) { fGrabImage = gi; }
267  Bool_t GetGrabImage() const { return fGrabImage; }
268 
269  // Matrix manipulation helpers
270  void ProjectionMatrixPushIdentity();
271  void ProjectionMatrixPop();
272 
273  ClassDef(TGLRnrCtx, 0); // Collection of objects and data passes along all rendering calls.
274 };
275 
276 
277 #endif