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:
parent
a7197ef3c7
commit
b6bf4ec174
24
src/Aspect/Aspect_FBConfig.hxx
Normal file
24
src/Aspect/Aspect_FBConfig.hxx
Normal 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
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include <Aspect_Background.hxx>
|
||||
#include <Aspect_GradientBackground.hxx>
|
||||
#include <Aspect_FBConfig.hxx>
|
||||
#include <Aspect_FillMethod.hxx>
|
||||
#include <Standard_Boolean.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)
|
||||
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)
|
||||
|
||||
|
@ -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
|
||||
|
@ -87,32 +87,32 @@ public:
|
||||
}
|
||||
|
||||
//! 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;
|
||||
|
||||
#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
|
||||
|
@ -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;
|
||||
{
|
||||
unsigned long aVisInfoMask = VisualIDMask | VisualScreenMask;
|
||||
XWindowAttributes aWinAttribs;
|
||||
XGetWindowAttributes (aDisp, aWindow, &aWinAttribs);
|
||||
XVisualInfo aVisInfo;
|
||||
aVisInfo.visualid = wattr.visual->visualid;
|
||||
aVisInfo.screen = scr;
|
||||
aVisInfo.visualid = aWinAttribs.visual->visualid;
|
||||
aVisInfo.screen = DefaultScreen (aDisp);
|
||||
int aNbItems;
|
||||
aVis = XGetVisualInfo (aDisp, aVisInfoMask, &aVisInfo, &aNbItems);
|
||||
}
|
||||
|
||||
#if defined(__linux__) || defined(Linux) || defined(__APPLE__)
|
||||
if (aVis != NULL)
|
||||
{
|
||||
// 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;
|
||||
|
||||
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
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!myOwnGContext)
|
||||
{
|
||||
XVisualInfo* aVis = XGetVisualInfo (aDisp, VisualIDMask | VisualScreenMask, &aVisInfo, &aNbItems);
|
||||
int isGl = 0;
|
||||
if (aVis == NULL)
|
||||
{
|
||||
Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: XGetVisualInfo is unable to choose needed configuration in existing OpenGL context. ");
|
||||
return;
|
||||
}
|
||||
|
||||
aWindow = aParent;
|
||||
}
|
||||
else
|
||||
else if (glXGetConfig (aDisp, aVis, GLX_USE_GL, &isGl) != 0 || !isGl)
|
||||
{
|
||||
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.");
|
||||
Aspect_GraphicDeviceDefinitionError::Raise ("OpenGl_Window::CreateWindow: window Visual does not support GL rendering!");
|
||||
return;
|
||||
}
|
||||
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"))
|
||||
{
|
||||
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);
|
||||
// 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)
|
||||
{
|
||||
int aCoreCtxAttribs[] =
|
||||
{
|
||||
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 (!theShareCtx.IsNull())
|
||||
if (aGContext == NULL)
|
||||
{
|
||||
// ctx est une copie du previous
|
||||
aGContext = glXCreateContext (aDisp, aVis, (GLXContext )theShareCtx->myGContext, GL_TRUE);
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
aGContext = glXCreateContext (aDisp, aVis, NULL, GL_TRUE);
|
||||
}
|
||||
XSetErrorHandler(anOldHandler);
|
||||
}
|
||||
|
||||
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)
|
||||
// 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)
|
||||
{
|
||||
XEvent anEvent;
|
||||
XMapWindow (aDisp, aWindow);
|
||||
XIfEvent (aDisp, &anEvent, WaitForNotify, (char* )aWindow);
|
||||
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);
|
||||
|
@ -68,7 +68,7 @@ public:
|
||||
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.
|
||||
@ -77,31 +77,31 @@ public:
|
||||
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;
|
||||
@ -110,12 +110,13 @@ public:
|
||||
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)
|
||||
|
||||
|
56
src/Xw/Xw_Window.cxx
Executable file → Normal file
56
src/Xw/Xw_Window.cxx
Executable file → Normal file
@ -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),
|
||||
|
33
src/Xw/Xw_Window.hxx
Executable file → Normal file
33
src/Xw/Xw_Window.hxx
Executable file → Normal file
@ -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 <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;
|
||||
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user