TGLContext.h

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLContext.h 36675 2010-11-15 20:33:58Z matevz $
00002 // Author:  Timur Pocheptsov, Jun 2007
00003 
00004 #include <utility>
00005 #include <list>
00006 
00007 /*************************************************************************
00008  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00009  * All rights reserved.                                                  *
00010  *                                                                       *
00011  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00012  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00013  *************************************************************************/
00014 
00015 #ifndef ROOT_TGLContext
00016 #define ROOT_TGLContext
00017 
00018 class TGLContextIdentity;
00019 
00020 #ifndef ROOT_TGLFormat
00021 #include "TGLFormat.h"
00022 #endif
00023 #ifndef ROOT_Rtypes
00024 #include "Rtypes.h"
00025 #endif
00026 
00027 class TGLContextPrivate;
00028 class TGLPaintDevice;
00029 //class TGLPBuffer;
00030 class TGLWidget;
00031 class TGLFontManager;
00032 
00033 class TGLContext
00034 {
00035    friend class TGLContextPrivate;
00036    friend class TGLWidget;
00037    //   friend class TGLPBuffer;
00038 
00039 private:
00040    TGLPaintDevice *fDevice;
00041    TGLContextPrivate *fPimpl;
00042 
00043    Bool_t fFromCtor;//To prohibit user's calls of SetContext.
00044    Bool_t fValid;
00045 
00046    TGLContextIdentity *fIdentity;
00047 
00048    static Bool_t fgGlewInitDone;
00049 
00050 public:
00051    TGLContext(TGLWidget *glWidget, Bool_t shareDefault=kTRUE, const TGLContext *shareList=0);
00052    //   TGLContext(TGLPBuffer *glPbuf, const TGLContext *shareList = 0);
00053 
00054    TGLContextIdentity *GetIdentity()const;
00055 
00056    virtual ~TGLContext();
00057 
00058    Bool_t           MakeCurrent();
00059    Bool_t           ClearCurrent();
00060    void             SwapBuffers();
00061 
00062    //This functions are public _ONLY_ for calls via
00063    //gROOT under win32. Please, DO NOT CALL IT DIRECTLY.
00064    void             SetContext(TGLWidget *widget, const TGLContext *shareList);
00065    // void          SetContextPB(TGLPBuffer *pbuff, const TGLContext *shareList);
00066    void             Release();
00067 
00068    Bool_t           IsValid() const { return fValid; }
00069 
00070    static TGLContext *GetCurrent();
00071    static void GlewInit();
00072 
00073 private:
00074    TGLContext(const TGLContext &);
00075    TGLContext &operator = (const TGLContext &);
00076 
00077    ClassDef(TGLContext, 0); // Control internal gl-context resources.
00078 };
00079 
00080 
00081 //______________________________________________________________________________
00082 
00083 class TGLContextIdentity
00084 {
00085 
00086 protected:
00087    TGLFontManager*      fFontManager;  // FreeType font manager.
00088 
00089 public:
00090    TGLContextIdentity();
00091    virtual ~TGLContextIdentity();
00092 
00093    void AddRef(TGLContext* ctx);
00094    void Release(TGLContext* ctx);
00095 
00096    void AddClientRef()  { ++fClientCnt; }
00097    void ReleaseClient() { --fClientCnt; CheckDestroy(); }
00098 
00099    Int_t GetRefCnt()       const { return fCnt; }
00100    Int_t GetClientRefCnt() const { return fClientCnt; }
00101 
00102    Bool_t IsValid() const { return fCnt > 0; }
00103 
00104    void RegisterDLNameRangeToWipe(UInt_t base, Int_t size);
00105    void DeleteGLResources();
00106 
00107    static TGLContextIdentity *GetCurrent();
00108 
00109    static TGLContextIdentity *GetDefaultIdentity();
00110    static TGLContext         *GetDefaultContextAny();
00111 
00112    TGLFontManager            *GetFontManager();
00113 
00114 private:
00115    Int_t fCnt;
00116    Int_t fClientCnt;
00117 
00118    void CheckDestroy();
00119 
00120    typedef std::pair<UInt_t, Int_t>  DLRange_t;
00121    typedef std::list<DLRange_t>      DLTrash_t;
00122    typedef DLTrash_t::const_iterator DLTrashIt_t;
00123 
00124    typedef std::list<TGLContext*>    CtxList_t;
00125 
00126    DLTrash_t fDLTrash;
00127    CtxList_t fCtxs;
00128 
00129    static TGLContextIdentity * fgDefaultIdentity;
00130 
00131    ClassDef(TGLContextIdentity, 0); // Identity of a shared GL context.
00132 };
00133 
00134 #endif

Generated on Tue Jul 5 14:16:43 2011 for ROOT_528-00b_version by  doxygen 1.5.1