aboutsummaryrefslogtreecommitdiff
path: root/src/graphics/backend/graphics.c
blob: 201b9e3799f4ad02fb5248efcf1a7af6251ad74b (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "../../../include/mgl/graphics/backend/graphics.h"
#include "../../../include/mgl/graphics/backend/glx.h"
#include "../../../include/mgl/graphics/backend/egl.h"
#include "../../../include/mgl/mgl.h"

#include <string.h>

bool mgl_graphics_init(mgl_graphics *self, const mgl_graphics_create_params *params) {
    memset(self, 0, sizeof(*self));
    self->graphics_api = params ? params->graphics_api : MGL_GRAPHICS_API_EGL;
    self->alpha = params && params->alpha;

    switch(self->graphics_api) {
        case MGL_GRAPHICS_API_GLX:
            return mgl_graphics_glx_init(self);
        case MGL_GRAPHICS_API_EGL:
            return mgl_graphics_egl_init(self);
    }
    return false;
}

void mgl_graphics_deinit(mgl_graphics *self) {
    if(self->deinit)
        self->deinit(self);
}

bool mgl_graphics_make_context_current(mgl_graphics *self, mgl_window_handle window) {
    const bool result = self->make_context_current(self, window);
    if(result) {
        mgl_context *context = mgl_get_context();
        context->gl.glEnable(GL_TEXTURE_2D);
        context->gl.glEnable(GL_BLEND);
        context->gl.glEnable(GL_SCISSOR_TEST);
        context->gl.glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
        context->gl.glEnableClientState(GL_VERTEX_ARRAY);
        context->gl.glEnableClientState(GL_TEXTURE_COORD_ARRAY);
        context->gl.glEnableClientState(GL_COLOR_ARRAY);
        context->gl.glPixelStorei(GL_PACK_ALIGNMENT, 1);
        context->gl.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    }
    return result;
}

void mgl_graphics_swap_buffers(mgl_graphics *self, mgl_window_handle window) {
    self->swap_buffers(self, window);
}

bool mgl_graphics_set_swap_interval(mgl_graphics *self, mgl_window_handle window, bool enabled) {
    return self->set_swap_interval(self, window, enabled);
}

void* mgl_graphics_get_xvisual_info(mgl_graphics *self) {
    return self->get_xvisual_info(self);
}

void* mgl_graphics_get_display(mgl_graphics *self) {
    if(self->get_display)
        return self->get_display(self);
    else
        return NULL;
}

void* mgl_graphics_get_context(mgl_graphics *self) {
    if(self->get_context)
        return self->get_context(self);
    else
        return NULL;
}