diff --git a/src/Aspect/Aspect_FBConfig.hxx b/src/Aspect/Aspect_FBConfig.hxx new file mode 100644 index 0000000000..40cfe92e98 --- /dev/null +++ b/src/Aspect/Aspect_FBConfig.hxx @@ -0,0 +1,24 @@ +// Copyright (c) 2015 OPEN CASCADE SAS +// +// This file is part of Open CASCADE Technology software library. +// +// This library is free software; you can redistribute it and/or modify it under +// the terms of the GNU Lesser General Public License version 2.1 as published +// by the Free Software Foundation, with special exception defined in the file +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT +// distribution for complete text of the license and disclaimer of any warranty. +// +// Alternatively, this file may be used under the terms of Open CASCADE +// commercial license or contractual agreement. + +#ifndef _Aspect_FBConfig_HeaderFile +#define _Aspect_FBConfig_HeaderFile + +#if !defined(_WIN32) && (!defined(__APPLE__) || defined(MACOSX_USE_GLX)) && !defined(__ANDROID__) + typedef struct __GLXFBConfigRec* GLXFBConfig; + typedef GLXFBConfig Aspect_FBConfig; // GLXFBConfig* under UNIX +#else + typedef void* Aspect_FBConfig; // unused on other systems +#endif + +#endif // _Aspect_FBConfig_HeaderFile diff --git a/src/Aspect/Aspect_Window.hxx b/src/Aspect/Aspect_Window.hxx index 690f7b99e5..77e6444df5 100644 --- a/src/Aspect/Aspect_Window.hxx +++ b/src/Aspect/Aspect_Window.hxx @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -113,8 +114,8 @@ public: //! Returns parent of native Window handle (HWND on Windows, Window with Xlib, and so on) Standard_EXPORT virtual Aspect_Drawable NativeParentHandle() const = 0; - - + //! Returns native Window FB config (GLXFBConfig on Xlib) + Standard_EXPORT virtual Aspect_FBConfig NativeFBConfig() const = 0; DEFINE_STANDARD_RTTI(Aspect_Window,MMgt_TShared) diff --git a/src/Aspect/FILES b/src/Aspect/FILES index 458d46b390..3c32b5c075 100755 --- a/src/Aspect/FILES +++ b/src/Aspect/FILES @@ -19,6 +19,7 @@ Aspect_DisplayConnection.hxx Aspect_DisplayConnectionDefinitionError.hxx Aspect_Drawable.hxx Aspect_DriverDefinitionError.hxx +Aspect_FBConfig.hxx Aspect_FillMethod.hxx Aspect_GenId.cxx Aspect_GenId.hxx diff --git a/src/Cocoa/Cocoa_Window.hxx b/src/Cocoa/Cocoa_Window.hxx index 4ab78e18db..0ee8da4ceb 100644 --- a/src/Cocoa/Cocoa_Window.hxx +++ b/src/Cocoa/Cocoa_Window.hxx @@ -87,32 +87,32 @@ public: } //! Opens the window - Standard_EXPORT virtual void Map() const; + Standard_EXPORT virtual void Map() const Standard_OVERRIDE; //! Closes the window - Standard_EXPORT virtual void Unmap() const; + Standard_EXPORT virtual void Unmap() const Standard_OVERRIDE; //! Applies the resizing to the window - Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const; + Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const Standard_OVERRIDE; //! Apply the mapping change to the window - Standard_EXPORT virtual Standard_Boolean DoMapping() const; + Standard_EXPORT virtual Standard_Boolean DoMapping() const Standard_OVERRIDE; //! Returns True if the window is opened - Standard_EXPORT virtual Standard_Boolean IsMapped() const; + Standard_EXPORT virtual Standard_Boolean IsMapped() const Standard_OVERRIDE; //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions - Standard_EXPORT virtual Quantity_Ratio Ratio() const; + Standard_EXPORT virtual Quantity_Ratio Ratio() const Standard_OVERRIDE; //! Returns The Window POSITION in PIXEL Standard_EXPORT virtual void Position (Standard_Integer& X1, Standard_Integer& Y1, Standard_Integer& X2, - Standard_Integer& Y2) const; + Standard_Integer& Y2) const Standard_OVERRIDE; //! Returns The Window SIZE in PIXEL Standard_EXPORT virtual void Size (Standard_Integer& theWidth, - Standard_Integer& theHeight) const; + Standard_Integer& theHeight) const Standard_OVERRIDE; #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE //! @return associated UIView @@ -129,17 +129,20 @@ public: #endif //! @return native Window handle - virtual Aspect_Drawable NativeHandle() const + virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE { return (Aspect_Drawable )HView(); } //! @return parent of native Window handle - virtual Aspect_Drawable NativeParentHandle() const + virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE { return 0; } + //! Returns nothing on OS X + virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE { return NULL; } + protected: #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE diff --git a/src/OpenGl/OpenGl_Window.cxx b/src/OpenGl/OpenGl_Window.cxx index 0572c09893..6a9eb3d85b 100644 --- a/src/OpenGl/OpenGl_Window.cxx +++ b/src/OpenGl/OpenGl_Window.cxx @@ -118,9 +118,37 @@ namespace return DefWindowProcW (theWin, theMsg, theParamW, theParamL); } #else - static Bool WaitForNotify (Display* theDisp, XEvent* theEv, char* theArg) + + // GLX_ARB_create_context +#ifndef GLX_CONTEXT_MAJOR_VERSION_ARB + #define GLX_CONTEXT_DEBUG_BIT_ARB 0x00000001 + #define GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB 0x00000002 + #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 + #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 + #define GLX_CONTEXT_FLAGS_ARB 0x2094 + + // GLX_ARB_create_context_profile + #define GLX_CONTEXT_CORE_PROFILE_BIT_ARB 0x00000001 + #define GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB 0x00000002 + #define GLX_CONTEXT_PROFILE_MASK_ARB 0x9126 +#endif + + //! Dummy XError handler which just skips errors + static int xErrorDummyHandler (Display* /*theDisplay*/, + XErrorEvent* /*theErrorEvent*/) { - return (theEv->type == MapNotify) && (theEv->xmap.window == (Window )theArg); + return 0; + } + + //! Auxiliary method to format list. + static void addMsgToList (TCollection_ExtendedString& theList, + const TCollection_ExtendedString& theMsg) + { + if (!theList.IsEmpty()) + { + theList += ", "; + } + theList += theMsg; } #endif @@ -437,235 +465,131 @@ OpenGl_Window::OpenGl_Window (const Handle(OpenGl_GraphicDriver)& theDriver, myGlContext->Init ((Aspect_Handle )aWindow, (Aspect_Handle )aWindowDC, (Aspect_RenderingContext )aGContext, isCoreProfile); #else - Window aParent = (Window )myPlatformWindow->NativeHandle(); - Window aWindow = 0; - + Window aWindow = (Window )myPlatformWindow->NativeHandle(); Display* aDisp = theDriver->GetDisplayConnection()->GetDisplay(); GLXContext aGContext = (GLXContext )theGContext; + GLXContext aSlaveCtx = !theShareCtx.IsNull() ? (GLXContext )theShareCtx->myGContext : NULL; - XWindowAttributes wattr; - XGetWindowAttributes (aDisp, aParent, &wattr); - const int scr = DefaultScreen (aDisp); - - XVisualInfo* aVis = NULL; + XWindowAttributes aWinAttribs; + XGetWindowAttributes (aDisp, aWindow, &aWinAttribs); + XVisualInfo aVisInfo; + aVisInfo.visualid = aWinAttribs.visual->visualid; + aVisInfo.screen = DefaultScreen (aDisp); + int aNbItems; + XVisualInfo* aVis = XGetVisualInfo (aDisp, VisualIDMask | VisualScreenMask, &aVisInfo, &aNbItems); + int isGl = 0; + if (aVis == NULL) { - unsigned long aVisInfoMask = VisualIDMask | VisualScreenMask; - XVisualInfo aVisInfo; - aVisInfo.visualid = wattr.visual->visualid; - aVisInfo.screen = scr; - int aNbItems; - aVis = XGetVisualInfo (aDisp, aVisInfoMask, &aVisInfo, &aNbItems); + Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: XGetVisualInfo is unable to choose needed configuration in existing OpenGL context. "); + return; + } + else if (glXGetConfig (aDisp, aVis, GLX_USE_GL, &isGl) != 0 || !isGl) + { + Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: window Visual does not support GL rendering!"); + return; } -#if defined(__linux__) || defined(Linux) || defined(__APPLE__) - if (aVis != NULL) + // create new context + GLXFBConfig anFBConfig = myPlatformWindow->NativeFBConfig(); + const char* aGlxExts = glXQueryExtensionsString (aDisp, aVisInfo.screen); + if (myOwnGContext + && anFBConfig != NULL + && OpenGl_Context::CheckExtension (aGlxExts, "GLX_ARB_create_context_profile")) { - // check Visual for OpenGl context's parameters compatibility - int isGl = 0, isDoubleBuffer = 0, isRGBA = 0, isStereo = 0; - int aDepthSize = 0, aStencilSize = 0; + // Replace default XError handler to ignore errors. + // Warning - this is global for all threads! + typedef int (*xerrorhandler_t)(Display* , XErrorEvent* ); + xerrorhandler_t anOldHandler = XSetErrorHandler(xErrorDummyHandler); - if (glXGetConfig (aDisp, aVis, GLX_USE_GL, &isGl) != 0) - isGl = 0; - - if (glXGetConfig (aDisp, aVis, GLX_RGBA, &isRGBA) != 0) - isRGBA = 0; - - if (glXGetConfig (aDisp, aVis, GLX_DOUBLEBUFFER, &isDoubleBuffer) != 0) - isDoubleBuffer = 0; - - if (glXGetConfig (aDisp, aVis, GLX_STEREO, &isStereo) != 0) - isStereo = 0; - - if (glXGetConfig (aDisp, aVis, GLX_DEPTH_SIZE, &aDepthSize) != 0) - aDepthSize = 0; - - if (glXGetConfig (aDisp, aVis, GLX_STENCIL_SIZE, &aStencilSize) != 0) - aStencilSize = 0; - - if (!isGl) + typedef GLXContext (*glXCreateContextAttribsARB_t)(Display* dpy, GLXFBConfig config, + GLXContext share_context, Bool direct, + const int* attrib_list); + glXCreateContextAttribsARB_t aCreateCtxProc = (glXCreateContextAttribsARB_t )glXGetProcAddress((const GLubyte* )"glXCreateContextAttribsARB"); + if (!theCaps->contextCompatible) { - XFree (aVis); - aVis = NULL; - if (myOwnGContext) + int aCoreCtxAttribs[] = { - TCollection_ExtendedString aMsg ("OpenGl_Window::CreateWindow: window Visual does not support GL rendering!"); - myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, - GL_DEBUG_TYPE_OTHER_ARB, - 0, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg); - } - } - else - { - TCollection_ExtendedString aList; - if (aDepthSize < 1) - { - if (!aList.IsEmpty()) aList += ", "; - aList += "no depth buffer"; - } - if (aStencilSize < 1) - { - if (!aList.IsEmpty()) aList += ", "; - aList += "no stencil buffer"; - } - if (isRGBA == 0) - { - if (!aList.IsEmpty()) aList += ", "; - aList += "no RGBA color buffer"; - } - if (isDoubleBuffer == 0) - { - if (!aList.IsEmpty()) aList += ", "; - aList += "no Double Buffer"; - } - if (theCaps->contextStereo && isStereo == 0) - { - if (!aList.IsEmpty()) aList += ", "; - aList += "no Quad Buffer"; - } - if (!theCaps->contextStereo && isStereo == 1) - { - if (!aList.IsEmpty()) aList += ", "; - aList += "extra Quad Buffer"; - } - if (!aList.IsEmpty()) - { - TCollection_ExtendedString aMsg = TCollection_ExtendedString ("OpenGl_Window::CreateWindow: window Visual is incomplete: ") + aList; - if (myOwnGContext) - { - XFree (aVis); - aVis = NULL; - } - myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, - GL_DEBUG_TYPE_OTHER_ARB, - 0, GL_DEBUG_SEVERITY_MEDIUM_ARB, aMsg); + GLX_CONTEXT_MAJOR_VERSION_ARB, 3, + GLX_CONTEXT_MINOR_VERSION_ARB, 2, + GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, + GLX_CONTEXT_FLAGS_ARB, theCaps->contextDebug ? GLX_CONTEXT_DEBUG_BIT_ARB : 0, + 0, 0 + }; + + // try to create the core profile of highest OpenGL version supported by OCCT + for (int aLowVer4 = 5; aLowVer4 >= 0 && aGContext == NULL; --aLowVer4) + { + aCoreCtxAttribs[1] = 4; + aCoreCtxAttribs[3] = aLowVer4; + aGContext = aCreateCtxProc (aDisp, anFBConfig, aSlaveCtx, True, aCoreCtxAttribs); + } + for (int aLowVer3 = 3; aLowVer3 >= 2 && aGContext == NULL; --aLowVer3) + { + aCoreCtxAttribs[1] = 3; + aCoreCtxAttribs[3] = aLowVer3; + aGContext = aCreateCtxProc (aDisp, anFBConfig, aSlaveCtx, True, aCoreCtxAttribs); + } + isCoreProfile = aGContext != NULL; + } + + if (aGContext == NULL) + { + int aCtxAttribs[] = + { + GLX_CONTEXT_FLAGS_ARB, theCaps->contextDebug ? GLX_CONTEXT_DEBUG_BIT_ARB : 0, + 0, 0 + }; + isCoreProfile = Standard_False; + aGContext = aCreateCtxProc (aDisp, anFBConfig, aSlaveCtx, True, aCtxAttribs); + + if (aGContext != NULL + && !theCaps->contextCompatible) + { + TCollection_ExtendedString aMsg("OpenGl_Window::CreateWindow: core profile creation failed."); + myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_PORTABILITY_ARB, 0, GL_DEBUG_SEVERITY_LOW_ARB, aMsg); } } + XSetErrorHandler(anOldHandler); } -#endif - if (!myOwnGContext) + if (myOwnGContext + && aGContext == NULL) { - if (aVis == NULL) - { - Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: XGetVisualInfo is unable to choose needed configuration in existing OpenGL context. "); - return; - } - - aWindow = aParent; - } - else - { - if (aVis == NULL) - { - int anIter = 0; - int anAttribs[13]; - anAttribs[anIter++] = GLX_RGBA; - - anAttribs[anIter++] = GLX_DEPTH_SIZE; - anAttribs[anIter++] = 1; - - anAttribs[anIter++] = GLX_STENCIL_SIZE; - anAttribs[anIter++] = 1; - - anAttribs[anIter++] = GLX_RED_SIZE; - anAttribs[anIter++] = (wattr.depth <= 8) ? 0 : 1; - - anAttribs[anIter++] = GLX_GREEN_SIZE; - anAttribs[anIter++] = (wattr.depth <= 8) ? 0 : 1; - - anAttribs[anIter++] = GLX_BLUE_SIZE; - anAttribs[anIter++] = (wattr.depth <= 8) ? 0 : 1; - - anAttribs[anIter++] = GLX_DOUBLEBUFFER; - - // warning: this flag may be set to None, so it need to be last in anAttribs - Standard_Integer aStereoFlagPos = anIter; - if (theCaps->contextStereo) - anAttribs[anIter++] = GLX_STEREO; - - anAttribs[anIter++] = None; - - aVis = glXChooseVisual (aDisp, scr, anAttribs); - - // in case of failure try without stereo if any - if (aVis == NULL && theCaps->contextStereo) - { - TCollection_ExtendedString aMsg ("OpenGl_Window::CreateWindow: " - "glXChooseVisual is unable to find stereo supported pixel format. " - "Choosing similar non stereo format."); - myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, - GL_DEBUG_TYPE_OTHER_ARB, - 0, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg); - - anAttribs[aStereoFlagPos] = None; - aVis = glXChooseVisual (aDisp, scr, anAttribs); - } - - if (aVis == NULL) - { - Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: glXChooseVisual failed."); - return; - } - else - { - TCollection_ExtendedString aMsg ("OpenGl_Window::CreateWindow: child window has been created with better Visual."); - myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, - GL_DEBUG_TYPE_OTHER_ARB, - 0, GL_DEBUG_SEVERITY_MEDIUM_ARB, aMsg); - } - } - - if (!theShareCtx.IsNull()) - { - // ctx est une copie du previous - aGContext = glXCreateContext (aDisp, aVis, (GLXContext )theShareCtx->myGContext, GL_TRUE); - } - else - { - aGContext = glXCreateContext (aDisp, aVis, NULL, GL_TRUE); - } - - if (!aGContext) + aGContext = glXCreateContext (aDisp, aVis, aSlaveCtx, GL_TRUE); + if (aGContext == NULL) { Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: glXCreateContext failed."); return; } + } - Colormap cmap = XCreateColormap (aDisp, aParent, aVis->visual, AllocNone); - - Quantity_Color aBgColor = myPlatformWindow->Background().Color(); - XColor color; - color.red = (unsigned short) (aBgColor.Red() * 0xFFFF); - color.green = (unsigned short) (aBgColor.Green() * 0xFFFF); - color.blue = (unsigned short) (aBgColor.Blue() * 0xFFFF); - color.flags = DoRed | DoGreen | DoBlue; - XAllocColor (aDisp, cmap, &color); - - XSetWindowAttributes cwa; - cwa.colormap = cmap; - cwa.event_mask = StructureNotifyMask; - cwa.border_pixel = color.pixel; - cwa.background_pixel = color.pixel; - - if (aVis->visualid == wattr.visual->visualid) - { - aWindow = aParent; - } - else - { - unsigned long mask = CWBackPixel | CWColormap | CWBorderPixel | CWEventMask; - aWindow = XCreateWindow (aDisp, aParent, 0, 0, myWidth, myHeight, 0/*bw*/, aVis->depth, InputOutput, aVis->visual, mask, &cwa); - } - - XSetWindowBackground (aDisp, aWindow, cwa.background_pixel); - XClearWindow (aDisp, aWindow); - - if (aWindow != aParent) - { - XEvent anEvent; - XMapWindow (aDisp, aWindow); - XIfEvent (aDisp, &anEvent, WaitForNotify, (char* )aWindow); - } + // check Visual for OpenGl context's parameters compatibility + TCollection_ExtendedString aList; + int isDoubleBuffer = 0, isRGBA = 0, isStereo = 0; + int aDepthSize = 0, aStencilSize = 0; + glXGetConfig (aDisp, aVis, GLX_RGBA, &isRGBA); + glXGetConfig (aDisp, aVis, GLX_DOUBLEBUFFER, &isDoubleBuffer); + glXGetConfig (aDisp, aVis, GLX_STEREO, &isStereo); + glXGetConfig (aDisp, aVis, GLX_DEPTH_SIZE, &aDepthSize); + glXGetConfig (aDisp, aVis, GLX_STENCIL_SIZE, &aStencilSize); + if (aDepthSize < 1) addMsgToList (aList, "no depth buffer"); + if (aStencilSize < 1) addMsgToList (aList, "no stencil buffer"); + if (isRGBA == 0) addMsgToList (aList, "no RGBA color buffer"); + if (isDoubleBuffer == 0) addMsgToList (aList, "no Double Buffer"); + if (theCaps->contextStereo && isStereo == 0) + { + addMsgToList (aList, "no Quad Buffer"); + } + else if (!theCaps->contextStereo && isStereo == 1) + { + addMsgToList (aList, "extra Quad Buffer"); + } + if (!aList.IsEmpty()) + { + TCollection_ExtendedString aMsg = TCollection_ExtendedString ("OpenGl_Window::CreateWindow: window Visual is incomplete: ") + aList; + myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, + GL_DEBUG_TYPE_OTHER_ARB, + 0, GL_DEBUG_SEVERITY_MEDIUM_ARB, aMsg); } myGlContext->Init ((Aspect_Drawable )aWindow, (Aspect_Display )aDisp, (Aspect_RenderingContext )aGContext, isCoreProfile); diff --git a/src/WNT/WNT_Window.hxx b/src/WNT/WNT_Window.hxx index 3882b1ca1c..69719a5a77 100644 --- a/src/WNT/WNT_Window.hxx +++ b/src/WNT/WNT_Window.hxx @@ -68,7 +68,7 @@ public: Standard_EXPORT void SetCursor (const Aspect_Handle aCursor) const; //! Opens the window . - Standard_EXPORT virtual void Map() const; + Standard_EXPORT virtual void Map() const Standard_OVERRIDE; //! Opens a window according to . //! This method is specific to Windows NT. @@ -77,45 +77,46 @@ public: Standard_EXPORT void Map (const Standard_Integer aMapMode) const; //! Closes the window . - Standard_EXPORT virtual void Unmap() const; + Standard_EXPORT virtual void Unmap() const Standard_OVERRIDE; //! Applies the resizing to the window . - Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const; + Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const Standard_OVERRIDE; //! Apply the mapping change to the window //! and returns TRUE if the window is mapped at screen. - virtual Standard_Boolean DoMapping() const; + virtual Standard_Boolean DoMapping() const Standard_OVERRIDE; //! Changes variables due to window position. Standard_EXPORT void SetPos (const Standard_Integer X, const Standard_Integer Y, const Standard_Integer X1, const Standard_Integer Y1); //! Returns True if the window is opened //! and False if the window is closed. - Standard_EXPORT virtual Standard_Boolean IsMapped() const; + Standard_EXPORT virtual Standard_Boolean IsMapped() const Standard_OVERRIDE; //! Returns The Window RATIO equal to the physical //! WIDTH/HEIGHT dimensions. - Standard_EXPORT virtual Quantity_Ratio Ratio() const; + Standard_EXPORT virtual Quantity_Ratio Ratio() const Standard_OVERRIDE; //! Returns The Window POSITION in PIXEL - Standard_EXPORT virtual void Position (Standard_Integer& X1, Standard_Integer& Y1, Standard_Integer& X2, Standard_Integer& Y2) const; + Standard_EXPORT virtual void Position (Standard_Integer& X1, Standard_Integer& Y1, Standard_Integer& X2, Standard_Integer& Y2) const Standard_OVERRIDE; //! Returns The Window SIZE in PIXEL - Standard_EXPORT virtual void Size (Standard_Integer& Width, Standard_Integer& Height) const; + Standard_EXPORT virtual void Size (Standard_Integer& Width, Standard_Integer& Height) const Standard_OVERRIDE; //! Returns the Windows NT handle of the created window . - Aspect_Handle HWindow() const; + Aspect_Handle HWindow() const; //! Returns the Windows NT handle parent of the created window . - Aspect_Handle HParentWindow() const; + Aspect_Handle HParentWindow() const; //! Returns native Window handle (HWND) - virtual Aspect_Drawable NativeHandle() const; + virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE; //! Returns parent of native Window handle (HWND on Windows, Window with Xlib, and so on) - virtual Aspect_Drawable NativeParentHandle() const; - + virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE; + //! Returns nothing on Windows + virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE { return NULL; } DEFINE_STANDARD_RTTI(WNT_Window,Aspect_Window) diff --git a/src/Xw/Xw_Window.cxx b/src/Xw/Xw_Window.cxx old mode 100755 new mode 100644 index 5cf879fd5a..9e7b98037a --- a/src/Xw/Xw_Window.cxx +++ b/src/Xw/Xw_Window.cxx @@ -26,8 +26,7 @@ namespace { //! Search for RGBA double-buffered visual with stencil buffer. - //! Each size property should be a nonnegative minimum specification. - static int TheDoubleBuff[] = + static int TheDoubleBuffVisual[] = { GLX_RGBA, GLX_DEPTH_SIZE, 16, @@ -36,8 +35,20 @@ namespace None }; -}; + //! Search for RGBA double-buffered visual with stencil buffer. + static int TheDoubleBuffFBConfig[] = + { + GLX_X_RENDERABLE, True, + GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, + GLX_RENDER_TYPE, GLX_RGBA_BIT, + GLX_X_VISUAL_TYPE, GLX_TRUE_COLOR, + GLX_DEPTH_SIZE, 16, + GLX_STENCIL_SIZE, 1, + GLX_DOUBLEBUFFER, True, + None + }; +} // ======================================================================= // function : Xw_Window @@ -48,10 +59,12 @@ Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay, const Standard_Integer thePxLeft, const Standard_Integer thePxTop, const Standard_Integer thePxWidth, - const Standard_Integer thePxHeight) + const Standard_Integer thePxHeight, + const Aspect_FBConfig theFBConfig) : Aspect_Window(), myDisplay (theXDisplay), myXWindow (0), + myFBConfig (theFBConfig), myXLeft (thePxLeft), myYTop (thePxTop), myXRight (thePxLeft + thePxWidth), @@ -77,8 +90,37 @@ Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay, Display* aDisp = myDisplay->GetDisplay(); int aScreen = DefaultScreen(aDisp); Window aParent = RootWindow (aDisp, aScreen); + XVisualInfo* aVisInfo = NULL; - XVisualInfo* aVisInfo = glXChooseVisual (aDisp, aScreen, TheDoubleBuff); + if (myFBConfig == NULL) + { + // FBConfigs were added in GLX version 1.3 + int aGlxMajor = 0; + int aGlxMinor = 0; + const bool hasFBCfg = glXQueryVersion (aDisp, &aGlxMajor, &aGlxMinor) + && ((aGlxMajor == 1 && aGlxMinor >= 3) || (aGlxMajor > 1)); + if (hasFBCfg) + { + int aFBCount = 0; + GLXFBConfig* aFBCfgList = NULL; + if (hasFBCfg) + { + aFBCfgList = glXChooseFBConfig (aDisp, aScreen, TheDoubleBuffFBConfig, &aFBCount); + } + if(aFBCfgList != NULL + && aFBCount >= 1) + { + myFBConfig = aFBCfgList[0]; + aVisInfo = glXGetVisualFromFBConfig (aDisp, myFBConfig); + } + XFree (aFBCfgList); + } + } + + if (aVisInfo == NULL) + { + aVisInfo = glXChooseVisual (aDisp, aScreen, TheDoubleBuffVisual); + } if (aVisInfo == NULL) { Aspect_WindowDefinitionError::Raise ("Xw_Window, couldn't find compatible Visual (RGBA, double-buffered)"); @@ -133,10 +175,12 @@ Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay, // purpose : // ======================================================================= Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay, - const Window theXWin) + const Window theXWin, + const Aspect_FBConfig theFBConfig) : Aspect_Window(), myDisplay (theXDisplay), myXWindow (theXWin), + myFBConfig (theFBConfig), myXLeft (0), myYTop (0), myXRight (512), diff --git a/src/Xw/Xw_Window.hxx b/src/Xw/Xw_Window.hxx old mode 100755 new mode 100644 index c36ef84f14..4e6236c689 --- a/src/Xw/Xw_Window.hxx +++ b/src/Xw/Xw_Window.hxx @@ -50,11 +50,13 @@ public: const Standard_Integer thePxLeft, const Standard_Integer thePxTop, const Standard_Integer thePxWidth, - const Standard_Integer thePxHeight); + const Standard_Integer thePxHeight, + const Aspect_FBConfig theFBConfig = NULL); //! Creates a wrapper over existing Window handle Standard_EXPORT Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay, - const Window theXWin); + const Window theXWin, + const Aspect_FBConfig theFBConfig = NULL); //! Destroies the Window and all resourses attached to it Standard_EXPORT virtual void Destroy(); @@ -65,32 +67,32 @@ public: } //! Opens the window - Standard_EXPORT virtual void Map() const; + Standard_EXPORT virtual void Map() const Standard_OVERRIDE; //! Closes the window - Standard_EXPORT virtual void Unmap() const; + Standard_EXPORT virtual void Unmap() const Standard_OVERRIDE; //! Applies the resizing to the window - Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const; + Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const Standard_OVERRIDE; //! Apply the mapping change to the window - Standard_EXPORT virtual Standard_Boolean DoMapping() const; + Standard_EXPORT virtual Standard_Boolean DoMapping() const Standard_OVERRIDE; //! Returns True if the window is opened - Standard_EXPORT virtual Standard_Boolean IsMapped() const; + Standard_EXPORT virtual Standard_Boolean IsMapped() const Standard_OVERRIDE; //! Returns The Window RATIO equal to the physical WIDTH/HEIGHT dimensions - Standard_EXPORT virtual Quantity_Ratio Ratio() const; + Standard_EXPORT virtual Quantity_Ratio Ratio() const Standard_OVERRIDE; //! Returns The Window POSITION in PIXEL Standard_EXPORT virtual void Position (Standard_Integer& X1, Standard_Integer& Y1, Standard_Integer& X2, - Standard_Integer& Y2) const; + Standard_Integer& Y2) const Standard_OVERRIDE; //! Returns The Window SIZE in PIXEL Standard_EXPORT virtual void Size (Standard_Integer& theWidth, - Standard_Integer& theHeight) const; + Standard_Integer& theHeight) const Standard_OVERRIDE; //! @return native Window handle Standard_EXPORT Window XWindow() const; @@ -99,21 +101,28 @@ public: Standard_EXPORT const Handle(Aspect_DisplayConnection)& DisplayConnection() const; //! @return native Window handle - virtual Aspect_Drawable NativeHandle() const + virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE { return (Aspect_Drawable )XWindow(); } //! @return parent of native Window handle - virtual Aspect_Drawable NativeParentHandle() const + virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE { return 0; } + //! @return native Window FB config (GLXFBConfig on Xlib) + virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE + { + return myFBConfig; + } + protected: Handle(Aspect_DisplayConnection) myDisplay; //!< X Display connection Window myXWindow; //!< XLib window handle + Aspect_FBConfig myFBConfig; //!< GLXFBConfig Standard_Integer myXLeft; //!< left position in pixels Standard_Integer myYTop; //!< top position in pixels Standard_Integer myXRight; //!< right position in pixels