1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-05-16 10:54:53 +03:00

0026732: Visualization, TKOpenGl - add option to request Core profile 3.2+ using GLX

Aspect_Window::NativeFBConfig() - extend interface with new method.
Xw_Window - add Aspect_FBConfig option to constructors,
use glXChooseFBConfig() instead of glXChooseVisual() on GLX1.3+.

OpenGl_Window - create context using glXCreateContextAttribsARB()
when GLXFBConfig is provided by Aspect_Window.
This procedure now handles Core Profile and Debug Context options on Linux.

OpenGl_Window - drop code implicitly creating child window
when window XVisual is incomplete for OpenGL context.
This should eliminate event-handling issues at application side,
but would require window to be properly created by application.
This commit is contained in:
kgv 2015-09-29 10:15:32 +03:00 committed by bugmaster
parent a7197ef3c7
commit b6bf4ec174
8 changed files with 261 additions and 254 deletions

View File

@ -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

View File

@ -21,6 +21,7 @@
#include <Aspect_Background.hxx> #include <Aspect_Background.hxx>
#include <Aspect_GradientBackground.hxx> #include <Aspect_GradientBackground.hxx>
#include <Aspect_FBConfig.hxx>
#include <Aspect_FillMethod.hxx> #include <Aspect_FillMethod.hxx>
#include <Standard_Boolean.hxx> #include <Standard_Boolean.hxx>
#include <MMgt_TShared.hxx> #include <MMgt_TShared.hxx>
@ -113,8 +114,8 @@ public:
//! Returns parent of native Window handle (HWND on Windows, Window with Xlib, and so on) //! Returns parent of native Window handle (HWND on Windows, Window with Xlib, and so on)
Standard_EXPORT virtual Aspect_Drawable NativeParentHandle() const = 0; 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) DEFINE_STANDARD_RTTI(Aspect_Window,MMgt_TShared)

View File

@ -19,6 +19,7 @@ Aspect_DisplayConnection.hxx
Aspect_DisplayConnectionDefinitionError.hxx Aspect_DisplayConnectionDefinitionError.hxx
Aspect_Drawable.hxx Aspect_Drawable.hxx
Aspect_DriverDefinitionError.hxx Aspect_DriverDefinitionError.hxx
Aspect_FBConfig.hxx
Aspect_FillMethod.hxx Aspect_FillMethod.hxx
Aspect_GenId.cxx Aspect_GenId.cxx
Aspect_GenId.hxx Aspect_GenId.hxx

View File

@ -87,32 +87,32 @@ public:
} }
//! Opens the window <me> //! Opens the window <me>
Standard_EXPORT virtual void Map() const; Standard_EXPORT virtual void Map() const Standard_OVERRIDE;
//! Closes the window <me> //! 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> //! 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> //! 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 //! 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 //! 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 //! Returns The Window POSITION in PIXEL
Standard_EXPORT virtual void Position (Standard_Integer& X1, Standard_EXPORT virtual void Position (Standard_Integer& X1,
Standard_Integer& Y1, Standard_Integer& Y1,
Standard_Integer& X2, Standard_Integer& X2,
Standard_Integer& Y2) const; Standard_Integer& Y2) const Standard_OVERRIDE;
//! Returns The Window SIZE in PIXEL //! Returns The Window SIZE in PIXEL
Standard_EXPORT virtual void Size (Standard_Integer& theWidth, 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 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
//! @return associated UIView //! @return associated UIView
@ -129,17 +129,20 @@ public:
#endif #endif
//! @return native Window handle //! @return native Window handle
virtual Aspect_Drawable NativeHandle() const virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE
{ {
return (Aspect_Drawable )HView(); return (Aspect_Drawable )HView();
} }
//! @return parent of native Window handle //! @return parent of native Window handle
virtual Aspect_Drawable NativeParentHandle() const virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE
{ {
return 0; return 0;
} }
//! Returns nothing on OS X
virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE { return NULL; }
protected: protected:
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE

View File

@ -118,9 +118,37 @@ namespace
return DefWindowProcW (theWin, theMsg, theParamW, theParamL); return DefWindowProcW (theWin, theMsg, theParamW, theParamL);
} }
#else #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 #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); myGlContext->Init ((Aspect_Handle )aWindow, (Aspect_Handle )aWindowDC, (Aspect_RenderingContext )aGContext, isCoreProfile);
#else #else
Window aParent = (Window )myPlatformWindow->NativeHandle(); Window aWindow = (Window )myPlatformWindow->NativeHandle();
Window aWindow = 0;
Display* aDisp = theDriver->GetDisplayConnection()->GetDisplay(); Display* aDisp = theDriver->GetDisplayConnection()->GetDisplay();
GLXContext aGContext = (GLXContext )theGContext; GLXContext aGContext = (GLXContext )theGContext;
GLXContext aSlaveCtx = !theShareCtx.IsNull() ? (GLXContext )theShareCtx->myGContext : NULL;
XWindowAttributes wattr; XWindowAttributes aWinAttribs;
XGetWindowAttributes (aDisp, aParent, &wattr); XGetWindowAttributes (aDisp, aWindow, &aWinAttribs);
const int scr = DefaultScreen (aDisp); XVisualInfo aVisInfo;
aVisInfo.visualid = aWinAttribs.visual->visualid;
XVisualInfo* aVis = NULL; 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; Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: XGetVisualInfo is unable to choose needed configuration in existing OpenGL context. ");
XVisualInfo aVisInfo; return;
aVisInfo.visualid = wattr.visual->visualid; }
aVisInfo.screen = scr; else if (glXGetConfig (aDisp, aVis, GLX_USE_GL, &isGl) != 0 || !isGl)
int aNbItems; {
aVis = XGetVisualInfo (aDisp, aVisInfoMask, &aVisInfo, &aNbItems); Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: window Visual does not support GL rendering!");
return;
} }
#if defined(__linux__) || defined(Linux) || defined(__APPLE__) // create new context
if (aVis != NULL) 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 // Replace default XError handler to ignore errors.
int isGl = 0, isDoubleBuffer = 0, isRGBA = 0, isStereo = 0; // Warning - this is global for all threads!
int aDepthSize = 0, aStencilSize = 0; typedef int (*xerrorhandler_t)(Display* , XErrorEvent* );
xerrorhandler_t anOldHandler = XSetErrorHandler(xErrorDummyHandler);
if (glXGetConfig (aDisp, aVis, GLX_USE_GL, &isGl) != 0) typedef GLXContext (*glXCreateContextAttribsARB_t)(Display* dpy, GLXFBConfig config,
isGl = 0; GLXContext share_context, Bool direct,
const int* attrib_list);
if (glXGetConfig (aDisp, aVis, GLX_RGBA, &isRGBA) != 0) glXCreateContextAttribsARB_t aCreateCtxProc = (glXCreateContextAttribsARB_t )glXGetProcAddress((const GLubyte* )"glXCreateContextAttribsARB");
isRGBA = 0; if (!theCaps->contextCompatible)
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)
{ {
XFree (aVis); int aCoreCtxAttribs[] =
aVis = NULL;
if (myOwnGContext)
{ {
TCollection_ExtendedString aMsg ("OpenGl_Window::CreateWindow: window Visual does not support GL rendering!"); GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, GLX_CONTEXT_MINOR_VERSION_ARB, 2,
GL_DEBUG_TYPE_OTHER_ARB, GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
0, GL_DEBUG_SEVERITY_HIGH_ARB, aMsg); GLX_CONTEXT_FLAGS_ARB, theCaps->contextDebug ? GLX_CONTEXT_DEBUG_BIT_ARB : 0,
} 0, 0
} };
else
{ // try to create the core profile of highest OpenGL version supported by OCCT
TCollection_ExtendedString aList; for (int aLowVer4 = 5; aLowVer4 >= 0 && aGContext == NULL; --aLowVer4)
if (aDepthSize < 1) {
{ aCoreCtxAttribs[1] = 4;
if (!aList.IsEmpty()) aList += ", "; aCoreCtxAttribs[3] = aLowVer4;
aList += "no depth buffer"; aGContext = aCreateCtxProc (aDisp, anFBConfig, aSlaveCtx, True, aCoreCtxAttribs);
} }
if (aStencilSize < 1) for (int aLowVer3 = 3; aLowVer3 >= 2 && aGContext == NULL; --aLowVer3)
{ {
if (!aList.IsEmpty()) aList += ", "; aCoreCtxAttribs[1] = 3;
aList += "no stencil buffer"; aCoreCtxAttribs[3] = aLowVer3;
} aGContext = aCreateCtxProc (aDisp, anFBConfig, aSlaveCtx, True, aCoreCtxAttribs);
if (isRGBA == 0) }
{ isCoreProfile = aGContext != NULL;
if (!aList.IsEmpty()) aList += ", "; }
aList += "no RGBA color buffer";
} if (aGContext == NULL)
if (isDoubleBuffer == 0) {
{ int aCtxAttribs[] =
if (!aList.IsEmpty()) aList += ", "; {
aList += "no Double Buffer"; GLX_CONTEXT_FLAGS_ARB, theCaps->contextDebug ? GLX_CONTEXT_DEBUG_BIT_ARB : 0,
} 0, 0
if (theCaps->contextStereo && isStereo == 0) };
{ isCoreProfile = Standard_False;
if (!aList.IsEmpty()) aList += ", "; aGContext = aCreateCtxProc (aDisp, anFBConfig, aSlaveCtx, True, aCtxAttribs);
aList += "no Quad Buffer";
} if (aGContext != NULL
if (!theCaps->contextStereo && isStereo == 1) && !theCaps->contextCompatible)
{ {
if (!aList.IsEmpty()) aList += ", "; TCollection_ExtendedString aMsg("OpenGl_Window::CreateWindow: core profile creation failed.");
aList += "extra Quad Buffer"; myGlContext->PushMessage (GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_PORTABILITY_ARB, 0, GL_DEBUG_SEVERITY_LOW_ARB, aMsg);
}
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);
} }
} }
XSetErrorHandler(anOldHandler);
} }
#endif
if (!myOwnGContext) if (myOwnGContext
&& aGContext == NULL)
{ {
if (aVis == NULL) aGContext = glXCreateContext (aDisp, aVis, aSlaveCtx, GL_TRUE);
{ if (aGContext == 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)
{ {
Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: glXCreateContext failed."); Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: glXCreateContext failed.");
return; return;
} }
}
Colormap cmap = XCreateColormap (aDisp, aParent, aVis->visual, AllocNone); // check Visual for OpenGl context's parameters compatibility
TCollection_ExtendedString aList;
Quantity_Color aBgColor = myPlatformWindow->Background().Color(); int isDoubleBuffer = 0, isRGBA = 0, isStereo = 0;
XColor color; int aDepthSize = 0, aStencilSize = 0;
color.red = (unsigned short) (aBgColor.Red() * 0xFFFF); glXGetConfig (aDisp, aVis, GLX_RGBA, &isRGBA);
color.green = (unsigned short) (aBgColor.Green() * 0xFFFF); glXGetConfig (aDisp, aVis, GLX_DOUBLEBUFFER, &isDoubleBuffer);
color.blue = (unsigned short) (aBgColor.Blue() * 0xFFFF); glXGetConfig (aDisp, aVis, GLX_STEREO, &isStereo);
color.flags = DoRed | DoGreen | DoBlue; glXGetConfig (aDisp, aVis, GLX_DEPTH_SIZE, &aDepthSize);
XAllocColor (aDisp, cmap, &color); glXGetConfig (aDisp, aVis, GLX_STENCIL_SIZE, &aStencilSize);
if (aDepthSize < 1) addMsgToList (aList, "no depth buffer");
XSetWindowAttributes cwa; if (aStencilSize < 1) addMsgToList (aList, "no stencil buffer");
cwa.colormap = cmap; if (isRGBA == 0) addMsgToList (aList, "no RGBA color buffer");
cwa.event_mask = StructureNotifyMask; if (isDoubleBuffer == 0) addMsgToList (aList, "no Double Buffer");
cwa.border_pixel = color.pixel; if (theCaps->contextStereo && isStereo == 0)
cwa.background_pixel = color.pixel; {
addMsgToList (aList, "no Quad Buffer");
if (aVis->visualid == wattr.visual->visualid) }
{ else if (!theCaps->contextStereo && isStereo == 1)
aWindow = aParent; {
} addMsgToList (aList, "extra Quad Buffer");
else }
{ if (!aList.IsEmpty())
unsigned long mask = CWBackPixel | CWColormap | CWBorderPixel | CWEventMask; {
aWindow = XCreateWindow (aDisp, aParent, 0, 0, myWidth, myHeight, 0/*bw*/, aVis->depth, InputOutput, aVis->visual, mask, &cwa); 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,
XSetWindowBackground (aDisp, aWindow, cwa.background_pixel); 0, GL_DEBUG_SEVERITY_MEDIUM_ARB, aMsg);
XClearWindow (aDisp, aWindow);
if (aWindow != aParent)
{
XEvent anEvent;
XMapWindow (aDisp, aWindow);
XIfEvent (aDisp, &anEvent, WaitForNotify, (char* )aWindow);
}
} }
myGlContext->Init ((Aspect_Drawable )aWindow, (Aspect_Display )aDisp, (Aspect_RenderingContext )aGContext, isCoreProfile); myGlContext->Init ((Aspect_Drawable )aWindow, (Aspect_Display )aDisp, (Aspect_RenderingContext )aGContext, isCoreProfile);

View File

@ -68,7 +68,7 @@ public:
Standard_EXPORT void SetCursor (const Aspect_Handle aCursor) const; Standard_EXPORT void SetCursor (const Aspect_Handle aCursor) const;
//! Opens the window <me>. //! 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>. //! Opens a window <me> according to <aMapMode>.
//! This method is specific to Windows NT. //! This method is specific to Windows NT.
@ -77,45 +77,46 @@ public:
Standard_EXPORT void Map (const Standard_Integer aMapMode) const; Standard_EXPORT void Map (const Standard_Integer aMapMode) const;
//! Closes the window <me>. //! 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>. //! 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> //! Apply the mapping change to the window <me>
//! and returns TRUE if the window is mapped at screen. //! 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. //! 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); 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 //! Returns True if the window <me> is opened
//! and False if the window is closed. //! 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 //! Returns The Window RATIO equal to the physical
//! WIDTH/HEIGHT dimensions. //! 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 //! 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 //! 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>. //! 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>. //! Returns the Windows NT handle parent of the created window <me>.
Aspect_Handle HParentWindow() const; Aspect_Handle HParentWindow() const;
//! Returns native Window handle (HWND) //! 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) //! 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) DEFINE_STANDARD_RTTI(WNT_Window,Aspect_Window)

56
src/Xw/Xw_Window.cxx Executable file → Normal file
View File

@ -26,8 +26,7 @@ namespace
{ {
//! Search for RGBA double-buffered visual with stencil buffer. //! Search for RGBA double-buffered visual with stencil buffer.
//! Each size property should be a nonnegative minimum specification. static int TheDoubleBuffVisual[] =
static int TheDoubleBuff[] =
{ {
GLX_RGBA, GLX_RGBA,
GLX_DEPTH_SIZE, 16, GLX_DEPTH_SIZE, 16,
@ -36,8 +35,20 @@ namespace
None 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 // function : Xw_Window
@ -48,10 +59,12 @@ Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay,
const Standard_Integer thePxLeft, const Standard_Integer thePxLeft,
const Standard_Integer thePxTop, const Standard_Integer thePxTop,
const Standard_Integer thePxWidth, const Standard_Integer thePxWidth,
const Standard_Integer thePxHeight) const Standard_Integer thePxHeight,
const Aspect_FBConfig theFBConfig)
: Aspect_Window(), : Aspect_Window(),
myDisplay (theXDisplay), myDisplay (theXDisplay),
myXWindow (0), myXWindow (0),
myFBConfig (theFBConfig),
myXLeft (thePxLeft), myXLeft (thePxLeft),
myYTop (thePxTop), myYTop (thePxTop),
myXRight (thePxLeft + thePxWidth), myXRight (thePxLeft + thePxWidth),
@ -77,8 +90,37 @@ Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay,
Display* aDisp = myDisplay->GetDisplay(); Display* aDisp = myDisplay->GetDisplay();
int aScreen = DefaultScreen(aDisp); int aScreen = DefaultScreen(aDisp);
Window aParent = RootWindow (aDisp, aScreen); 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) if (aVisInfo == NULL)
{ {
Aspect_WindowDefinitionError::Raise ("Xw_Window, couldn't find compatible Visual (RGBA, double-buffered)"); 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 : // purpose :
// ======================================================================= // =======================================================================
Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay, Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay,
const Window theXWin) const Window theXWin,
const Aspect_FBConfig theFBConfig)
: Aspect_Window(), : Aspect_Window(),
myDisplay (theXDisplay), myDisplay (theXDisplay),
myXWindow (theXWin), myXWindow (theXWin),
myFBConfig (theFBConfig),
myXLeft (0), myXLeft (0),
myYTop (0), myYTop (0),
myXRight (512), myXRight (512),

33
src/Xw/Xw_Window.hxx Executable file → Normal file
View File

@ -50,11 +50,13 @@ public:
const Standard_Integer thePxLeft, const Standard_Integer thePxLeft,
const Standard_Integer thePxTop, const Standard_Integer thePxTop,
const Standard_Integer thePxWidth, const Standard_Integer thePxWidth,
const Standard_Integer thePxHeight); const Standard_Integer thePxHeight,
const Aspect_FBConfig theFBConfig = NULL);
//! Creates a wrapper over existing Window handle //! Creates a wrapper over existing Window handle
Standard_EXPORT Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay, 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 //! Destroies the Window and all resourses attached to it
Standard_EXPORT virtual void Destroy(); Standard_EXPORT virtual void Destroy();
@ -65,32 +67,32 @@ public:
} }
//! Opens the window <me> //! Opens the window <me>
Standard_EXPORT virtual void Map() const; Standard_EXPORT virtual void Map() const Standard_OVERRIDE;
//! Closes the window <me> //! 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> //! 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> //! 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 //! 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 //! 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 //! Returns The Window POSITION in PIXEL
Standard_EXPORT virtual void Position (Standard_Integer& X1, Standard_EXPORT virtual void Position (Standard_Integer& X1,
Standard_Integer& Y1, Standard_Integer& Y1,
Standard_Integer& X2, Standard_Integer& X2,
Standard_Integer& Y2) const; Standard_Integer& Y2) const Standard_OVERRIDE;
//! Returns The Window SIZE in PIXEL //! Returns The Window SIZE in PIXEL
Standard_EXPORT virtual void Size (Standard_Integer& theWidth, Standard_EXPORT virtual void Size (Standard_Integer& theWidth,
Standard_Integer& theHeight) const; Standard_Integer& theHeight) const Standard_OVERRIDE;
//! @return native Window handle //! @return native Window handle
Standard_EXPORT Window XWindow() const; Standard_EXPORT Window XWindow() const;
@ -99,21 +101,28 @@ public:
Standard_EXPORT const Handle(Aspect_DisplayConnection)& DisplayConnection() const; Standard_EXPORT const Handle(Aspect_DisplayConnection)& DisplayConnection() const;
//! @return native Window handle //! @return native Window handle
virtual Aspect_Drawable NativeHandle() const virtual Aspect_Drawable NativeHandle() const Standard_OVERRIDE
{ {
return (Aspect_Drawable )XWindow(); return (Aspect_Drawable )XWindow();
} }
//! @return parent of native Window handle //! @return parent of native Window handle
virtual Aspect_Drawable NativeParentHandle() const virtual Aspect_Drawable NativeParentHandle() const Standard_OVERRIDE
{ {
return 0; return 0;
} }
//! @return native Window FB config (GLXFBConfig on Xlib)
virtual Aspect_FBConfig NativeFBConfig() const Standard_OVERRIDE
{
return myFBConfig;
}
protected: protected:
Handle(Aspect_DisplayConnection) myDisplay; //!< X Display connection Handle(Aspect_DisplayConnection) myDisplay; //!< X Display connection
Window myXWindow; //!< XLib window handle Window myXWindow; //!< XLib window handle
Aspect_FBConfig myFBConfig; //!< GLXFBConfig
Standard_Integer myXLeft; //!< left position in pixels Standard_Integer myXLeft; //!< left position in pixels
Standard_Integer myYTop; //!< top position in pixels Standard_Integer myYTop; //!< top position in pixels
Standard_Integer myXRight; //!< right position in pixels Standard_Integer myXRight; //!< right position in pixels