Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLContextPrivate.cxx
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Timur Pocheptsov, Jun 2007
3
4#include "TGLContextPrivate.h"
5
6#ifdef R__HAS_COCOA
7#include <cassert>
8
9#include "TVirtualX.h"
10#include "TError.h"
11#endif
12
13////////////////////////////////////////////////////////////////////////////////
14///Register gl-context to find it later as current (GetCurrentContext)
15
17{
18 if (ctx->IsValid())
19 fgContexts[ctx->fPimpl->fGLContext] = ctx;
20}
21
22////////////////////////////////////////////////////////////////////////////////
23///Un-register deleted context.
24
26{
27 if (ctx->IsValid())
28 fgContexts.erase(ctx->fPimpl->fGLContext);
29}
30
31#ifdef WIN32
32
33std::map<HGLRC, TGLContext *> TGLContextPrivate::fgContexts;
34
35////////////////////////////////////////////////////////////////////////////////
36///Ask wgl what HGLRC is current and look up corresponding TGLContext.
37
39{
40 HGLRC glContext = wglGetCurrentContext();
41 std::map<HGLRC, TGLContext *>::const_iterator it = fgContexts.find(glContext);
42
43 if (it != fgContexts.end())
44 return it->second;
45
46 return 0;
47}
48
49#elif defined(R__HAS_COCOA)
50
51std::map<Handle_t, TGLContext *> TGLContextPrivate::fgContexts;
52
53////////////////////////////////////////////////////////////////////////////////
54
56{
57 const Handle_t ctxID = gVirtualX->GetCurrentOpenGLContext();
58 if (ctxID) {
59 assert(fgContexts.find(ctxID) != fgContexts.end() && "GetCurrentContext, context id is unknown");
60 return fgContexts[ctxID];
61 }
62
63 //Else part - error message was issued already by TGCocoa.
64 return 0;
65}
66
67#else
68
69std::map<GLXContext, TGLContext *> TGLContextPrivate::fgContexts;
70
71////////////////////////////////////////////////////////////////////////////////
72///Ask wgl what HGLRC is current and look up corresponding TGLContext.
73
75{
76 GLXContext glContext = glXGetCurrentContext();
77 std::map<GLXContext, TGLContext *>::const_iterator it = fgContexts.find(glContext);
78
79 if (it != fgContexts.end())
80 return it->second;
81
82 return 0;
83}
84
85#endif
ULong_t Handle_t
Generic resource handle.
Definition GuiTypes.h:26
#define gVirtualX
Definition TVirtualX.h:338
static std::map< GLXContext, TGLContext * > fgContexts
static void RegisterContext(TGLContext *ctx)
Register gl-context to find it later as current (GetCurrentContext)
static void RemoveContext(TGLContext *ctx)
Un-register deleted context.
static TGLContext * GetCurrentContext()
Ask wgl what HGLRC is current and look up corresponding TGLContext.
This class encapsulates window-system specific information about a GL-context and alows their proper ...
Definition TGLContext.h:31
std::unique_ptr< TGLContextPrivate > fPimpl
Definition TGLContext.h:38
Bool_t IsValid() const
Definition TGLContext.h:65