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/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..d961f5f 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..af10eb7 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,30 @@ 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 = 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); + } + 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;