diff options
Diffstat (limited to 'src/graphics/backend/graphics.c')
-rw-r--r-- | src/graphics/backend/graphics.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/graphics/backend/graphics.c b/src/graphics/backend/graphics.c new file mode 100644 index 0000000..201b9e3 --- /dev/null +++ b/src/graphics/backend/graphics.c @@ -0,0 +1,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; +} |