6 #include <QOffscreenSurface>
7 #include <QOpenGLContext>
9 #include <QSurfaceFormat>
11 QGLWidget *global_share_widget = nullptr;
15 QSurface *create_surface()
18 fmt.setDepthBufferSize(0);
19 fmt.setStencilBufferSize(0);
20 fmt.setProfile(QSurfaceFormat::CoreProfile);
21 fmt.setMajorVersion(4);
22 fmt.setMinorVersion(5);
23 fmt.setSwapInterval(0);
24 QOffscreenSurface *surface = new QOffscreenSurface;
25 surface->setFormat(fmt);
27 if (!surface->isValid()) {
28 fprintf(stderr, "ERROR: surface not valid!\n");
34 QSurface *create_surface(const QSurfaceFormat &format)
36 QOffscreenSurface *surface = new QOffscreenSurface;
37 surface->setFormat(format);
39 if (!surface->isValid()) {
40 fprintf(stderr, "ERROR: surface not valid!\n");
46 QSurface *create_surface_with_same_format(const QSurface *surface)
48 return create_surface(surface->format());
51 QOpenGLContext *create_context(const QSurface *surface)
53 QOpenGLContext *context = new QOpenGLContext;
54 context->setShareContext(global_share_widget->context()->contextHandle());
55 context->setFormat(surface->format());
60 bool make_current(QOpenGLContext *context, QSurface *surface)
62 return context->makeCurrent(surface);
65 void delete_context(QOpenGLContext *context)