30 #include "gdk/win32/gdkwin32.h"
38 struct TGWin32GLManager::TGLContext {
68 CDCGuard(
const CDCGuard &);
72 explicit CDCGuard(HDC hDC) : fHDC(hDC)
91 WDCGuard(
const WDCGuard &);
95 WDCGuard(HDC hDC,
Window_t winID) : fHDC(hDC), fWinID(winID)
100 ReleaseDC((HWND)GDK_DRAWABLE_XID((GdkWindow *)fWinID), fHDC);
113 BMPGuard(
const BMPGuard &);
117 explicit BMPGuard(HBITMAP bmp) : fBMP(bmp)
135 WGLGuard(
const WGLGuard &);
139 explicit WGLGuard(HGLRC glrc) : fCtx(glrc)
144 wglDeleteContext(fCtx);
153 const PIXELFORMATDESCRIPTOR
173 const PIXELFORMATDESCRIPTOR
192 class TGWin32GLManager::TGWin32GLImpl {
194 TGWin32GLImpl() : fNextFreeContext(0)
197 std::deque<TGLContext> fGLContexts;
201 TGWin32GLManager::TGWin32GLImpl::~TGWin32GLImpl()
204 std::deque<TGLContext>::size_type i = 0;
206 for (; i < fGLContexts.size(); ++i) {
209 if (ctx.fGLContext) {
211 ::Warning(
"TGWin32GLManager::~TGLWin32GLManager",
"You forget to destroy gl-context %d\n", i);
213 if (ctx.fPixmapIndex != -1) {
214 gVirtualX->SelectWindow(ctx.fPixmapIndex);
218 wglDeleteContext(ctx.fGLContext);
219 ReleaseDC((HWND)GDK_DRAWABLE_XID((GdkWindow *)
gVirtualX->GetWindowID(ctx.fWindowIndex)),
232 gROOT->GetListOfSpecials()->AddLast(
this);
257 HDC hDC = GetWindowDC((HWND)GDK_DRAWABLE_XID((GdkWindow *)winID));
260 Error(
"CreateGLContext",
"GetWindowDC failed\n");
264 WDCGuard dcGuard(hDC, winID);
268 HGLRC glCtx = wglCreateContext(hDC);
271 Error(
"CreateGLContext",
"wglCreateContext failed\n");
275 TGLContext newDevice = {winInd, -1, hDC, 0, glCtx};
276 PIXELFORMATDESCRIPTOR testFormat = {};
277 DescribePixelFormat(hDC, pixFormat,
sizeof testFormat, &testFormat);
278 newDevice.fHighColor = testFormat.cColorBits < 24 ?
kTRUE :
kFALSE;
280 if (TGLContext *ctx =
fPimpl->fNextFreeContext) {
281 Int_t ind = ctx->fWindowIndex;
282 fPimpl->fNextFreeContext =
fPimpl->fNextFreeContext->fNextFreeContext;
287 WGLGuard wglGuard(glCtx);
288 fPimpl->fGLContexts.push_back(newDevice);
291 return fPimpl->fGLContexts.size() - 1;
294 Error(
"CreateGLContext",
"SetPixelFormat failed\n");
296 Error(
"CreateGLContext",
"ChoosePixelFormat failed\n");
306 HDC dibDC = CreateCompatibleDC(0);
309 Error(
"CreateDIB",
"CreateCompatibleDC failed\n");
313 CDCGuard dcGuard(dibDC);
315 BITMAPINFOHEADER bmpHeader = {
sizeof bmpHeader, ctx.fW, ctx.fH, 1, 32, BI_RGB};
317 HBITMAP hDIB = CreateDIBSection(dibDC, (BITMAPINFO*)&bmpHeader, DIB_RGB_COLORS, &bmpCnt, 0, 0);
320 Error(
"CreateDIB",
"CreateDIBSection failed\n");
324 BMPGuard bmpGuard(hDIB);
328 ctx.fDIBData =
static_cast<UChar_t *
>(bmpCnt);
339 TGLContext &ctx =
fPimpl->fGLContexts[ctxInd];
340 TGLContext newCtx = {ctx.fWindowIndex, -1, ctx.fDC, 0, ctx.fGLContext, w,
h,
x,
y, ctx.fHighColor};
355 TGLContext &ctx =
fPimpl->fGLContexts[ctxInd];
357 if (ctx.fPixmapIndex != -1)
359 TGLContext newCtx = {ctx.fWindowIndex, -1, ctx.fDC, 0, ctx.fGLContext, w,
h,
x,
y, ctx.fHighColor};
362 gVirtualX->SelectWindow(ctx.fPixmapIndex);
366 Error(
"ResizeOffScreenDevice",
"Error trying to create new DIB\n");
388 if (
fPimpl->fGLContexts[pixInd].fPixmapIndex != -1)
389 fPimpl->fGLContexts[pixInd].fDirect = isDirect;
396 TGLContext &ctx =
fPimpl->fGLContexts[ctxInd];
398 if (ctx.fPixmapIndex != -1) {
399 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
400 glReadBuffer(GL_BACK);
401 glReadPixels(0, 0, ctx.fW, ctx.fH, GL_BGRA_EXT, GL_UNSIGNED_BYTE, ctx.fDIBData);
409 return fPimpl->fGLContexts[ctxInd].fPixmapIndex;
416 TGLContext &ctx =
fPimpl->fGLContexts[ctxInd];
417 return (
Bool_t)wglMakeCurrent(ctx.fDC, ctx.fGLContext);
424 TGLContext &ctx =
fPimpl->fGLContexts[ctxInd];
426 if (ctx.fPixmapIndex == -1) {
428 wglSwapLayerBuffers(ctx.fDC, WGL_SWAP_MAIN_PLANE);
429 }
else if (ctx.fDirect) {
431 HDC hDC = CreateCompatibleDC(0);
434 Error(
"Flush",
"CreateCompatibleDC failed\n");
438 HBITMAP oldDIB = (HBITMAP)SelectObject(hDC, ctx.fHBitmap);
440 if (!BitBlt(ctx.fDC, ctx.fX, ctx.fY, ctx.fW, ctx.fH, hDC, 0, 0, SRCCOPY))
443 SelectObject(hDC, oldDIB);
453 TGLContext &ctx =
fPimpl->fGLContexts[ctxInd];
455 if (ctx.fPixmapIndex != -1) {
456 gVirtualX->SelectWindow(ctx.fPixmapIndex);
458 ctx.fPixmapIndex = -1;
461 wglDeleteContext(ctx.fGLContext);
463 ReleaseDC((HWND)GDK_DRAWABLE_XID((GdkWindow *)
gVirtualX->GetWindowID(ctx.fWindowIndex)),
466 ctx.fWindowIndex = ctxInd;
467 ctx.fNextFreeContext =
fPimpl->fNextFreeContext;
468 fPimpl->fNextFreeContext = &ctx;
475 TGLContext &ctx =
fPimpl->fGLContexts[ctxInd];
477 if (ctx.fPixmapIndex != -1) {
480 viewport[2] = ctx.fW;
481 viewport[3] = ctx.fH;
503 return manip->
Select(*camera, *rect, *sceneBox);
534 return fPimpl->fGLContexts[ctxInd].fHighColor;
char * GetPlotInfo(TVirtualGLPainter *plot, Int_t px, Int_t py)
Int_t GetVirtualXInd(Int_t devInd)
Abstract base camera class - concrete classes for orthographic and perspective cameras derive from it...
void DeleteGLContext(Int_t devInd)
void MarkForDirectCopy(Int_t devInd, Bool_t)
Int_t CreateGLContext(Int_t winInd)
winInd is TGWin32 index, returned by previous call gGLManager->InitGLWindow returns descripto (index)...
virtual Bool_t Select(const TGLCamera &camera, const TGLRect &rect, const TGLBoundingBox &sceneBox)=0
void ExtractViewport(Int_t devInd, Int_t *vp)
Int_t InitGLWindow(Window_t winID)
virtual char * GetPlotInfo(Int_t px, Int_t py)=0
virtual Bool_t PlotSelected(Int_t px, Int_t py)=0
static TGLManager * ProxyObject()
Bool_t AttachOffScreenDevice(Int_t ctxInd, Int_t x, Int_t y, UInt_t w, UInt_t h)
Bool_t ResizeOffScreenDevice(Int_t devInd, Int_t x, Int_t y, UInt_t w, UInt_t h)
Create new DIB if needed.
Viewport (pixel base) 2D rectangle class.
Bool_t HighColorFormat(Int_t ctx)
Abstract 3D shapes viewer.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
void PrintViewer(TVirtualViewer3D *vv)
Bool_t CreateDIB(TGLContext &ctx) const
Create DIB section to read GL buffer into.
ClassImp(TGWin32GLManager) TGWin32GLManager
Bool_t MakeCurrent(Int_t devInd)
Bool_t PlotSelected(TVirtualGLPainter *plot, Int_t px, Int_t py)
void Warning(const char *location, const char *msgfmt,...)
void SelectOffScreenDevice(Int_t devInd)
virtual void Pan(Int_t px, Int_t py)=0
R__EXTERN TGLManager *(* gPtr2GLManager)()
const PIXELFORMATDESCRIPTOR doubleBufferDesc
This class encapsulates window-system specific information about a GL-context and alows their proper ...
Bool_t SelectManip(TVirtualGLManip *manip, const TGLCamera *camera, const TGLRect *rect, const TGLBoundingBox *sceneBox)
const PIXELFORMATDESCRIPTOR singleScreenDesc
Binding & operator=(OUT(*fun)(void))
Concrete class describing an orientated (free) or axis aligned box of 8 vertices. ...
void ReadGLBuffer(Int_t devInd)
void PanObject(TVirtualGLPainter *o, Int_t x, Int_t y)
virtual void PrintObjects()
void PaintSingleObject(TVirtualGLPainter *)