X-Git-Url: https://git.sesse.net/?p=nageru;a=blobdiff_plain;f=context.cpp;h=eb62183a3b3a8c9c7c9065f6d212a21b92e8257e;hp=72275e9f9ba5db18d039e8c6e577356a6f9aa2b0;hb=4e3c52ba57c4552a969e71ccdefd9941ce8d6290;hpb=e18d9bad93d5bf766d52d0cb66db4c3d3f8a711b diff --git a/context.cpp b/context.cpp index 72275e9..eb62183 100644 --- a/context.cpp +++ b/context.cpp @@ -1,27 +1,40 @@ #include -#include -#include +#include + +#include #include -#include +#include +#include +#include + +QGLWidget *global_share_widget = nullptr; +bool using_egl = false; + +using namespace std; QSurface *create_surface(const QSurfaceFormat &format) { QOffscreenSurface *surface = new QOffscreenSurface; surface->setFormat(format); -// QWindow *surface = new QWindow; surface->create(); if (!surface->isValid()) { - printf("ERROR: surface not valid!\n"); -// abort(); + fprintf(stderr, "ERROR: surface not valid!\n"); + exit(1); } return surface; } -QOpenGLContext *create_context() +QSurface *create_surface_with_same_format(const QSurface *surface) +{ + return create_surface(surface->format()); +} + +QOpenGLContext *create_context(const QSurface *surface) { QOpenGLContext *context = new QOpenGLContext; - context->setShareContext(QOpenGLContext::globalShareContext()); + context->setShareContext(global_share_widget->context()->contextHandle()); + context->setFormat(surface->format()); context->create(); return context; } @@ -30,3 +43,8 @@ bool make_current(QOpenGLContext *context, QSurface *surface) { return context->makeCurrent(surface); } + +void delete_context(QOpenGLContext *context) +{ + delete context; +}