Ask SDL for a linear framebuffer and wait for the ZX window's first frame

The hosted native ZX test read (244,96,110) where its picture is
(230,30,40), and (252,253,254) for the 0xf8fafc background: the whole
window had been sRGB-encoded a second time. That gate ran with a private
SDK whose libSDL2 is sdl2-compat on SDL 3.4.2. SDL 3 gave raylib's
OpenGL ES context an sRGB-capable framebuffer, and Mesa encodes every
write to one. The system SDL 2 picks a linear visual, so the same player
drew exact colours without the SDK. OpenRaylib now sets
SDL_OPENGL_FORCE_SRGB_FRAMEBUFFER=0 before InitWindow; SDL 3 then
requests a linear framebuffer and turns GL_FRAMEBUFFER_SRGB off, and
classic SDL 2 ignores the hint. Under that SDK the test finds the exact
colours again.

zx_window_test captured the window right after it mapped and sometimes
read X's black contents before the player presented its first frame. It
now waits up to 10 s for the presented frame and keeps the exact
single-colour assertion; the corner pixel is checked before the colour
count, so the wait does not build a 2 MB table every 20 ms.
This commit is contained in:
waozi committed 2026-11-16 10:31:04 -03:00
1 parent 3982886e04
commit 631f15e715
3 files changed
+44 -7

No files matched your search

+4
View File
@@ -2,6 +2,10 @@
## Unreleased
- Raylib desktop windows on Linux show their exact colours where SDL 2 runs
on SDL 3 through sdl2-compat. SDL 3 could give the OpenGL ES context an
sRGB-capable framebuffer that encoded Kryon's sRGB colours a second time
and washed out the whole window; the host now asks SDL for a linear one.
- On the web, the mouse wheel scrolls what is under it even when the
pointer has not moved since a click elsewhere: the canvas host takes the
pointer position from the wheel event, which a page with a text editor
+19
View File
@@ -1920,6 +1920,24 @@ RaylibDiscardTypefaceTextures :: (typeface: *RaylibTypeface) {
}
}
// Kryon's colours are sRGB already, so the window must store them as they
// are. SDL 3, which an SDL 2 program also runs on through sdl2-compat, can
// give an OpenGL ES context an sRGB-capable framebuffer that encodes every
// colour a second time, washing out the whole window; ask for a linear one.
#if #defined(ANDROID_BUILD) || #defined(PLATFORM_WEB) || #defined(_WIN32) || #defined(__APPLE__) {
RaylibLinearFramebuffer :: () {}
} else {
framebuffer_sdl :: #system_library "SDL2";
HostSdlSetHint :: (name: *u8, value: *u8) -> s32 #foreign framebuffer_sdl "SDL_SetHint";
RaylibLinearFramebuffer :: () {
hint: [64]u8
value: [2]u8 = .[48, 0]
if CopyCString("SDL_OPENGL_FORCE_SRGB_FRAMEBUFFER", hint[:]) {
unused HostSdlSetHint(*hint[0], *value[0])
}
}
}
// An empty title names the window after the program; see program_title.
#program_export
OpenRaylib :: (width: s32 = 960, height: s32 = 600,
@@ -1936,6 +1954,7 @@ OpenRaylib :: (width: s32 = 960, height: s32 = 600,
InputDeliveryReset(*raylib_input)
raylib_input_focused = false
HostRaylibSetConfigFlags(flags)
RaylibLinearFramebuffer()
HostRaylibInitWindow(width, height, *label[0])
if !HostRaylibIsWindowReady() { return false }
if !WindowVisible() {
+21 -7
View File
@@ -87,13 +87,27 @@ main :: (argc: s32, argv: **u8) -> s32 {
} else if width != 320 || height != 160 {
print("zx window: the window is % by %\n", width, height)
status = 1
} else if !CaptureWindow(*display, window, *image) {
status = Fail("cannot capture the window")
} else if ImageColorCount(*image) != 1 || ImagePixel(*image, 0, 0) != cast(u32)EMPTY_COLOR {
first := ImagePixel(*image, 0, 0)
print("zx window: % colours, the first %, %, %\n", ImageColorCount(*image), PixelRed(first),
PixelGreen(first), PixelBlue(first))
status = 1
} else {
// The window maps before its first frame is presented, and X shows
// black until then, longer while other tests load the machine. Wait
// up to 10 s for the presented frame; the assertion stays exact.
painted_deadline := MonotonicMilliseconds() + 10000
while true {
if !CaptureWindow(*display, window, *image) {
status = Fail("cannot capture the window")
break
}
if ImagePixel(*image, 0, 0) == cast(u32)EMPTY_COLOR && ImageColorCount(*image) == 1 { break }
if MonotonicMilliseconds() < painted_deadline && !PollProcess(*app) {
unused SleepMilliseconds(20)
continue
}
first := ImagePixel(*image, 0, 0)
print("zx window: % colours, the first %, %, %\n", ImageColorCount(*image), PixelRed(first),
PixelGreen(first), PixelBlue(first))
status = 1
break
}
}
if !RequestWindowClose(*display, window) {
unused StopOwnedProcess(*app, 2000)