Skip to content

Commit da1a26d

Browse files
committed
Introduce Wayland support
The patch requires OCCT with Wayland-compatibility patches. Wayland support is enabled via HAVE_WAYLAND macros.
1 parent 7056256 commit da1a26d

6 files changed

Lines changed: 62 additions & 37 deletions

File tree

occt-qopenglwidget/OcctQOpenGLWidgetViewer.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,14 @@
2424
#include <Message.hxx>
2525
#include <OpenGl_GraphicDriver.hxx>
2626

27-
#if !defined(__APPLE__) && !defined(_WIN32) && defined(__has_include)
28-
#if __has_include(<Xw_DisplayConnection.hxx>)
29-
#include <Xw_DisplayConnection.hxx>
30-
#define USE_XW_DISPLAY
31-
#endif
32-
#endif
33-
#ifndef USE_XW_DISPLAY
34-
typedef Aspect_DisplayConnection Xw_DisplayConnection;
35-
#endif
36-
3727
// ================================================================
3828
// Function : OcctQOpenGLWidgetViewer
3929
// ================================================================
4030
OcctQOpenGLWidgetViewer::OcctQOpenGLWidgetViewer(QWidget* theParent)
4131
: QOpenGLWidget(theParent)
4232
{
4333
Handle(Aspect_DisplayConnection) aDisp;
44-
#if !defined(__APPLE__) && !defined(_WIN32)
34+
#if !defined(__APPLE__) && !defined(_WIN32) && !defined(HAVE_WAYLAND)
4535
aDisp = new Xw_DisplayConnection();
4636
#endif
4737
Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver(aDisp, false);

occt-qt-tools/OcctGlTools.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include <OpenGl_View.hxx>
1313
#include <OpenGl_Window.hxx>
1414

15+
#if defined(HAVE_WAYLAND) || defined(HAVE_GLES2)
16+
#include <EGL/egl.h>
17+
#endif
18+
1519
// Exporting this symbol from .exe with value=1 will direct to NVIDIA GPU on Optimus systems
1620
//__declspec(dllexport) DWORD NvOptimusEnablement = 1;
1721
// Exporting this symbol from .exe with value=1 will direct to faster GPU on AMD PowerXpress systems
@@ -96,6 +100,25 @@ bool OcctGlTools::InitializeGlWindow(const Handle(V3d_View)& theView,
96100
{
97101
aWindow = new OcctNeutralWindow();
98102
aWindow->SetVirtual(true);
103+
104+
#if defined(HAVE_WAYLAND) || defined(HAVE_GLES2)
105+
// wrap EGL surface
106+
EGLContext anEglCtx = eglGetCurrentContext();
107+
EGLContext anEglDisplay = eglGetCurrentDisplay();
108+
EGLContext anEglSurf = eglGetCurrentSurface(EGL_DRAW);
109+
110+
EGLint anEglCfgId = 0, aNbConfigs = 0;
111+
eglQuerySurface(anEglDisplay, anEglSurf, EGL_CONFIG_ID, &anEglCfgId);
112+
const EGLint aConfigAttribs[] = { EGL_CONFIG_ID, anEglCfgId, EGL_NONE };
113+
void* anEglCfg = nullptr;
114+
eglChooseConfig(anEglDisplay, aConfigAttribs, &anEglCfg, 1, &aNbConfigs);
115+
116+
if (!aDriver->InitEglContext(anEglDisplay, anEglCtx, anEglCfg))
117+
{
118+
Message::SendFail() << "Error: OpenGl_GraphicDriver cannot initialize EGL context";
119+
return false;
120+
}
121+
#endif
99122
}
100123
aWindow->SetNativeHandle(aNativeWin);
101124
aWindow->SetSize(theSize.x(), theSize.y());
@@ -118,20 +141,21 @@ bool OcctGlTools::InitializeGlWindow(const Handle(V3d_View)& theView,
118141
// ================================================================
119142
bool OcctGlTools::InitializeGlFbo(const Handle(V3d_View)& theView)
120143
{
121-
Handle(OpenGl_Context) aGlCtx = OcctGlTools::GetGlContext(theView);
122-
Handle(OpenGl_FrameBuffer) aDefaultFbo = aGlCtx->DefaultFrameBuffer();
144+
Handle(OpenGl_Context) aGlCtx = OcctGlTools::GetGlContext(theView);
145+
Handle(OcctQtFrameBuffer) aDefaultFbo = Handle(OcctQtFrameBuffer)::DownCast(aGlCtx->DefaultFrameBuffer());
123146
if (aDefaultFbo.IsNull())
124-
{
125147
aDefaultFbo = new OcctQtFrameBuffer();
126-
aGlCtx->SetDefaultFrameBuffer(aDefaultFbo);
127-
}
148+
128149
if (!aDefaultFbo->InitWrapper(aGlCtx))
129150
{
130151
aDefaultFbo.Nullify();
131152
Message::DefaultMessenger()->Send("Default FBO wrapper creation failed", Message_Fail);
132153
return false;
133154
}
134155

156+
// workaround some bugs (legacy code in OpenGl_Window::init() for surface-less EGL context)
157+
aGlCtx->SetDefaultFrameBuffer(Handle(OpenGl_FrameBuffer)());
158+
135159
Graphic3d_Vec2i aViewSizeOld;
136160
const Graphic3d_Vec2i aViewSizeNew = aDefaultFbo->GetVPSize();
137161
Handle(OcctNeutralWindow) aWindow = Handle(OcctNeutralWindow)::DownCast(theView->Window());
@@ -150,6 +174,7 @@ bool OcctGlTools::InitializeGlFbo(const Handle(V3d_View)& theView)
150174
}
151175
#endif
152176
}
177+
aGlCtx->SetDefaultFrameBuffer(aDefaultFbo);
153178
return true;
154179
}
155180

@@ -173,11 +198,13 @@ void OcctGlTools::ResetGlStateBeforeOcct(const Handle(V3d_View)& theView)
173198
// Disable also texture bindings left by Qt.
174199
aGlCtx->core11fwd->glBindTexture(GL_TEXTURE_2D, 0);
175200
aGlCtx->core11fwd->glDisable(GL_BLEND);
201+
#ifndef HAVE_GLES2
176202
if (aGlCtx->core11ffp != nullptr)
177203
{
178204
aGlCtx->core11fwd->glDisable(GL_ALPHA_TEST);
179205
aGlCtx->core11fwd->glDisable(GL_TEXTURE_2D);
180206
}
207+
#endif
181208
}
182209

183210
// ================================================================

occt-qt-tools/OcctGlTools.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,20 @@
33
#ifndef _OcctGlTools_HeaderFile
44
#define _OcctGlTools_HeaderFile
55

6+
#include <Aspect_DisplayConnection.hxx>
67
#include <Aspect_NeutralWindow.hxx>
78
#include <V3d_View.hxx>
89

10+
#if !defined(__APPLE__) && !defined(_WIN32) && defined(__has_include)
11+
#if __has_include(<Xw_DisplayConnection.hxx>)
12+
#include <Xw_DisplayConnection.hxx>
13+
#define USE_XW_DISPLAY
14+
#endif
15+
#endif
16+
#ifndef USE_XW_DISPLAY
17+
typedef Aspect_DisplayConnection Xw_DisplayConnection;
18+
#endif
19+
920
class OpenGl_Context;
1021

1122
//! Auxiliary wrapper to avoid OpenGL macros collisions between Qt and OCCT headers.

occt-qt-tools/OcctQtTools.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ void OcctQtTools::qtGlPlatformSetup()
131131
QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
132132
#elif defined(__APPLE__)
133133
//
134+
#elif defined(HAVE_WAYLAND)
135+
OSD_Environment aQpaPlat("QT_QPA_PLATFORM");
136+
if (aQpaPlat.Value().IsEmpty())
137+
{
138+
aQpaPlat.SetValue("wayland");
139+
aQpaPlat.Build();
140+
}
134141
#else
135142
// Qt6 tries to use Wayland platform by default, which is incompatible with OCCT depending on Xlib;
136143
// Force 'xcb' platform plugin (alternatively, could be passed QApplication as '-platform xcb' argument).

occt-qtquick/OcctQQuickFramebufferViewer.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,14 @@
2727
#include <OpenGl_GraphicDriver.hxx>
2828
#include <WNT_HIDSpaceMouse.hxx>
2929

30-
#if !defined(__APPLE__) && !defined(_WIN32) && defined(__has_include)
31-
#if __has_include(<Xw_DisplayConnection.hxx>)
32-
#include <Xw_DisplayConnection.hxx>
33-
#define USE_XW_DISPLAY
34-
#endif
35-
#endif
36-
#ifndef USE_XW_DISPLAY
37-
typedef Aspect_DisplayConnection Xw_DisplayConnection;
38-
#endif
39-
4030
// ================================================================
4131
// Function : OcctQQuickFramebufferViewer
4232
// ================================================================
4333
OcctQQuickFramebufferViewer::OcctQQuickFramebufferViewer(QQuickItem* theParent)
4434
: QQuickFramebufferObject(theParent)
4535
{
4636
Handle(Aspect_DisplayConnection) aDisp;
47-
#if !defined(__APPLE__) && !defined(_WIN32)
37+
#if !defined(__APPLE__) && !defined(_WIN32) && !defined(HAVE_WAYLAND)
4838
aDisp = new Xw_DisplayConnection();
4939
#endif
5040
Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver(aDisp, false);

occt-qwidget/OcctQWidgetViewer.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,7 @@
2323
#include <Message.hxx>
2424
#include <OpenGl_GraphicDriver.hxx>
2525

26-
#if !defined(__APPLE__) && !defined(_WIN32) && defined(__has_include)
27-
#if __has_include(<Xw_DisplayConnection.hxx>)
28-
#include <Xw_DisplayConnection.hxx>
29-
#define USE_XW_DISPLAY
30-
#endif
31-
#endif
32-
#ifndef USE_XW_DISPLAY
33-
typedef Aspect_DisplayConnection Xw_DisplayConnection;
34-
#endif
26+
#include <Wayland_DisplayConnection.hxx>
3527

3628
// ================================================================
3729
// Function : OcctQWidgetViewer
@@ -40,10 +32,18 @@ OcctQWidgetViewer::OcctQWidgetViewer(QWidget* theParent)
4032
: QWidget(theParent)
4133
{
4234
Handle(Aspect_DisplayConnection) aDisp;
43-
#if !defined(__APPLE__) && !defined(_WIN32)
35+
#if defined(HAVE_WAYLAND)
36+
aDisp = new Wayland_DisplayConnection();
37+
#elif !defined(__APPLE__) && !defined(_WIN32)
4438
aDisp = new Xw_DisplayConnection();
4539
#endif
4640
Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver(aDisp, false);
41+
#if defined(HAVE_WAYLAND)
42+
//if (!aDriver->InitContext())
43+
{
44+
// TODO need to wrap Wayland display connection from Qt?
45+
}
46+
#endif
4747

4848
// create viewer
4949
myViewer = new V3d_Viewer(aDriver);

0 commit comments

Comments
 (0)