-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
86 lines (70 loc) · 2.43 KB
/
main.cpp
File metadata and controls
86 lines (70 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <QtQml>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQuickImageProvider>
#include <QQuickItem>
#include <QQuickItemGrabResult>
#include <QQuickView>
#include <QQuickWindow>
#include "OccViewerItem.h"
int main(int argc, char *argv[])
{
#if defined(_WIN32)
// never use ANGLE on Windows, since OCCT 3D Viewer does not expect this
QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL);
#elif defined(__APPLE__)
qputenv("QT_QPA_PLATFORM", "cocoa");
#else
// wayland-egl, minimal, xcb, vnc, linuxfb, eglfs, minimalegl, offscreen,
// wayland, vkkhrdisplay.
qputenv("QT_QPA_PLATFORM", "xcb");
// WSL2-specific workarounds
const char *wslEnv = getenv("WSL_DISTRO_NAME");
if (wslEnv != nullptr)
{
// Force software OpenGL in WSL2 if D3D12 causes issues
// qputenv("LIBGL_ALWAYS_SOFTWARE", "1");
// Disable VSync which can cause issues in WSL2
qputenv("vblank_mode", "0");
qputenv("__GL_SYNC_TO_VBLANK", "0");
// Force OpenGL 3.3 compatibility profile for better WSL2 support
qputenv("MESA_GL_VERSION_OVERRIDE", "3.3COMPAT");
qputenv("MESA_GLSL_VERSION_OVERRIDE", "330");
}
#endif
// Set up OpenGL surface format BEFORE creating QGuiApplication
QSurfaceFormat aGlFormat;
aGlFormat.setDepthBufferSize(24);
aGlFormat.setStencilBufferSize(8);
// Use compatibility profile and fallback version for WSL2
#if defined(_WIN32)
aGlFormat.setVersion(4, 5);
aGlFormat.setProfile(QSurfaceFormat::CoreProfile);
#else
// Use a more compatible version for WSL2/D3D12
aGlFormat.setVersion(3, 3);
aGlFormat.setProfile(QSurfaceFormat::CompatibilityProfile);
#endif
QSurfaceFormat::setDefaultFormat(aGlFormat);
QQuickWindow::setGraphicsApi(QSGRendererInterface::OpenGL);
QGuiApplication app(argc, argv);
// register custom QML type
qmlRegisterType<geotoys::OccViewerItem>("OcctQML", 1, 0, "OccViewerItem");
// use QQuickView to create window and load QML
QQuickView view;
view.setTitle("QML Occ Demo");
view.setResizeMode(QQuickView::SizeRootObjectToView);
view.resize(800, 600);
// load QML file
view.setSource(QUrl("qrc:/main.qml"));
// show window
view.show();
// check if loaded successfully
if (view.status() == QQuickView::Error)
{
qWarning("Failed to load QML file!");
return -1;
}
return app.exec();
}