2 #include <QOffscreenSurface>
3 #include <QOpenGLContext>
5 #include <QSurfaceFormat>
9 QGLWidget *global_share_widget = nullptr;
13 QSurface *create_surface()
16 fmt.setDepthBufferSize(0);
17 fmt.setStencilBufferSize(0);
18 fmt.setProfile(QSurfaceFormat::CoreProfile);
19 fmt.setMajorVersion(4);
20 fmt.setMinorVersion(5);
21 fmt.setSwapInterval(0);
22 QOffscreenSurface *surface = new QOffscreenSurface;
23 surface->setFormat(fmt);
25 if (!surface->isValid()) {
26 fprintf(stderr, "ERROR: surface not valid!\n");
32 QSurface *create_surface(const QSurfaceFormat &format)
34 QOffscreenSurface *surface = new QOffscreenSurface;
35 surface->setFormat(format);
37 if (!surface->isValid()) {
38 fprintf(stderr, "ERROR: surface not valid!\n");
44 QSurface *create_surface_with_same_format(const QSurface *surface)
46 return create_surface(surface->format());
49 QOpenGLContext *create_context(const QSurface *surface)
51 QOpenGLContext *context = new QOpenGLContext;
52 context->setShareContext(global_share_widget->context()->contextHandle());
54 // Qt has a bug (QTBUG-76299) where, when using EGL, the surface ignores
55 // the requested OpenGL context version and just becomes 2.0. Mesa honors
56 // this and gives us a 3.0 compatibility context, but then has a bug related
57 // to its shader cache (Mesa bug #110872) that causes spurious linker failures
58 // when we need to re-link a Movit shader in the same context. However,
59 // the surface itself doesn't use the OpenGL version in its format for anything,
60 // so we can just override it and get a proper context.
61 QSurfaceFormat fmt = surface->format();
62 fmt.setProfile(QSurfaceFormat::CoreProfile);
63 fmt.setMajorVersion(4);
64 fmt.setMinorVersion(5);
65 context->setFormat(fmt);
71 bool make_current(QOpenGLContext *context, QSurface *surface)
73 return context->makeCurrent(surface);
76 void delete_context(QOpenGLContext *context)