Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
16 void TGLContextPrivate::RegisterContext(TGLContext *ctx)
17 {
18  if (ctx->IsValid())
19  fgContexts[ctx->fPimpl->fGLContext] = ctx;
20 }
21 
22 ////////////////////////////////////////////////////////////////////////////////
23 ///Un-register deleted context.
24 
25 void TGLContextPrivate::RemoveContext(TGLContext *ctx)
26 {
27  if (ctx->IsValid())
28  fgContexts.erase(ctx->fPimpl->fGLContext);
29 }
30 
31 #ifdef WIN32
32 
33 std::map<HGLRC, TGLContext *> TGLContextPrivate::fgContexts;
34 
35 ////////////////////////////////////////////////////////////////////////////////
36 ///Ask wgl what HGLRC is current and look up corresponding TGLContext.
37 
38 TGLContext *TGLContextPrivate::GetCurrentContext()
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 
51 std::map<Handle_t, TGLContext *> TGLContextPrivate::fgContexts;
52 
53 ////////////////////////////////////////////////////////////////////////////////
54 
55 TGLContext *TGLContextPrivate::GetCurrentContext()
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 
69 std::map<GLXContext, TGLContext *> TGLContextPrivate::fgContexts;
70 
71 ////////////////////////////////////////////////////////////////////////////////
72 ///Ask wgl what HGLRC is current and look up corresponding TGLContext.
73 
74 TGLContext *TGLContextPrivate::GetCurrentContext()
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