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 0;
+ }
+
+ //! Auxiliary method to format list.
+ static void addMsgToList (TCollection_ExtendedString& theList,
+ const TCollection_ExtendedString& theMsg)
{
- return (theEv->type == MapNotify) && (theEv->xmap.window == (Window )theArg);
+ if (!theList.IsEmpty())
+ {
+ theList += ", ";
+ }
+ theList += theMsg;
}
#endif
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;
-
- XWindowAttributes wattr;
- XGetWindowAttributes (aDisp, aParent, &wattr);
- const int scr = DefaultScreen (aDisp);
-
- XVisualInfo* aVis = NULL;
+ GLXContext aSlaveCtx = !theShareCtx.IsNull() ? (GLXContext )theShareCtx->myGContext : 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;
}
-
-#if defined(__linux__) || defined(Linux) || defined(__APPLE__)
- if (aVis != NULL)
+ else if (glXGetConfig (aDisp, aVis, GLX_USE_GL, &isGl) != 0 || !isGl)
{
- // check Visual for OpenGl context's parameters compatibility
- int isGl = 0, isDoubleBuffer = 0, isRGBA = 0, isStereo = 0;
- int aDepthSize = 0, aStencilSize = 0;
-
- 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;
+ Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: window Visual does not support GL rendering!");
+ return;
+ }
- if (!isGl)
- {
- XFree (aVis);
- aVis = NULL;
- if (myOwnGContext)
- {
- 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
+ // 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"))
+ {
+ // 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);
+
+ 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)
{
- 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)
+ int aCoreCtxAttribs[] =
{
- 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)
+ 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)
{
- if (!aList.IsEmpty()) aList += ", ";
- aList += "extra Quad Buffer";
+ aCoreCtxAttribs[1] = 4;
+ aCoreCtxAttribs[3] = aLowVer4;
+ aGContext = aCreateCtxProc (aDisp, anFBConfig, aSlaveCtx, True, aCoreCtxAttribs);
}
- if (!aList.IsEmpty())
+ for (int aLowVer3 = 3; aLowVer3 >= 2 && aGContext == NULL; --aLowVer3)
{
- 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);
+ aCoreCtxAttribs[1] = 3;
+ aCoreCtxAttribs[3] = aLowVer3;
+ aGContext = aCreateCtxProc (aDisp, anFBConfig, aSlaveCtx, True, aCoreCtxAttribs);
}
- }
- }
-#endif
-
- if (!myOwnGContext)
- {
- if (aVis == NULL)
- {
- Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: XGetVisualInfo is unable to choose needed configuration in existing OpenGL context. ");
- return;
+ isCoreProfile = aGContext != NULL;
}
- aWindow = aParent;
- }
- else
- {
- if (aVis == NULL)
+ if (aGContext == 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)
+ int aCtxAttribs[] =
{
- 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);
- }
+ 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 (aVis == NULL)
- {
- Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: glXChooseVisual failed.");
- return;
- }
- else
+ if (aGContext != NULL
+ && !theCaps->contextCompatible)
{
- 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);
+ 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);
+ }
- 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)
+ if (myOwnGContext
+ && aGContext == NULL)
+ {
+ 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);
Standard_EXPORT void SetCursor (const Aspect_Handle aCursor) const;
//! Opens the window <me>.
- Standard_EXPORT virtual void Map() const;
+ Standard_EXPORT virtual void Map() const Standard_OVERRIDE;
//! Opens a window <me> according to <aMapMode>.
//! This method is specific to Windows NT.
Standard_EXPORT void Map (const Standard_Integer aMapMode) const;
//! Closes the window <me>.
- Standard_EXPORT virtual void Unmap() const;
+ Standard_EXPORT virtual void Unmap() const Standard_OVERRIDE;
//! Applies the resizing to the window <me>.
- Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const;
+ Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const Standard_OVERRIDE;
//! Apply the mapping change to the window <me>
//! 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 <me> 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 <me>.
- Aspect_Handle HWindow() const;
+ Aspect_Handle HWindow() const;
//! Returns the Windows NT handle parent of the created window <me>.
- 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)
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();
}
//! Opens the window <me>
- Standard_EXPORT virtual void Map() const;
+ Standard_EXPORT virtual void Map() const Standard_OVERRIDE;
//! Closes the window <me>
- Standard_EXPORT virtual void Unmap() const;
+ Standard_EXPORT virtual void Unmap() const Standard_OVERRIDE;
//! Applies the resizing to the window <me>
- Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const;
+ Standard_EXPORT virtual Aspect_TypeOfResize DoResize() const Standard_OVERRIDE;
//! Apply the mapping change to the window <me>
- Standard_EXPORT virtual Standard_Boolean DoMapping() const;
+ Standard_EXPORT virtual Standard_Boolean DoMapping() const Standard_OVERRIDE;
//! Returns True if the window <me> 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;
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