diff options
| author | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-10 16:58:26 +0100 |
|---|---|---|
| committer | Fabrice <fabrice@schaub-dev.xyz> | 2026-02-10 16:58:26 +0100 |
| commit | 394cbd934f5771907aeb07480ecb19b9fe618bbd (patch) | |
| tree | 42eab799a4545d0995408e65c62948e3acc4c602 /src | |
| parent | 41ce98080cbd98fb2d57b0686ed5297d8fcc9cf3 (diff) | |
graphics stuff
Diffstat (limited to 'src')
| -rw-r--r-- | src/graphics.cc | 49 | ||||
| -rw-r--r-- | src/graphics.h | 40 |
2 files changed, 87 insertions, 2 deletions
diff --git a/src/graphics.cc b/src/graphics.cc index 0e34213..9027400 100644 --- a/src/graphics.cc +++ b/src/graphics.cc @@ -3,6 +3,8 @@ #include <EGL/egl.h> #include <EGL/eglplatform.h> +#include <cstring> + #include "utils.h" #include "wlstate.h" @@ -44,6 +46,7 @@ enum graphics_error_e wayc_graphics_init(struct graphics_s* graphics, struct wlstate_s* state) { wayc_notnull(graphics); wayc_notnull(state); + memset(graphics, 0, sizeof(*graphics)); EGLDisplay display = eglGetDisplay(state->display); if (display == EGL_NO_DISPLAY) return GRAPHICS_ERROR_ACQUIRE_DISPLAY; @@ -90,3 +93,49 @@ void wayc_graphics_deinit(struct graphics_s* graphics) { graphics->display = nullptr; graphics->context = nullptr; } + +enum renderer_error_e wayc_renderer_init(struct renderer_s* renderer, + struct window_s* window, + struct graphics_s* graphics, i32 width, + i32 height) { + wayc_notnull(renderer); + wayc_notnull(window); + wayc_notnull(graphics); + memset(renderer, 0, sizeof(*renderer)); + + wl_egl_window_t ewindow = + wl_egl_window_create(window->surface, width, height); + if (ewindow == nullptr) return RENDERER_ERROR_WINDOW_CREATION; + + EGLNativeWindowType nwindow = (EGLNativeWindowType)ewindow; + + EGLSurface esurface = eglCreateWindowSurface( + graphics->display, graphics->config, nwindow, nullptr); + if (esurface == EGL_NO_SURFACE) { + wl_egl_window_destroy(ewindow); + return RENDERER_ERROR_SURFACE_CREATION; + } + + renderer->graphics = graphics; + renderer->ewindow = ewindow; + renderer->esurface = esurface; + renderer->width = width; + renderer->height = height; + + return RENDERER_ERROR_NONE; +} + +void wayc_renderer_deinit(struct renderer_s* renderer) { + wayc_notnull(renderer); + + if (renderer->graphics == nullptr || renderer->esurface == nullptr || + renderer->ewindow == nullptr) + return; + + eglDestroySurface(renderer->graphics->display, renderer->esurface); + wl_egl_window_destroy(renderer->ewindow); + + renderer->graphics = nullptr; + renderer->esurface = nullptr; + renderer->ewindow = nullptr; +} diff --git a/src/graphics.h b/src/graphics.h index 56d16de..0dd916e 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -4,6 +4,7 @@ #include <wayland-egl.h> #include "utils.h" +#include "window.h" enum graphics_error_e : u8 { GRAPHICS_ERROR_NONE = 0, @@ -25,10 +26,45 @@ 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, }; struct renderer_s { struct graphics_s* graphics; - wl_egl_window_t window; - EGLSurface surface; + 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); |
