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