]> git.sesse.net Git - nageru/blob - context.cpp
Run IWYU (plus lots of manual fiddling).
[nageru] / context.cpp
1 #include <stdio.h>
2
3 #include <QGL>
4 #include <QOffscreenSurface>
5 #include <QOpenGLContext>
6 #include <QSurfaceFormat>
7
8 class QSurface;
9
10 QGLWidget *global_share_widget = nullptr;
11
12 QSurface *create_surface(const QSurfaceFormat &format)
13 {
14         QOffscreenSurface *surface = new QOffscreenSurface;
15         surface->setFormat(format);
16 //      QWindow *surface = new QWindow;
17         surface->create();
18         if (!surface->isValid()) {
19                 printf("ERROR: surface not valid!\n");
20 //              abort();
21         }
22         return surface;
23 }
24
25 QOpenGLContext *create_context()
26 {
27         QOpenGLContext *context = new QOpenGLContext;
28         context->setShareContext(global_share_widget->context()->contextHandle());
29         context->create();
30         return context;
31 }
32
33 bool make_current(QOpenGLContext *context, QSurface *surface)
34 {
35         return context->makeCurrent(surface);
36 }