26 #include "RConfigure.h"
89 return Create(format, parent, selectInput, shareDefault, shareDevice,
104 std::pair<void *, void *> innerData;
112 #elif defined(R__HAS_COCOA)
124 (glw, shareDefault, shareDevice && !shareDefault ? shareDevice->
GetContext() : 0);
126 catch (
const std::exception &)
170 Warning(
"~TGLWidget",
"There are some gl-contexts connected to this gl device"
171 "which have longer lifetime than lifetime of gl-device");
285 struct LayoutCompatible_t {
289 unsigned char fDummy2;
291 unsigned short fDummy4;
292 unsigned short fDummy5;
297 void fill_pfd(PIXELFORMATDESCRIPTOR *pfd,
const TGLFormat &request)
299 pfd->nSize =
sizeof(PIXELFORMATDESCRIPTOR);
301 pfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
303 pfd->dwFlags |= PFD_DOUBLEBUFFER;
304 pfd->iPixelType = PFD_TYPE_RGBA;
305 pfd->cColorBits = 24;
307 pfd->cAccumBits = acc;
309 pfd->cDepthBits = depth;
311 pfd->cStencilBits = stencil;
314 void check_pixel_format(
Int_t pixIndex, HDC hDC,
TGLFormat &request)
316 PIXELFORMATDESCRIPTOR pfd = {};
318 if (!DescribePixelFormat(hDC, pixIndex,
sizeof pfd, &pfd)) {
319 Warning(
"TGLContext::SetContext",
"DescribePixelFormat failed");
329 if (pfd.cStencilBits)
348 std::pair<void *, void *>& innerData)
351 innerData.second = (
void*) widx;
353 gVirtualX->ResizeWindow(win, width, height);
364 Error(
"TGLWidget::SetFormat",
"Sorry, you should not call this function");
368 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%lx)->SetFormat()",
this));
372 LayoutCompatible_t *trick =
373 reinterpret_cast<LayoutCompatible_t *
>(
GetId());
374 HWND hWND = *trick->fPHwnd;
375 HDC hDC = GetWindowDC(hWND);
378 Error(
"TGLWidget::SetFormat",
"GetWindowDC failed");
379 throw std::runtime_error(
"GetWindowDC failed");
383 PIXELFORMATDESCRIPTOR pfd = {};
386 if (
const Int_t pixIndex = ChoosePixelFormat(hDC, &pfd)) {
387 check_pixel_format(pixIndex, hDC,
fGLFormat);
389 if (!SetPixelFormat(hDC, pixIndex, &pfd)) {
390 Error(
"TGLWidget::SetFormat",
"SetPixelFormat failed");
391 throw std::runtime_error(
"SetPixelFormat failed");
394 Error(
"TGLWidget::SetFormat",
"ChoosePixelFormat failed");
395 throw std::runtime_error(
"ChoosePixelFormat failed");
399 #elif defined(R__HAS_COCOA) //MacOSX with Cocoa enabled.
408 std::pair<void *, void *>& )
410 typedef std::pair<UInt_t, Int_t> component_type;
412 std::vector<component_type>formatComponents;
423 formatComponents.push_back(component_type(
Rgl::kStereo, 0));
427 return gVirtualX->CreateOpenGLWindow(parent->
GetId(), width, height, formatComponents);
444 void fill_format(std::vector<Int_t> &format,
const TGLFormat &request)
446 format.push_back(GLX_RGBA);
447 format.push_back(GLX_RED_SIZE);
449 format.push_back(GLX_GREEN_SIZE);
451 format.push_back(GLX_BLUE_SIZE);
455 format.push_back(GLX_DOUBLEBUFFER);
458 format.push_back(GLX_DEPTH_SIZE);
463 format.push_back(GLX_STENCIL_SIZE);
468 format.push_back(GLX_ACCUM_RED_SIZE);
470 format.push_back(GLX_ACCUM_GREEN_SIZE);
472 format.push_back(GLX_ACCUM_BLUE_SIZE);
477 format.push_back(GLX_STEREO);
482 format.push_back(GLX_SAMPLE_BUFFERS_ARB);
484 format.push_back(GLX_SAMPLES_ARB);
488 format.push_back(
None);
501 std::pair<void *, void *>& innerData)
503 std::vector<Int_t> glxfmt;
504 fill_format(glxfmt, format);
506 Display *dpy =
reinterpret_cast<Display *
>(
gVirtualX->GetDisplay());
508 ::Error(
"TGLWidget::CreateWindow",
"Display is not set!");
509 throw std::runtime_error(
"Display is not set!");
511 XVisualInfo *visInfo = glXChooseVisual(dpy, DefaultScreen(dpy), &glxfmt[0]);
514 ::Error(
"TGLWidget::CreateWindow",
"No good OpenGL visual found!");
515 throw std::runtime_error(
"No good OpenGL visual found!");
520 XSetWindowAttributes
attr;
521 attr.colormap = XCreateColormap(dpy, winID, visInfo->visual, AllocNone);
522 attr.background_pixel = 0;
523 attr.event_mask = NoEventMask;
524 attr.backing_store = Always;
525 attr.bit_gravity = NorthWestGravity;
527 ULong_t mask = CWBackPixel | CWColormap | CWEventMask | CWBackingStore | CWBitGravity;
528 Window glWin = XCreateWindow(dpy, winID, 0, 0, width, height, 0,
530 InputOutput, visInfo->visual, mask, &attr);
532 innerData.first = dpy;
533 innerData.second = visInfo;
569 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%lx)->HandleCrossing((Event_t *)0x%lx)", (
ULong_t)
this, (
ULong_t)ev));
590 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%lx)->HandleButton((Event_t *)0x%lx)", (
ULong_t)
this, (
ULong_t)ev));
606 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%lx)->HandleDoubleClick((Event_t *)0x%lx)", (
ULong_t)
this, (
ULong_t)ev));
622 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%lx)->HandleConfigureNotify((Event_t *)0x%lx)", (
ULong_t)
this, (
ULong_t)ev));
641 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%lx)->HandleFocusChange((Event_t *)0x%lx)", (
ULong_t)
this, (
ULong_t)ev));
673 gROOT->ProcessLineFast(
Form(
"((TGLWidget *)0x%lx)->HandleMotion((Event_t *)0x%lx)", (
ULong_t)
this, (
ULong_t)ev));
const Mask_t kKeyReleaseMask
const Mask_t kLeaveWindowMask
R__EXTERN TVirtualMutex * gROOTMutex
static std::string format(double x, double y, int digits, int width)
virtual Bool_t HandleConfigureNotify(Event_t *)
virtual Bool_t HandleButton(Event_t *)
const Mask_t kPointerMotionMask
UChar_t mod R__LOCKGUARD2(gSrvAuthenticateMutex)
virtual Bool_t HandleDoubleClick(Event_t *)
if(pyself &&pyself!=Py_None)
Bool_t MakeCurrent()
If context is valid (TGLPaintDevice, for which context was created still exists), make it current...
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual const TGLContext * GetContext() const =0
const Mask_t kButtonPressMask
const Mask_t kKeyPressMask
virtual Bool_t HandleCrossing(Event_t *)
virtual Bool_t HandleKey(Event_t *)
static void InitializeIfNeeded()
Initialize globals that require other libraries to be initialized.
TOneArgGuard< Func, Arg > make_guard(Func f, Arg a)
virtual Bool_t HandleFocusChange(Event_t *)
const Mask_t kExposureMask
char * Form(const char *fmt,...)
void Warning(const char *location, const char *msgfmt,...)
virtual Bool_t HandleConfigureNotify(Event_t *event)
This event is generated when the frame is resized.
const Mask_t kEnterWindowMask
const Mask_t kStructureNotifyMask
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 ...
const Mask_t kButtonReleaseMask
Bool_t ClearCurrent()
Reset current context.
const Mask_t kFocusChangeMask
virtual Bool_t HandleMotion(Event_t *)
const Mask_t kAnyModifier
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.