#pragma once #include #include #include "utils.h" #include "window.h" enum graphics_error_e : u8 { GRAPHICS_ERROR_NONE = 0, GRAPHICS_ERROR_ACQUIRE_DISPLAY, GRAPHICS_ERROR_SELECT_CONFIG, GRAPHICS_ERROR_USE_DESKTOP, GRAPHICS_ERROR_CREATE_CONTEXT, }; struct graphics_s { EGLDisplay display; EGLContext context; EGLConfig config; }; enum graphics_error_e wayc_graphics_init(struct graphics_s* graphics, struct wlstate_s* state); void wayc_graphics_deinit(struct graphics_s* graphics); enum renderer_error_e : u8 { RENDERER_ERROR_NONE = 0, RENDERER_ERROR_WINDOW_CREATION, RENDERER_ERROR_SURFACE_CREATION, RENDERER_ERROR_LOAD_FUNCTIONS, }; struct renderer_s { struct graphics_s* graphics; wl_egl_window_t ewindow; EGLSurface esurface; i32 width, height; }; enum renderer_error_e wayc_renderer_init(struct renderer_s* renderer, struct window_s* window, struct graphics_s* graphics, i32 width, i32 height); static inline void wayc_renderer_resize(struct renderer_s* renderer, i32 width, i32 height) { wayc_notnull(renderer); renderer->width = width; renderer->height = height; wl_egl_window_resize(renderer->ewindow, width, height, 0, 0); } static inline void wayc_renderer_use(struct renderer_s* renderer) { wayc_notnull(renderer); struct graphics_s* graphics = renderer->graphics; EGLDisplay display = graphics->display; eglMakeCurrent(display, renderer->esurface, renderer->esurface, graphics->context); } static inline void wayc_renderer_swap(struct renderer_s* renderer) { wayc_notnull(renderer); struct graphics_s* graphics = renderer->graphics; EGLDisplay display = graphics->display; eglSwapBuffers(display, renderer->esurface); } void wayc_renderer_deinit(struct renderer_s* renderer);