61 typedef std::deque<TX11GLManager::TGLContext_t> DeviceTable_t;
62 typedef DeviceTable_t::size_type SizeType_t;
63 typedef std::map<Int_t, XVisualInfo *> WinTable_t;
73 TX11PixGuard(Display *dpy, Pixmap pix) : fDpy(dpy), fPix(pix) {}
74 ~TX11PixGuard(){
if (fPix) XFreePixmap(fDpy, fPix);}
75 void Stop(){fPix = 0;}
78 TX11PixGuard(
const TX11PixGuard &) =
delete;
79 TX11PixGuard &
operator = (
const TX11PixGuard &) =
delete;
89 TGLXCtxGuard(Display *dpy, GLXContext ctx) : fDpy(dpy), fCtx(ctx) {}
90 ~TGLXCtxGuard(){
if (fCtx) glXDestroyContext(fDpy, fCtx);}
91 void Stop(){fCtx =
nullptr;}
94 TGLXCtxGuard(
const TGLXCtxGuard &) =
delete;
95 TGLXCtxGuard &
operator = (
const TGLXCtxGuard &) =
delete;
103 TXImageGuard(
const TXImageGuard &) =
delete;
104 TXImageGuard &
operator = (
const TXImageGuard &) =
delete;
107 explicit TXImageGuard(XImage *im) : fImage(im) {}
108 ~TXImageGuard(){
if (fImage) XDestroyImage(fImage);}
109 void Stop(){fImage =
nullptr;}
166 ::Warning(
"TX11GLManager::~TX11GLManager",
"opengl device with index %ld was not destroyed", (
Long_t)i);
186 gROOT->GetListOfSpecials()->
Add(
this);
210 Error(
"InitGLWindow",
"No good visual found!\n");
217 XGetGeometry(
fPimpl->fDpy, winID, &root, &
x, &
y, &w, &
h, &
b, &
d);
220 attr.colormap = XCreateColormap(
fPimpl->fDpy, root, visInfo->visual, AllocNone);
221 attr.event_mask = NoEventMask;
222 attr.backing_store = Always;
223 attr.bit_gravity = NorthWestGravity;
225 ULong_t mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWBackingStore | CWBitGravity;
228 Window glWin = XCreateWindow(
231 0, visInfo->depth, InputOutput,
232 visInfo->visual, mask, &attr
236 XMapWindow(
fPimpl->fDpy, glWin);
242 fPimpl->fGLWindows[x11Ind] = visInfo;
254 GLXContext glxCtx = glXCreateContext(
fPimpl->fDpy,
fPimpl->fGLWindows[winInd], None, True);
257 Error(
"CreateContext",
"glXCreateContext failed\n");
263 Int_t ind = ctx->fWindowIndex;
264 ctx->fWindowIndex = winInd;
265 ctx->fGLXContext = glxCtx;
266 fPimpl->fNextFreeContext =
fPimpl->fNextFreeContext->fNextFreeContext;
269 TGLXCtxGuard glxCtxGuard(
fPimpl->fDpy, glxCtx);
274 fPimpl->fGLContexts.push_back(newDev);
301 glXSwapBuffers(
fPimpl->fDpy, winID);
307 Error(
"Flush",
"XCreateGC failed while copying pixmap\n");
327 Error(
"CreateGLPixmap",
"XCreatePixmap failed\n");
331 TX11PixGuard pixGuard(
fPimpl->fDpy, x11Pix);
335 XImage *testIm = XCreateImage(
fPimpl->fDpy, visInfo->visual, visInfo->depth, ZPixmap,
336 0,
nullptr, ctx.
fW, ctx.
fH,
337 visInfo->depth <= 8 ? 8 : (visInfo->depth <= 16 ? 16 : 32), 0);
340 TXImageGuard imGuard(testIm);
341 testIm->data =
static_cast<Char_t *
>(
malloc(testIm->bytes_per_line * testIm->height));
344 Error(
"CreateGLPixmap",
"Cannot malloc XImage data\n");
348 if (XInitImage(testIm)) {
350 ctx.
fBUBuffer.resize(testIm->bytes_per_line * testIm->height);
357 Error(
"CreateGLPixmap",
"XInitImage error!\n");
359 Error(
"CreateGLPixmap",
"XCreateImage error!\n");
374 newCtx.
fW = w, newCtx.
fH =
h, newCtx.
fX =
x, newCtx.
fY =
y;
403 newCtx.
fW = w, newCtx.
fH =
h, newCtx.
fX =
x, newCtx.
fY =
y;
418 Error(
"ResizeOffScreenDevice",
"Resize failed\n");
443 if (
fPimpl->fGLContexts[ctxInd].fPixmapIndex != -1)
444 fPimpl->fGLContexts[ctxInd].fDirect = dir;
458 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
459 glReadBuffer(GL_BACK);
467 char *dest = ctx.
fXImage->data;
470 memcpy(dest, src, ctx.
fW * 4);
476 Error(
"ReadGLBuffer",
"XCreateGC error while attempt to copy XImage\n");
508 fPimpl->fNextFreeContext = &ctx;
518 return fPimpl->fGLContexts[ctxInd].fPixmapIndex;
532 viewport[2] = ctx.
fW;
533 viewport[3] = ctx.
fH;
560 return manip->
Select(*camera, *rect, *sceneBox);
Handle_t Window_t
Window handle.
int Int_t
Signed integer 4 bytes (int).
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char).
char Char_t
Character 1 byte (char).
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.
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
bool Bool_t
Boolean (0=false, 1=true) (bool).
Binding & operator=(OUT(*fun)(void))
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
Viewport (pixel base) 2D rectangle 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 Bool_t Select(const TGLCamera &camera, const TGLRect &rect, const TGLBoundingBox &sceneBox)=0
virtual Bool_t PlotSelected(Int_t px, Int_t py)=0
virtual char * GetPlotInfo(Int_t px, Int_t py)=0
virtual void Pan(Int_t px, Int_t py)=0
Abstract 3D shapes viewer.
virtual void PrintObjects()
DeviceTable_t fGLContexts
TX11GLImpl(const TX11GLImpl &)=delete
TGLContext_t * fNextFreeContext
TX11GLImpl & operator=(const TX11GLImpl &)=delete
void PanObject(TVirtualGLPainter *o, Int_t x, Int_t y) override
Pan objects.
Int_t InitGLWindow(Window_t winID) override
Try to find correct visual.
~TX11GLManager() override
Destructor.
char * GetPlotInfo(TVirtualGLPainter *plot, Int_t px, Int_t py) override
Analog of TObject::GetObjectInfo.
void ReadGLBuffer(Int_t devInd) override
GL buffer is read info buffer, after that lines are reordered into XImage, XImage copied into pixmap.
void SelectOffScreenDevice(Int_t devInd) override
Selects off-screen device to make it accessible by gVirtualX.
void Flush(Int_t ctxInd) override
Swaps buffers or copy pixmap.
Bool_t AttachOffScreenDevice(Int_t ctxInd, Int_t x, Int_t y, UInt_t w, UInt_t h) override
Attach off screen device.
void DeleteGLContext(Int_t devInd) override
Deletes GLX context and frees pixmap and image (if any).
void MarkForDirectCopy(Int_t devInd, Bool_t) override
Selection-rotation support for TPad/TCanvas.
Bool_t MakeCurrent(Int_t devInd) override
Make GL context current.
Int_t GetVirtualXInd(Int_t devInd) override
Returns an index suitable for gVirtualX.
Bool_t ResizeOffScreenDevice(Int_t devInd, Int_t x, Int_t y, UInt_t w, UInt_t h) override
Resize off screen device.
Int_t CreateGLContext(Int_t winInd) override
Context creation requires Display * and XVisualInfo (was saved for such winInd).
Bool_t CreateGLPixmap(TGLContext_t &)
Create GL pixmap.
void PrintViewer(TVirtualViewer3D *vv) override
Print viewer.
void PaintSingleObject(TVirtualGLPainter *) override
Paint a single object.
Bool_t PlotSelected(TVirtualGLPainter *plot, Int_t px, Int_t py) override
Analog of TObject::DistancetoPrimitive.
TX11GLManager()
Constructor.
Bool_t SelectManip(TVirtualGLManip *manip, const TGLCamera *camera, const TGLRect *rect, const TGLBoundingBox *sceneBox) override
Select manipulator.
void ExtractViewport(Int_t devInd, Int_t *vp) override
Returns the current dimensions of a GL pixmap.
TMatrixT< Element > & Add(TMatrixT< Element > &target, Element scalar, const TMatrixT< Element > &source)
Modify addition: target += scalar * source.
TGLContext_t * fNextFreeContext
std::vector< UChar_t > fBUBuffer