Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLContext.h
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Timur Pocheptsov, Jun 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_TGLContext
13 #define ROOT_TGLContext
14 
15 #include <list>
16 #include <memory>
17 #include <utility>
18 
19 class TGLContextIdentity;
20 
21 #include "TGLFormat.h"
22 #include "Rtypes.h"
23 
24 class TGLContextPrivate;
25 class TGLPaintDevice;
26 //class TGLPBuffer;
27 class TGLWidget;
28 class TGLFontManager;
29 
30 class TGLContext
31 {
32  friend class TGLContextPrivate;
33  friend class TGLWidget;
34  // friend class TGLPBuffer;
35 
36 private:
37  TGLPaintDevice *fDevice;
38  std::unique_ptr<TGLContextPrivate> fPimpl;
39 
40  Bool_t fFromCtor;//To prohibit user's calls of SetContext.
41  Bool_t fValid;
42 
43  TGLContextIdentity *fIdentity;
44 
45  static Bool_t fgGlewInitDone;
46 
47 public:
48  TGLContext(TGLWidget *glWidget, Bool_t shareDefault=kTRUE, const TGLContext *shareList=0);
49  // TGLContext(TGLPBuffer *glPbuf, const TGLContext *shareList = 0);
50 
51  TGLContextIdentity *GetIdentity()const;
52 
53  virtual ~TGLContext();
54 
55  Bool_t MakeCurrent();
56  Bool_t ClearCurrent();
57  void SwapBuffers();
58 
59  //This functions are public _ONLY_ for calls via
60  //gROOT under win32. Please, DO NOT CALL IT DIRECTLY.
61  void SetContext(TGLWidget *widget, const TGLContext *shareList);
62  // void SetContextPB(TGLPBuffer *pbuff, const TGLContext *shareList);
63  void Release();
64 
65  Bool_t IsValid() const { return fValid; }
66 
67  static TGLContext *GetCurrent();
68  static void GlewInit();
69 
70 private:
71  TGLContext(const TGLContext &);
72  TGLContext &operator = (const TGLContext &);
73 
74  ClassDef(TGLContext, 0); // Control internal gl-context resources.
75 };
76 
77 
78 //______________________________________________________________________________
79 
80 class TGLContextIdentity
81 {
82 
83 protected:
84  TGLFontManager* fFontManager; // FreeType font manager.
85 
86 public:
87  TGLContextIdentity();
88  virtual ~TGLContextIdentity();
89 
90  void AddRef(TGLContext* ctx);
91  void Release(TGLContext* ctx);
92 
93  void AddClientRef() { ++fClientCnt; }
94  void ReleaseClient() { --fClientCnt; CheckDestroy(); }
95 
96  Int_t GetRefCnt() const { return fCnt; }
97  Int_t GetClientRefCnt() const { return fClientCnt; }
98 
99  Bool_t IsValid() const { return fCnt > 0; }
100 
101  void RegisterDLNameRangeToWipe(UInt_t base, Int_t size);
102  void DeleteGLResources();
103 
104  static TGLContextIdentity *GetCurrent();
105 
106  static TGLContextIdentity *GetDefaultIdentity();
107  static TGLContext *GetDefaultContextAny();
108 
109  TGLFontManager *GetFontManager();
110 
111 private:
112  Int_t fCnt;
113  Int_t fClientCnt;
114 
115  void CheckDestroy();
116 
117  typedef std::pair<UInt_t, Int_t> DLRange_t;
118  typedef std::list<DLRange_t> DLTrash_t;
119  typedef DLTrash_t::const_iterator DLTrashIt_t;
120 
121  typedef std::list<TGLContext*> CtxList_t;
122 
123  DLTrash_t fDLTrash;
124  CtxList_t fCtxs;
125 
126  static TGLContextIdentity * fgDefaultIdentity;
127 
128  ClassDef(TGLContextIdentity, 0); // Identity of a shared GL context.
129 };
130 
131 #endif