aboutsummaryrefslogtreecommitdiff
path: root/src/saffron_window.c
diff options
context:
space:
mode:
authorArslaan Pathan <[email protected]>2026-09-05 21:34:22 +1200
committerArslaan Pathan <[email protected]>2026-09-05 21:34:22 +1200
commit4e352be0f5828c401176b96af3b703e8a56afb79 (patch)
treed678683f024877e85f990f3f57e26d5880897617 /src/saffron_window.c
parent5ac74b20bfe5842edf404cafd7f82bc8cd1fcb0b (diff)
downloadsaffron-4e352be0f5828c401176b96af3b703e8a56afb79.tar.xz
saffron-4e352be0f5828c401176b96af3b703e8a56afb79.zip
[feat] add some more EGL functions that SFWK needsHEADmain
Diffstat (limited to 'src/saffron_window.c')
-rw-r--r--src/saffron_window.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/saffron_window.c b/src/saffron_window.c
index 085ee20..022c5e4 100644
--- a/src/saffron_window.c
+++ b/src/saffron_window.c
@@ -10,6 +10,90 @@
#include <saffron.h>
#include <SDL3/SDL_egl.h>
#include <SDL3/SDL_opengles2.h>
+#include <EGL/egl.h>
+
+EGLDisplay saffron_window_get_egl_display(SaffronWindow* window) {
+ if (!window || !window->gl_context) {
+ return EGL_NO_DISPLAY;
+ }
+
+ EGLDisplay display = eglGetCurrentDisplay();
+
+ if (display == EGL_NO_DISPLAY) {
+ display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
+ }
+
+ return display;
+}
+
+EGLConfig saffron_window_get_egl_config(SaffronWindow* window) {
+ if (!window || !window->gl_context) {
+ return NULL;
+ }
+
+ EGLDisplay display = saffron_window_get_egl_display(window);
+ if (display == EGL_NO_DISPLAY) {
+ return NULL;
+ }
+
+ EGLConfig config = NULL;
+ EGLint config_id;
+
+ if (eglQueryContext(display, eglGetCurrentContext(), EGL_CONFIG_ID, &config_id)) {
+ EGLint num_configs;
+ EGLConfig configs[32];
+ EGLint attribs[] = {
+ EGL_CONFIG_ID, config_id,
+ EGL_NONE
+ };
+
+ if (eglChooseConfig(display, attribs, configs, 32, &num_configs) && num_configs > 0) {
+ config = configs[0];
+ }
+ }
+
+ if (!config) {
+ EGLint config_attribs[] = {
+ EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
+ EGL_ALPHA_SIZE, 8,
+ EGL_DEPTH_SIZE, 24,
+ EGL_STENCIL_SIZE, 8,
+ EGL_NONE
+ };
+
+ EGLint num_configs;
+ if (eglChooseConfig(display, config_attribs, &config, 1, &num_configs) && num_configs > 0) {
+ return config;
+ }
+ return NULL;
+ }
+
+ return config;
+}
+
+EGLSurface saffron_window_get_egl_surface(SaffronWindow* window) {
+ if (!window || !window->gl_context) {
+ return EGL_NO_SURFACE;
+ }
+
+ EGLSurface surface = eglGetCurrentSurface(EGL_DRAW);
+
+ if (surface == EGL_NO_SURFACE) {
+ EGLDisplay display = saffron_window_get_egl_display(window);
+ EGLConfig config = saffron_window_get_egl_config(window);
+
+ if (display != EGL_NO_DISPLAY && config) {
+ surface = eglCreateWindowSurface(display, config,
+ (EGLNativeWindowType)window->sdl_window, NULL);
+ }
+ }
+
+ return surface;
+}
SaffronWindow* saffron_window_new(const char* title, int w, int h) {
SaffronWindow* window = malloc(sizeof(SaffronWindow));