Logo ROOT   6.12/07
Reference Guide
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 
31 {
32  friend class TGLContextPrivate;
33  friend class TGLWidget;
34  // friend class TGLPBuffer;
35 
36 private:
38  std::unique_ptr<TGLContextPrivate> fPimpl;
39 
40  Bool_t fFromCtor;//To prohibit user's calls of SetContext.
42 
44 
46 
47 public:
48  TGLContext(TGLWidget *glWidget, Bool_t shareDefault=kTRUE, const TGLContext *shareList=0);
49  // TGLContext(TGLPBuffer *glPbuf, const TGLContext *shareList = 0);
50 
52 
53  virtual ~TGLContext();
54 
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 &);
73 
74  ClassDef(TGLContext, 0); // Control internal gl-context resources.
75 };
76 
77 
78 //______________________________________________________________________________
79 
81 {
82 
83 protected:
84  TGLFontManager* fFontManager; // FreeType font manager.
85 
86 public:
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:
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 
127 
128  ClassDef(TGLContextIdentity, 0); // Identity of a shared GL context.
129 };
130 
131 #endif
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:443
std::pair< UInt_t, Int_t > DLRange_t
Definition: TGLContext.h:117
Identifier of a shared GL-context.
Definition: TGLContext.h:80
Bool_t fValid
Definition: TGLContext.h:41
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
DLTrash_t::const_iterator DLTrashIt_t
Definition: TGLContext.h:119
std::list< TGLContext * > CtxList_t
Definition: TGLContext.h:121
TGLContextIdentity * fIdentity
Definition: TGLContext.h:43
#define ClassDef(name, id)
Definition: Rtypes.h:320
TGLPaintDevice * fDevice
Definition: TGLContext.h:37
DLTrash_t fDLTrash
Definition: TGLContext.h:123
Bool_t MakeCurrent()
If context is valid (TGLPaintDevice, for which context was created still exists), make it current...
Definition: TGLContext.cxx:362
std::list< DLRange_t > DLTrash_t
Definition: TGLContext.h:118
Bool_t IsValid() const
Definition: TGLContext.h:65
Bool_t IsValid() const
Definition: TGLContext.h:99
TGLContext(TGLWidget *glWidget, Bool_t shareDefault=kTRUE, const TGLContext *shareList=0)
TGLContext ctor "from" TGLWidget.
Definition: TGLContext.cxx:51
TGLFontManager * fFontManager
Definition: TGLContext.h:84
Int_t GetRefCnt() const
Definition: TGLContext.h:96
unsigned int UInt_t
Definition: RtypesCore.h:42
GL window with context.
Definition: TGLWidget.h:27
static void GlewInit()
Initialize GLEW - static private function.
Definition: TGLContext.cxx:85
void SetContext(TGLWidget *widget, const TGLContext *shareList)
X11 gl-context creation.
Definition: TGLContext.cxx:329
void SwapBuffers()
If context is valid (TGLPaintDevice, for which context was created still exists), swap buffers (in ca...
Definition: TGLContext.cxx:395
This class encapsulates window-system specific information about a GL-context and alows their proper ...
Definition: TGLContext.h:30
Bool_t ClearCurrent()
Reset current context.
Definition: TGLContext.cxx:386
Int_t GetClientRefCnt() const
Definition: TGLContext.h:97
void Release()
Make the context invalid and (do thread switch, if needed) free resources.
Definition: TGLContext.cxx:412
static TGLContext * GetCurrent()
Ask TGLContextPrivate to lookup context in its internal map.
Definition: TGLContext.cxx:451
A FreeType GL font manager.
static Bool_t fgGlewInitDone
Definition: TGLContext.h:45
static TGLContextIdentity * fgDefaultIdentity
Definition: TGLContext.h:126
Bool_t fFromCtor
Definition: TGLContext.h:40
const Bool_t kTRUE
Definition: RtypesCore.h:87
virtual ~TGLContext()
TGLContext dtor.
Definition: TGLContext.cxx:428
std::unique_ptr< TGLContextPrivate > fPimpl
Definition: TGLContext.h:38
TGLContext & operator=(const TGLContext &)
void ReleaseClient()
Definition: TGLContext.h:94