From 5f33cfecf1a06bc2120b7d3cc3f10efa08c33362 Mon Sep 17 00:00:00 2001 From: Igor Chernakov Date: Thu, 24 Sep 2026 16:03:07 +0200 Subject: [PATCH 1/3] Declare sRGB output on window surfaces --- ios/ios_window.m | 7 +++++++ macos/macos_window.m | 3 ++- wayland/wayland_egl.c | 15 ++++++++++----- x11/x11_egl.c | 24 +++++++++++++++++++++++- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/ios/ios_window.m b/ios/ios_window.m index e6a0aa9..9111a1f 100644 --- a/ios/ios_window.m +++ b/ios/ios_window.m @@ -304,6 +304,13 @@ bool_t axCreateWindow(const char *title, uint32_t w, uint32_t h, uint32_t flags) ios_view.contentScaleFactor = ios_scale; CAEAGLLayer *layer = (CAEAGLLayer *)ios_view.layer; layer.opaque = YES; + CGColorSpaceRef color_space = CGColorSpaceCreateWithName(kCGColorSpaceSRGB); + if (color_space) { + layer.colorspace = color_space; + CGColorSpaceRelease(color_space); + } else { + IOS_TRACE("sRGB drawable color space unavailable; using platform default"); + } layer.drawableProperties = @{kEAGLDrawablePropertyRetainedBacking: @YES, kEAGLDrawablePropertyColorFormat: kEAGLColorFormatRGBA8}; glGenFramebuffers(1, &ios_framebuffer); glGenRenderbuffers(1, &ios_color); diff --git a/macos/macos_window.m b/macos/macos_window.m index 54fb1ee..e64a1c1 100644 --- a/macos/macos_window.m +++ b/macos/macos_window.m @@ -283,7 +283,8 @@ static void ConfigureOpenGLView(NSOpenGLView *openglView, uint32_t flags) { [delegate setWindow:window]; - [window setFrameOrigin:windowRect.origin]; + [window setFrameOrigin:windowRect.origin]; + [window setColorSpace:[NSColorSpace sRGBColorSpace]]; [window setTitle:windowTitle]; [window setReleasedWhenClosed:NO]; [window setAcceptsMouseMovedEvents:YES]; diff --git a/wayland/wayland_egl.c b/wayland/wayland_egl.c index 0b2ce24..74015fd 100644 --- a/wayland/wayland_egl.c +++ b/wayland/wayland_egl.c @@ -1,4 +1,5 @@ #include "wayland_local.h" +#include #define WIDTH 640 #define HEIGHT 480 @@ -131,14 +132,18 @@ create_window(struct _WND* window, int32_t width, int32_t height) EGL_NONE }; window->egl_surface = eglCreateWindowSurface(egl_display, config, window->egl_window, surface_attributes); - if (!window->egl_window) { - printf("Failed to create sRGB EGL surface, trying regular RGB!\n"); + if (window->egl_surface == EGL_NO_SURFACE) { + fprintf(stderr, "[wayland] sRGB EGL surface failed error=0x%x; trying default RGB surface\n", + eglGetError()); + fflush(stderr); window->egl_surface = eglCreateWindowSurface(egl_display, config, window->egl_window, NULL); } else { - printf("Created sRGB EGL surface\n"); + fprintf(stderr, "[wayland] created sRGB EGL surface\n"); + fflush(stderr); } - if (!window->egl_window) { - printf("Failed to create EGL surface!\n"); + if (window->egl_surface == EGL_NO_SURFACE) { + fprintf(stderr, "[wayland] EGL surface creation failed error=0x%x\n", eglGetError()); + fflush(stderr); return; } eglMakeCurrent(egl_display, window->egl_surface, window->egl_surface, window->egl_context); diff --git a/x11/x11_egl.c b/x11/x11_egl.c index bff1595..849972a 100644 --- a/x11/x11_egl.c +++ b/x11/x11_egl.c @@ -1,5 +1,6 @@ #include "x11_local.h" #include "../platform.h" +#include #define WIDTH 640 #define HEIGHT 480 @@ -87,8 +88,29 @@ create_window(struct _WND* win, int32_t width, int32_t height) XFlush(x_display); win->egl_context = eglCreateContext(egl_display, egl_config, EGL_NO_CONTEXT, NULL); + EGLint surface_attributes[] = { + EGL_GL_COLORSPACE, EGL_GL_COLORSPACE_SRGB, + EGL_NONE + }; + int surface_srgb = 1; win->egl_surface = eglCreateWindowSurface(egl_display, egl_config, - (EGLNativeWindowType)x_window, NULL); + (EGLNativeWindowType)x_window, + surface_attributes); + if (win->egl_surface == EGL_NO_SURFACE) { + surface_srgb = false; + fprintf(stderr, "[x11] sRGB EGL surface failed error=0x%x; trying default RGB surface\n", + eglGetError()); + win->egl_surface = eglCreateWindowSurface(egl_display, egl_config, + (EGLNativeWindowType)x_window, NULL); + } + if (win->egl_surface == EGL_NO_SURFACE) { + fprintf(stderr, "[x11] EGL surface creation failed error=0x%x\n", eglGetError()); + fflush(stderr); + return; + } + fprintf(stderr, "[x11] EGL output surface color space=%s\n", + surface_srgb ? "sRGB" : "platform default fallback"); + fflush(stderr); eglMakeCurrent(egl_display, win->egl_surface, win->egl_surface, win->egl_context); win->width = width; From 7a1bdde9b5534a5d908d8d7d41200237a936f55f Mon Sep 17 00:00:00 2001 From: Igor Chernakov Date: Thu, 24 Sep 2026 16:34:15 +0200 Subject: [PATCH 2/3] Fix X11 sRGB surface fallback build --- x11/x11_egl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x11/x11_egl.c b/x11/x11_egl.c index 849972a..8b1eafa 100644 --- a/x11/x11_egl.c +++ b/x11/x11_egl.c @@ -97,7 +97,7 @@ create_window(struct _WND* win, int32_t width, int32_t height) (EGLNativeWindowType)x_window, surface_attributes); if (win->egl_surface == EGL_NO_SURFACE) { - surface_srgb = false; + surface_srgb = 0; fprintf(stderr, "[x11] sRGB EGL surface failed error=0x%x; trying default RGB surface\n", eglGetError()); win->egl_surface = eglCreateWindowSurface(egl_display, egl_config, From 82d8b5b8e56c3812af462aa4c644361cb5cb2de0 Mon Sep 17 00:00:00 2001 From: corepunch <83646194+corepunch@users.noreply.github.com> Date: Sat, 3 Oct 2026 06:41:10 +0000 Subject: [PATCH 3/3] Fix API test parsing of one-line declarations The symbol test assumed every AX_API prototype put the function name on the next line. The iOS one-line declarations made it emit assert(AX_API != NULL), which failed the Linux, macOS, Windows, and X11 checks. Parse the declarator before the opening parenthesis, and skip AX_PLATFORM_IOS prototypes unless the build is iOS. Also match the macOS sRGB color-space call to the surrounding indent and flush the X11 fallback error before retrying surface creation. --- Makefile | 8 +++++++- macos/macos_window.m | 2 +- x11/x11_egl.c | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a5543f9..293dbca 100644 --- a/Makefile +++ b/Makefile @@ -147,6 +147,12 @@ $(TARGET): endif +ifeq ($(PLATFORM_OS),ios) +INCLUDE_IOS_API := 1 +else +INCLUDE_IOS_API := 0 +endif + # Parse platform.h to find all AX_API functions, generate a C test that asserts # each function pointer is non-NULL (i.e. the symbol is defined), then compile, # link and run that test against the built library. @@ -156,7 +162,7 @@ test: else test: $(TARGET) @printf '#include "platform.h"\n#include \nint main(void) {\n' > $(TEST_SRC) - @awk '/^AX_API[[:space:]]/{getline; sub(/[(].*/,""); printf " assert(%s != NULL);\n", $$1}' platform.h >> $(TEST_SRC) + @awk -v include_ios=$(INCLUDE_IOS_API) '/^#ifdef AX_PLATFORM_IOS/ { ios=1; next } /^#endif/ && ios { ios=0; next } ios && include_ios != 1 { next } /^AX_API[[:space:]]/ { line=$$0; while (line !~ /;/ && (getline nl) > 0) line=line " " nl; sub(/^AX_API[[:space:]]+/, "", line); n=split(line, parts, "("); if (n < 2) next; m=split(parts[1], toks, /[^A-Za-z0-9_]+/); name=toks[m]; if (name != "") printf " assert(%s != NULL);\n", name }' platform.h >> $(TEST_SRC) @printf ' return 0;\n}\n' >> $(TEST_SRC) @$(CC) -I. $(TEST_SRC) $(TEST_LDFLAGS) -o $(TEST_BIN) @$(TEST_BIN) diff --git a/macos/macos_window.m b/macos/macos_window.m index e64a1c1..d961f5f 100644 --- a/macos/macos_window.m +++ b/macos/macos_window.m @@ -284,7 +284,7 @@ static void ConfigureOpenGLView(NSOpenGLView *openglView, uint32_t flags) { [delegate setWindow:window]; [window setFrameOrigin:windowRect.origin]; - [window setColorSpace:[NSColorSpace sRGBColorSpace]]; + [window setColorSpace:[NSColorSpace sRGBColorSpace]]; [window setTitle:windowTitle]; [window setReleasedWhenClosed:NO]; [window setAcceptsMouseMovedEvents:YES]; diff --git a/x11/x11_egl.c b/x11/x11_egl.c index 8b1eafa..af10eb7 100644 --- a/x11/x11_egl.c +++ b/x11/x11_egl.c @@ -100,6 +100,7 @@ create_window(struct _WND* win, int32_t width, int32_t height) surface_srgb = 0; fprintf(stderr, "[x11] sRGB EGL surface failed error=0x%x; trying default RGB surface\n", eglGetError()); + fflush(stderr); win->egl_surface = eglCreateWindowSurface(egl_display, egl_config, (EGLNativeWindowType)x_window, NULL); }