25 #include "RConfigure.h"
63 gROOT->ProcessLineFast(
Form(
"((TGLContext *)0x%lx)->SetContext((TGLWidget *)0x%lx, (TGLContext *)0x%lx)",
90 GLenum
status = glewInit();
91 if (status != GLEW_OK)
92 Warning(
"TGLContext::GlewInit",
"GLEW initalization failed.");
94 Info(
"TGLContext::GlewInit",
"GLEW initalization successful.");
105 struct LayoutCompatible_t {
109 unsigned char fDummy2;
111 unsigned short fDummy4;
112 unsigned short fDummy5;
127 Error(
"TGLContext::SetContext",
"SetContext must be called only from ctor");
132 LayoutCompatible_t *trick =
133 reinterpret_cast<LayoutCompatible_t *
>(widget->
GetId());
134 HWND hWND = *trick->fPHwnd;
135 HDC hDC = GetWindowDC(hWND);
138 Error(
"TGLContext::SetContext",
"GetWindowDC failed");
139 throw std::runtime_error(
"GetWindowDC failed");
143 if (HGLRC glContext = wglCreateContext(hDC)) {
144 if (shareList && !wglShareLists(shareList->
fPimpl->
fGLContext, glContext)) {
145 wglDeleteContext(glContext);
146 Error(
"TGLContext::SetContext",
"Context sharing failed!");
147 throw std::runtime_error(
"Context sharing failed");
153 Error(
"TGLContext::SetContext",
"wglCreateContext failed");
154 throw std::runtime_error(
"wglCreateContext failed");
173 Error(
"TGLContext::MakeCurrent",
"This context is invalid.");
178 return Bool_t(
gROOT->ProcessLineFast(
Form(
"((TGLContext *)0x%lx)->MakeCurrent()",
this)));
198 return wglMakeCurrent(0, 0);
208 Error(
"TGLContext::SwapBuffers",
"This context is invalid.");
213 gROOT->ProcessLineFast(
Form(
"((TGLContext *)0x%lx)->SwapBuffers()",
this));
219 wglSwapLayerBuffers(
fPimpl->fHDC, WGL_SWAP_MAIN_PLANE);
232 gROOT->ProcessLineFast(
Form(
"((TGLContext *)0x%lx)->Release()",
this));
246 #elif defined(R__HAS_COCOA)
254 Error(
"TGLContext::SetContext",
"SetContext must be called only from ctor");
277 Error(
"TGLContext::MakeCurrent",
"This context is invalid.");
307 Error(
"TGLContext::SwapBuffers",
"This context is invalid.");
336 Error(
"TGLContext::SetContext",
"SetContext must be called only from ctor");
341 Display *dpy =
static_cast<Display *
>(widget->
GetInnerData().first);
342 XVisualInfo *visInfo =
static_cast<XVisualInfo *
>(widget->
GetInnerData().second);
344 GLXContext glCtx = shareList ? glXCreateContext(dpy, visInfo, shareList->
fPimpl->
fGLContext,
True)
345 : glXCreateContext(dpy, visInfo,
None,
True);
348 Error(
"TGLContext::SetContext",
"glXCreateContext failed!");
349 throw std::runtime_error(
"glXCreateContext failed!");
371 Error(
"TGLContext::MakeCurrent",
"This context is invalid.");
404 Error(
"TGLContext::SwapCurrent",
"This context is invalid.");
479 TGLContextIdentity::TGLContextIdentity():
480 fFontManager(0), fCnt(0), fClientCnt(0)
498 fCtxs.push_back(ctx);
506 CtxList_t::iterator i = std::find(
fCtxs.begin(),
fCtxs.end(), ctx);
507 if (i !=
fCtxs.end())
515 Error(
"TGLContextIdentity::Release",
"unregistered context.");
535 glDeleteLists(it->first, it->second);
static TGLContext * GetDefaultContextAny()
Get the first GL context with the default identity.
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 TGLContextIdentity * GetDefaultIdentity()
Get identity of a default Gl context. Static.
std::pair< UInt_t, Int_t > DLRange_t
Identifier of a shared GL-context.
R__EXTERN TVirtualMutex * gROOTMutex
DLTrash_t::const_iterator DLTrashIt_t
virtual void RemoveContext(TGLContext *ctx)=0
TGLContextIdentity * fIdentity
void CheckDestroy()
Private function called when reference count is reduced.
void Release(TGLContext *ctx)
Remove context ctx from the list of references.
XVisualInfo * fVisualInfo
virtual void AddContext(TGLContext *ctx)=0
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
TGLContextIdentity * GetIdentity() const
We can have several shared contexts, and gl-scene wants to know, if some context (defined by its iden...
Bool_t MakeCurrent()
If context is valid (TGLPaintDevice, for which context was created still exists), make it current...
void Info(const char *location, const char *msgfmt,...)
TGLContextPrivate * fPimpl
void Error(const char *location, const char *msgfmt,...)
virtual ~TGLContextIdentity()
Destructor.
static TGLContextIdentity * GetCurrent()
Find identitfy of current context. Static.
TGLContext(TGLWidget *glWidget, Bool_t shareDefault=kTRUE, const TGLContext *shareList=0)
TGLContext ctor "from" TGLWidget.
TGLFontManager * fFontManager
TOneArgGuard< Func, Arg > make_guard(Func f, Arg a)
static TGLContextIdentity * fgDefaultIdentity
char * Form(const char *fmt,...)
void DeleteGLResources()
Delete GL resources registered for destruction.
static TGLContext * GetCurrentContext()
Ask wgl what HGLRC is current and look up corresponding TGLContext.
void Warning(const char *location, const char *msgfmt,...)
static void GlewInit()
Initialize GLEW - static private function.
TGLFontManager * GetFontManager()
Get the free-type font-manager associated with this context-identity.
void SetContext(TGLWidget *widget, const TGLContext *shareList)
X11 gl-context creation.
void SwapBuffers()
If context is valid (TGLPaintDevice, for which context was created still exists), swap buffers (in ca...
This class encapsulates window-system specific information about a GL-context and alows their proper ...
Bool_t ClearCurrent()
Reset current context.
void AddRef(TGLContext *ctx)
Add context ctx to the list of references.
void Release()
Make the context invalid and (do thread switch, if needed) free resources.
static TGLContext * GetCurrent()
Ask TGLContextPrivate to lookup context in its internal map.
A FreeType GL font manager.
static Bool_t fgGlewInitDone
void ClearFontTrash()
Delete FTFFont objects registered for destruction.
void RegisterDLNameRangeToWipe(UInt_t base, Int_t size)
Remember dl range for deletion in next MakeCurrent or dtor execution.
virtual ~TGLContext()
TGLContext dtor.