Logo ROOT   6.08/07
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 #include <memory>
19 
20 class TGLContextIdentity;
21 
22 #ifndef ROOT_TGLFormat
23 #include "TGLFormat.h"
24 #endif
25 #ifndef ROOT_Rtypes
26 #include "Rtypes.h"
27 #endif
28 
29 class TGLContextPrivate;
30 class TGLPaintDevice;
31 //class TGLPBuffer;
32 class TGLWidget;
33 class TGLFontManager;
34 
36 {
37  friend class TGLContextPrivate;
38  friend class TGLWidget;
39  // friend class TGLPBuffer;
40 
41 private:
43  std::unique_ptr<TGLContextPrivate> fPimpl;
44 
45  Bool_t fFromCtor;//To prohibit user's calls of SetContext.
47 
49 
51 
52 public:
53  TGLContext(TGLWidget *glWidget, Bool_t shareDefault=kTRUE, const TGLContext *shareList=0);
54  // TGLContext(TGLPBuffer *glPbuf, const TGLContext *shareList = 0);
55 
57 
58  virtual ~TGLContext();
59 
62  void SwapBuffers();
63 
64  //This functions are public _ONLY_ for calls via
65  //gROOT under win32. Please, DO NOT CALL IT DIRECTLY.
66  void SetContext(TGLWidget *widget, const TGLContext *shareList);
67  // void SetContextPB(TGLPBuffer *pbuff, const TGLContext *shareList);
68  void Release();
69 
70  Bool_t IsValid() const { return fValid; }
71 
72  static TGLContext *GetCurrent();
73  static void GlewInit();
74 
75 private:
76  TGLContext(const TGLContext &);
78 
79  ClassDef(TGLContext, 0); // Control internal gl-context resources.
80 };
81 
82 
83 //______________________________________________________________________________
84 
86 {
87 
88 protected:
89  TGLFontManager* fFontManager; // FreeType font manager.
90 
91 public:
93  virtual ~TGLContextIdentity();
94 
95  void AddRef(TGLContext* ctx);
96  void Release(TGLContext* ctx);
97 
98  void AddClientRef() { ++fClientCnt; }
99  void ReleaseClient() { --fClientCnt; CheckDestroy(); }
100 
101  Int_t GetRefCnt() const { return fCnt; }
102  Int_t GetClientRefCnt() const { return fClientCnt; }
103 
104  Bool_t IsValid() const { return fCnt > 0; }
105 
106  void RegisterDLNameRangeToWipe(UInt_t base, Int_t size);
107  void DeleteGLResources();
108 
109  static TGLContextIdentity *GetCurrent();
110 
111  static TGLContextIdentity *GetDefaultIdentity();
112  static TGLContext *GetDefaultContextAny();
113 
114  TGLFontManager *GetFontManager();
115 
116 private:
119 
120  void CheckDestroy();
121 
122  typedef std::pair<UInt_t, Int_t> DLRange_t;
123  typedef std::list<DLRange_t> DLTrash_t;
124  typedef DLTrash_t::const_iterator DLTrashIt_t;
125 
126  typedef std::list<TGLContext*> CtxList_t;
127 
128  DLTrash_t fDLTrash;
129  CtxList_t fCtxs;
130 
132 
133  ClassDef(TGLContextIdentity, 0); // Identity of a shared GL context.
134 };
135 
136 #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:122
Identifier of a shared GL-context.
Definition: TGLContext.h:85
Bool_t fValid
Definition: TGLContext.h:46
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
DLTrash_t::const_iterator DLTrashIt_t
Definition: TGLContext.h:124
std::list< TGLContext * > CtxList_t
Definition: TGLContext.h:126
TGLContextIdentity * fIdentity
Definition: TGLContext.h:48
#define ClassDef(name, id)
Definition: Rtypes.h:254
TGLPaintDevice * fDevice
Definition: TGLContext.h:42
DLTrash_t fDLTrash
Definition: TGLContext.h:128
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:123
Bool_t IsValid() const
Definition: TGLContext.h:70
Bool_t IsValid() const
Definition: TGLContext.h:104
TGLContext(TGLWidget *glWidget, Bool_t shareDefault=kTRUE, const TGLContext *shareList=0)
TGLContext ctor "from" TGLWidget.
Definition: TGLContext.cxx:51
TGLFontManager * fFontManager
Definition: TGLContext.h:89
Int_t GetRefCnt() const
Definition: TGLContext.h:101
unsigned int UInt_t
Definition: RtypesCore.h:42
GL window with context.
Definition: TGLWidget.h:35
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:35
Bool_t ClearCurrent()
Reset current context.
Definition: TGLContext.cxx:386
Int_t GetClientRefCnt() const
Definition: TGLContext.h:102
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:50
static TGLContextIdentity * fgDefaultIdentity
Definition: TGLContext.h:131
const Bool_t kTRUE
Definition: Rtypes.h:91
Bool_t fFromCtor
Definition: TGLContext.h:45
virtual ~TGLContext()
TGLContext dtor.
Definition: TGLContext.cxx:428
std::unique_ptr< TGLContextPrivate > fPimpl
Definition: TGLContext.h:43
TGLContext & operator=(const TGLContext &)
void ReleaseClient()
Definition: TGLContext.h:99