ROOT  6.06/09
Reference Guide
TGLContext.h
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Timur Pocheptsov, Jun 2007
3 
4 #include <utility>
5 #include <list>
6 
7 /*************************************************************************
8  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
9  * All rights reserved. *
10  * *
11  * For the licensing terms see $ROOTSYS/LICENSE. *
12  * For the list of contributors see $ROOTSYS/README/CREDITS. *
13  *************************************************************************/
14 
15 #ifndef ROOT_TGLContext
16 #define ROOT_TGLContext
17 
18 class TGLContextIdentity;
19 
20 #ifndef ROOT_TGLFormat
21 #include "TGLFormat.h"
22 #endif
23 #ifndef ROOT_Rtypes
24 #include "Rtypes.h"
25 #endif
26 
27 class TGLContextPrivate;
28 class TGLPaintDevice;
29 //class TGLPBuffer;
30 class TGLWidget;
31 class TGLFontManager;
32 
34 {
35  friend class TGLContextPrivate;
36  friend class TGLWidget;
37  // friend class TGLPBuffer;
38 
39 private:
42 
43  Bool_t fFromCtor;//To prohibit user's calls of SetContext.
45 
47 
49 
50 public:
51  TGLContext(TGLWidget *glWidget, Bool_t shareDefault=kTRUE, const TGLContext *shareList=0);
52  // TGLContext(TGLPBuffer *glPbuf, const TGLContext *shareList = 0);
53 
55 
56  virtual ~TGLContext();
57 
60  void SwapBuffers();
61 
62  //This functions are public _ONLY_ for calls via
63  //gROOT under win32. Please, DO NOT CALL IT DIRECTLY.
64  void SetContext(TGLWidget *widget, const TGLContext *shareList);
65  // void SetContextPB(TGLPBuffer *pbuff, const TGLContext *shareList);
66  void Release();
67 
68  Bool_t IsValid() const { return fValid; }
69 
70  static TGLContext *GetCurrent();
71  static void GlewInit();
72 
73 private:
74  TGLContext(const TGLContext &);
76 
77  ClassDef(TGLContext, 0); // Control internal gl-context resources.
78 };
79 
80 
81 //______________________________________________________________________________
82 
84 {
85 
86 protected:
87  TGLFontManager* fFontManager; // FreeType font manager.
88 
89 public:
91  virtual ~TGLContextIdentity();
92 
93  void AddRef(TGLContext* ctx);
94  void Release(TGLContext* ctx);
95 
96  void AddClientRef() { ++fClientCnt; }
98 
99  Int_t GetRefCnt() const { return fCnt; }
100  Int_t GetClientRefCnt() const { return fClientCnt; }
101 
102  Bool_t IsValid() const { return fCnt > 0; }
103 
104  void RegisterDLNameRangeToWipe(UInt_t base, Int_t size);
105  void DeleteGLResources();
106 
107  static TGLContextIdentity *GetCurrent();
108 
111 
113 
114 private:
117 
118  void CheckDestroy();
119 
120  typedef std::pair<UInt_t, Int_t> DLRange_t;
121  typedef std::list<DLRange_t> DLTrash_t;
122  typedef DLTrash_t::const_iterator DLTrashIt_t;
123 
124  typedef std::list<TGLContext*> CtxList_t;
125 
126  DLTrash_t fDLTrash;
127  CtxList_t fCtxs;
128 
130 
131  ClassDef(TGLContextIdentity, 0); // Identity of a shared GL context.
132 };
133 
134 #endif
static TGLContext * GetDefaultContextAny()
Get the first GL context with the default identity.
Definition: TGLContext.cxx:566
Int_t GetRefCnt() const
Definition: TGLContext.h:99
static TGLContextIdentity * GetDefaultIdentity()
Get identity of a default Gl context. Static.
Definition: TGLContext.cxx:555
Int_t GetClientRefCnt() const
Definition: TGLContext.h:100
std::pair< UInt_t, Int_t > DLRange_t
Definition: TGLContext.h:120
Identifier of a shared GL-context.
Definition: TGLContext.h:83
Bool_t fValid
Definition: TGLContext.h:44
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
DLTrash_t::const_iterator DLTrashIt_t
Definition: TGLContext.h:122
std::list< TGLContext * > CtxList_t
Definition: TGLContext.h:124
TGLContextIdentity * fIdentity
Definition: TGLContext.h:46
void CheckDestroy()
Private function called when reference count is reduced.
Definition: TGLContext.cxx:585
void Release(TGLContext *ctx)
Remove context ctx from the list of references.
Definition: TGLContext.cxx:504
TGLPaintDevice * fDevice
Definition: TGLContext.h:40
DLTrash_t fDLTrash
Definition: TGLContext.h:126
TGLContextIdentity * GetIdentity() const
We can have several shared contexts, and gl-scene wants to know, if some context (defined by its iden...
Definition: TGLContext.cxx:451
Bool_t MakeCurrent()
If context is valid (TGLPaintDevice, for which context was created still exists), make it current...
Definition: TGLContext.cxx:368
std::list< DLRange_t > DLTrash_t
Definition: TGLContext.h:121
TGLContextPrivate * fPimpl
Definition: TGLContext.h:41
ClassDef(TGLContextIdentity, 0)
virtual ~TGLContextIdentity()
Destructor.
Definition: TGLContext.cxx:487
static TGLContextIdentity * GetCurrent()
Find identitfy of current context. Static.
Definition: TGLContext.cxx:546
TGLContext(TGLWidget *glWidget, Bool_t shareDefault=kTRUE, const TGLContext *shareList=0)
TGLContext ctor "from" TGLWidget.
Definition: TGLContext.cxx:51
TGLFontManager * fFontManager
Definition: TGLContext.h:87
Bool_t IsValid() const
Definition: TGLContext.h:68
static TGLContextIdentity * fgDefaultIdentity
Definition: TGLContext.h:129
unsigned int UInt_t
Definition: RtypesCore.h:42
void DeleteGLResources()
Delete GL resources registered for destruction.
Definition: TGLContext.cxx:530
Bool_t IsValid() const
Definition: TGLContext.h:102
GL window with context.
Definition: TGLWidget.h:35
static void GlewInit()
Initialize GLEW - static private function.
Definition: TGLContext.cxx:86
TGLFontManager * GetFontManager()
Get the free-type font-manager associated with this context-identity.
Definition: TGLContext.cxx:576
void SetContext(TGLWidget *widget, const TGLContext *shareList)
X11 gl-context creation.
Definition: TGLContext.cxx:333
void SwapBuffers()
If context is valid (TGLPaintDevice, for which context was created still exists), swap buffers (in ca...
Definition: TGLContext.cxx:401
This class encapsulates window-system specific information about a GL-context and alows their proper ...
Definition: TGLContext.h:33
Bool_t ClearCurrent()
Reset current context.
Definition: TGLContext.cxx:392
void AddRef(TGLContext *ctx)
Add context ctx to the list of references.
Definition: TGLContext.cxx:495
ClassDef(TGLContext, 0)
void Release()
Make the context invalid and (do thread switch, if needed) free resources.
Definition: TGLContext.cxx:418
static TGLContext * GetCurrent()
Ask TGLContextPrivate to lookup context in its internal map.
Definition: TGLContext.cxx:459
A FreeType GL font manager.
static Bool_t fgGlewInitDone
Definition: TGLContext.h:48
const Bool_t kTRUE
Definition: Rtypes.h:91
void RegisterDLNameRangeToWipe(UInt_t base, Int_t size)
Remember dl range for deletion in next MakeCurrent or dtor execution.
Definition: TGLContext.cxx:522
Bool_t fFromCtor
Definition: TGLContext.h:43
virtual ~TGLContext()
TGLContext dtor.
Definition: TGLContext.cxx:434
TGLContext & operator=(const TGLContext &)
void ReleaseClient()
Definition: TGLContext.h:97