26#include "RConfigure.h"
27#include "TGLIncludes.h"
63 gROOT->ProcessLineFast(
Form(
"((TGLContext *)0x%zx)->SetContext((TGLWidget *)0x%zx, (TGLContext *)0x%zx)",
64 (
size_t)
this, (
size_t)
wid, (
size_t)shareList));
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");
151 fPimpl->fGLContext = glContext;
153 Error(
"TGLContext::SetContext",
"wglCreateContext failed");
154 throw std::runtime_error(
"wglCreateContext failed");
172 Error(
"TGLContext::MakeCurrent",
"This context is invalid.");
177 return Bool_t(
gROOT->ProcessLineFast(
Form(
"((TGLContext *)0x%zx)->MakeCurrent()", (
size_t)
this)));
197 return wglMakeCurrent(0, 0);
207 Error(
"TGLContext::SwapBuffers",
"This context is invalid.");
212 gROOT->ProcessLineFast(
Form(
"((TGLContext *)0x%zx)->SwapBuffers()", (
size_t)
this));
218 wglSwapLayerBuffers(
fPimpl->fHDC, WGL_SWAP_MAIN_PLANE);
231 gROOT->ProcessLineFast(
Form(
"((TGLContext *)0x%zx)->Release()", (
size_t)
this));
241 wglDeleteContext(
fPimpl->fGLContext);
245#elif defined(R__HAS_COCOA)
253 Error(
"TGLContext::SetContext",
"SetContext must be called only from ctor");
274 Error(
"TGLContext::MakeCurrent",
"This context is invalid.");
304 Error(
"TGLContext::SwapBuffers",
"This context is invalid.");
333 Error(
"TGLContext::SetContext",
"SetContext must be called only from ctor");
337 fPimpl = std::make_unique<TGLContextPrivate>();
338 Display *dpy =
static_cast<Display *
>(widget->
GetInnerData().first);
341 GLXContext glCtx = shareList ? glXCreateContext(dpy, visInfo, shareList->
fPimpl->fGLContext, True)
342 : glXCreateContext(dpy, visInfo, None, True);
345 Error(
"TGLContext::SetContext",
"glXCreateContext failed!");
346 throw std::runtime_error(
"glXCreateContext failed!");
350 fPimpl->fVisualInfo = visInfo;
351 fPimpl->fGLContext = glCtx;
366 Error(
"TGLContext::MakeCurrent",
"This context is invalid.");
370 if (
fPimpl->fWindowID != 0) {
389 return glXMakeCurrent(
fPimpl->fDpy, None,
nullptr);
399 Error(
"TGLContext::SwapCurrent",
"This context is invalid.");
403 if (
fPimpl->fWindowID != 0)
473fFontManager(nullptr), fCnt(0), fClientCnt(0)
491 fCtxs.push_back(ctx);
499 CtxList_t::iterator i = std::find(
fCtxs.begin(),
fCtxs.end(), ctx);
500 if (i !=
fCtxs.end())
508 Error(
"TGLContextIdentity::Release",
"unregistered context.");
528 glDeleteLists(it->first, it->second);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize wid
R__EXTERN TVirtualMutex * gROOTMutex
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
#define R__LOCKGUARD(mutex)
Identifier of a shared GL-context.
virtual ~TGLContextIdentity()
Destructor.
static TGLContextIdentity * GetDefaultIdentity()
Get identity of a default Gl context. Static.
void CheckDestroy()
Private function called when reference count is reduced.
TGLContextIdentity()
Constructor.
std::pair< UInt_t, Int_t > DLRange_t
TGLFontManager * fFontManager
static TGLContextIdentity * fgDefaultIdentity
void DeleteGLResources()
Delete GL resources registered for destruction.
void Release(TGLContext *ctx)
Remove context ctx from the list of references.
DLTrash_t::const_iterator DLTrashIt_t
static TGLContextIdentity * GetCurrent()
Find identitfy of current context. Static.
TGLFontManager * GetFontManager()
Get the free-type font-manager associated with this context-identity.
void AddRef(TGLContext *ctx)
Add context ctx to the list of references.
void RegisterDLNameRangeToWipe(UInt_t base, Int_t size)
Remember dl range for deletion in next MakeCurrent or dtor execution.
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 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 ...
void Release()
Make the context invalid and (do thread switch, if needed) free resources.
void SwapBuffers()
If context is valid (TGLPaintDevice, for which context was created still exists), swap buffers (in ca...
TGLContextIdentity * GetIdentity() const
We can have several shared contexts, and gl-scene wants to know, if some context (defined by its iden...
static Bool_t fgGlewInitDone
std::unique_ptr< TGLContextPrivate > fPimpl
TGLContext(TGLWidget *glWidget, Bool_t shareDefault=kTRUE, const TGLContext *shareList=nullptr)
TGLContext ctor "from" TGLWidget.
virtual ~TGLContext()
TGLContext dtor.
Bool_t MakeCurrent()
If context is valid (TGLPaintDevice, for which context was created still exists), make it current.
void SetContext(TGLWidget *widget, const TGLContext *shareList)
X11 gl-context creation.
static void GlewInit()
Initialize GLEW - static private function.
Bool_t ClearCurrent()
Reset current context.
TGLContextIdentity * fIdentity
static TGLContext * GetCurrent()
Ask TGLContextPrivate to lookup context in its internal map.
A FreeType GL font manager.
void ClearFontTrash()
Delete FTFFont objects registered for destruction.
virtual void AddContext(TGLContext *ctx)=0
virtual void RemoveContext(TGLContext *ctx)=0
TOneArgGuard< Func, Arg > make_guard(Func f, Arg a)