summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGL/GLContext.cpp
blob: 4c8f7dc977456d82609fa2f87d28b9e32c7d2d2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
 * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include "GLContext.h"
#include "SoftwareGLContext.h"
#include <LibGfx/Bitmap.h>

__attribute__((visibility("hidden"))) GL::GLContext* g_gl_context;

namespace GL {

GLContext::~GLContext()
{
    if (g_gl_context == this)
        make_context_current(nullptr);
}

OwnPtr<GLContext> create_context(Gfx::Bitmap& bitmap)
{
    auto context = adopt_own(*new SoftwareGLContext(bitmap));

    if (!g_gl_context)
        g_gl_context = context;

    return context;
}

void make_context_current(GLContext* context)
{
    g_gl_context = context;
}

void present_context(GLContext* context)
{
    context->present();
}

}