summaryrefslogtreecommitdiff
path: root/src/graphics.cc
diff options
context:
space:
mode:
authorFabrice <fabrice@schaub-dev.xyz>2026-02-10 16:58:26 +0100
committerFabrice <fabrice@schaub-dev.xyz>2026-02-10 16:58:26 +0100
commit394cbd934f5771907aeb07480ecb19b9fe618bbd (patch)
tree42eab799a4545d0995408e65c62948e3acc4c602 /src/graphics.cc
parent41ce98080cbd98fb2d57b0686ed5297d8fcc9cf3 (diff)
graphics stuff
Diffstat (limited to 'src/graphics.cc')
-rw-r--r--src/graphics.cc49
1 files changed, 49 insertions, 0 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;
+}