22#include "TGLIncludes.h"
26#include "RConfigure.h"
88 return Create(format, parent, selectInput, shareDefault, shareDevice,
103 std::pair<void *, void *> innerData;
111#elif defined(R__HAS_COCOA)
123 (glw, shareDefault, shareDevice && !shareDefault ? shareDevice->
GetContext() :
nullptr);
125 catch (
const std::exception &)
169 Warning(
"~TGLWidget",
"There are some gl-contexts connected to this gl device"
170 "which have longer lifetime than lifetime of gl-device");
284 struct LayoutCompatible_t {
288 unsigned char fDummy2;
290 unsigned short fDummy4;
291 unsigned short fDummy5;
296 void fill_pfd(PIXELFORMATDESCRIPTOR *pfd,
const TGLFormat &request)
298 pfd->nSize =
sizeof(PIXELFORMATDESCRIPTOR);
300 pfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
302 pfd->dwFlags |= PFD_DOUBLEBUFFER;
303 pfd->iPixelType = PFD_TYPE_RGBA;
304 pfd->cColorBits = 24;
306 pfd->cAccumBits = acc;
308 pfd->cDepthBits = depth;
310 pfd->cStencilBits = stencil;
313 void check_pixel_format(
Int_t pixIndex, HDC hDC,
TGLFormat &request)
315 PIXELFORMATDESCRIPTOR pfd = {};
317 if (!DescribePixelFormat(hDC, pixIndex,
sizeof pfd, &pfd)) {
318 Warning(
"TGLContext::SetContext",
"DescribePixelFormat failed");
328 if (pfd.cStencilBits)
347 std::pair<void *, void *>& innerData)
350 innerData.second = (
void*)(
Longptr_t)widx;
352 gVirtualX->ResizeWindow(win, width, height);
363 Error(
"TGLWidget::SetFormat",
"Sorry, you should not call this function");
367 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%zx)->SetFormat()", (
size_t)
this));
373 LayoutCompatible_t *trick =
374 reinterpret_cast<LayoutCompatible_t *
>(
GetId());
375 HWND hWND = *trick->fPHwnd;
376 HDC hDC = GetWindowDC(hWND);
379 Error(
"TGLWidget::SetFormat",
"GetWindowDC failed");
380 throw std::runtime_error(
"GetWindowDC failed");
383 static bool wgl_init =
false;
386 int version = gladLoaderLoadWGL(hDC);
388 Warning(
"TGLWidget::SetFormat",
"WGL initalization failed.");
390 Info(
"TGLWidget::SetFormat",
"WGL initalization successful.");
393 const Rgl::TGuardBase &dcGuard =
Rgl::make_guard(ReleaseDC, hWND, hDC);
394 PIXELFORMATDESCRIPTOR pfd = {};
397 if (
const Int_t pixIndex = ChoosePixelFormat(hDC, &pfd)) {
398 check_pixel_format(pixIndex, hDC,
fGLFormat);
400 if (!SetPixelFormat(hDC, pixIndex, &pfd)) {
401 Error(
"TGLWidget::SetFormat",
"SetPixelFormat failed");
402 throw std::runtime_error(
"SetPixelFormat failed");
405 Error(
"TGLWidget::SetFormat",
"ChoosePixelFormat failed");
406 throw std::runtime_error(
"ChoosePixelFormat failed");
410#elif defined(R__HAS_COCOA)
419 std::pair<void *, void *>& )
421 typedef std::pair<UInt_t, Int_t> component_type;
423 std::vector<component_type>formatComponents;
434 formatComponents.push_back(component_type(
Rgl::kStereo, 0));
438 return gVirtualX->CreateOpenGLWindow(parent->
GetId(), width, height, formatComponents);
455 void fill_format(std::vector<Int_t> &format,
const TGLFormat &request)
457 format.push_back(GLX_RGBA);
458 format.push_back(GLX_RED_SIZE);
460 format.push_back(GLX_GREEN_SIZE);
462 format.push_back(GLX_BLUE_SIZE);
466 format.push_back(GLX_DOUBLEBUFFER);
469 format.push_back(GLX_DEPTH_SIZE);
474 format.push_back(GLX_STENCIL_SIZE);
479 format.push_back(GLX_ACCUM_RED_SIZE);
481 format.push_back(GLX_ACCUM_GREEN_SIZE);
483 format.push_back(GLX_ACCUM_BLUE_SIZE);
488 format.push_back(GLX_STEREO);
493 format.push_back(GLX_SAMPLE_BUFFERS_ARB);
495 format.push_back(GLX_SAMPLES_ARB);
499 format.push_back(None);
512 std::pair<void *, void *>& innerData)
514 std::vector<Int_t> glxfmt;
515 fill_format(glxfmt, format);
517 Display *dpy =
reinterpret_cast<Display *
>(
gVirtualX->GetDisplay());
519 ::Error(
"TGLWidget::CreateWindow",
"Display is not set!");
520 throw std::runtime_error(
"Display is not set!");
523 static std::atomic<bool> s_glx_init_done =
false;
524 bool glx_init =
false;
525 if (s_glx_init_done.compare_exchange_strong(glx_init,
true)) {
526 int version = gladLoaderLoadGLX(dpy, DefaultScreen(dpy));
528 ::Warning(
"TGLWidget::CreateWindow",
"GLX initalization failed.");
530 ::Info(
"TGLWidget::CreateWindow",
"GLX initalization successful.");
533 XVisualInfo *visInfo = glXChooseVisual(dpy, DefaultScreen(dpy), &glxfmt[0]);
536 ::Error(
"TGLWidget::CreateWindow",
"No good OpenGL visual found!");
537 throw std::runtime_error(
"No good OpenGL visual found!");
543 attr.colormap = XCreateColormap(dpy, winID, visInfo->visual, AllocNone);
544 attr.background_pixel = 0;
545 attr.event_mask = NoEventMask;
546 attr.backing_store = Always;
547 attr.bit_gravity = NorthWestGravity;
549 ULong_t mask = CWBackPixel | CWColormap | CWEventMask | CWBackingStore | CWBitGravity;
550 Window glWin = XCreateWindow(dpy, winID, 0, 0, width, height, 0,
552 InputOutput, visInfo->visual, mask, &attr);
554 innerData.first = dpy;
555 innerData.second = visInfo;
591 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%zx)->HandleCrossing((Event_t *)0x%zx)", (
size_t)
this, (
size_t)ev));
612 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%zx)->HandleButton((Event_t *)0x%zx)", (
size_t)
this, (
size_t)ev));
628 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%zx)->HandleDoubleClick((Event_t *)0x%zx)", (
size_t)
this, (
size_t)ev));
644 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%zx)->HandleConfigureNotify((Event_t *)0x%zx)", (
size_t)
this, (
size_t)ev));
663 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%zx)->HandleFocusChange((Event_t *)0x%zx)", (
size_t)
this, (
size_t)ev));
679 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%zx)->HandleKey((Event_t *)0x%zx)", (
size_t)
this, (
size_t)ev));
695 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%zx)->HandleMotion((Event_t *)0x%zx)", (
size_t)
this, (
size_t)ev));
const Mask_t kFocusChangeMask
const Mask_t kButtonPressMask
const Mask_t kExposureMask
const Mask_t kKeyReleaseMask
const Mask_t kAnyModifier
const Mask_t kKeyPressMask
const Mask_t kPointerMotionMask
const Mask_t kLeaveWindowMask
const Mask_t kStructureNotifyMask
const Mask_t kButtonReleaseMask
const Mask_t kEnterWindowMask
Handle_t Window_t
Window handle.
int Int_t
Signed integer 4 bytes (int).
long Longptr_t
Integer large enough to hold a pointer (platform-dependent).
unsigned long ULongptr_t
Unsigned integer large enough to hold a pointer (platform-dependent).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
bool Bool_t
Boolean (0=false, 1=true) (bool).
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
externTVirtualMutex * gROOTMutex
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
#define R__LOCKGUARD(mutex)
virtual Bool_t HandleConfigureNotify(Event_t *event)
This event is generated when the frame is resized.
TGFrame(const TGFrame &)=delete
virtual const TGLContext * GetContext() const =0
static void InitializeIfNeeded()
Initialize globals that require other libraries to be initialized.
ROOT GUI Window base class.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
TOneArgGuard< Func, Arg > make_guard(Func f, Arg a)
EGEventType fType
of event (see EGEventType)