Skip to content

BGF: Minor GLES code fixits - #128

Merged
natetrost merged 1 commit into
android:mainfrom
natetrost:main
Nov 16, 2026
Merged

natetrost merged 1 commit into
android:mainfrom
natetrost:main

Conversation

@natetrost

Copy link
Copy Markdown
Contributor

Fix GLES config selection, sRGB surfaces, resize/orientation detection

  • Config selection:
    • GenerateEGLConfigAttribList: add the missing break after the RGBA5551 case, which fell through into RGB565 (and after RGB565).
    • eglChooseConfig treats channel sizes as minimums and sorts larger color depths first, so taking its first result meant RGB565, RGBA5551 and RGBA4 requests got an 8888 config. InitializeEGLSurface now takes all candidates, keeps only exact color matches (preferring exact depth/stencil, in eglChooseConfig order), and tries them until eglCreateWindowSurface succeeds. Zero matches is a failure.
    • RestoreSurfaceGLES recreates the window surface with the config the still-live context was created with, instead of re-choosing a config. It also checks EGL_NO_SURFACE rather than nullptr.
    • GenerateEGLConfigAttribList returns a std::vector instead of a raw new[] array.
  • sRGB:
    • EGL_KHR_gl_colorspace was detected with HasEGLExtension(), which queries the EGL_NO_DISPLAY client extension string, before eglInitialize. It is a display extension, so detection always failed and GLES never offered sRGB formats. Detect it on the initialized display via a new PlatformUtilGLES::HasEGLDisplayExtension().
    • Window surfaces now pass EGL_GL_COLORSPACE_KHR / EGL_GL_COLORSPACE_SRGB_KHR when an sRGB format is requested. They previously passed no attributes, so surfaces were always linear.
    • Extension checks (client and display) share a whole-token matcher that rejects null/empty names. HasEGLExtension previously matched substrings.
  • InitSwapchain: on failure, reset swapchain_frame_count_ (the 'initialized' flag) and the chosen config. The count stayed non-zero, so every later InitSwapchain retry was refused.
  • Resize detection: CheckScreenResolutionChange always returned true, so PresentCurrentSwapchainFrame hid the callback behind a static once-only flag. The display-changed callback then fired once, spuriously, on the first frame and never for real resizes. It now reports only real size changes, ignores failed queries and non-positive sizes, and updates the orientation. The static flag is removed.
  • GetScreenResolutions clears its output and rejects failed queries and non-positive sizes instead of reporting 0x0.
  • Orientation: integer division ((width / height) >= 4.0f / 3.0f) misclassified e.g. 1920x1080 as portrait and could divide by zero. It is now width >= height of the surface (as displayed), so a side-by-side split-screen pane reports portrait.

…ection

Fix GLES backend bugs in base_game_framework:

- Config selection:
  - GenerateEGLConfigAttribList: add the missing break after the
    RGBA5551 case, which fell through into RGB565 (and after RGB565).
  - eglChooseConfig treats channel sizes as minimums and sorts larger
    color depths first, so taking its first result meant RGB565,
    RGBA5551 and RGBA4 requests got an 8888 config. InitializeEGLSurface
    now takes all candidates, keeps only exact color matches (preferring
    exact depth/stencil, in eglChooseConfig order), and tries them until
    eglCreateWindowSurface succeeds. Zero matches is a failure.
  - RestoreSurfaceGLES recreates the window surface with the config the
    still-live context was created with, instead of re-choosing a
    config. It also checks EGL_NO_SURFACE rather than nullptr.
  - GenerateEGLConfigAttribList returns a std::vector instead of a raw
    new[] array.
- sRGB:
  - EGL_KHR_gl_colorspace was detected with HasEGLExtension(), which
    queries the EGL_NO_DISPLAY client extension string, before
    eglInitialize. It is a display extension, so detection always failed
    and GLES never offered sRGB formats. Detect it on the initialized
    display via a new PlatformUtilGLES::HasEGLDisplayExtension().
  - Window surfaces now pass EGL_GL_COLORSPACE_KHR /
    EGL_GL_COLORSPACE_SRGB_KHR when an sRGB format is requested. They
    previously passed no attributes, so surfaces were always linear.
  - Extension checks (client and display) share a whole-token matcher
    that rejects null/empty names. HasEGLExtension previously matched
    substrings.
- InitSwapchain: on failure, reset swapchain_frame_count_ (the
  'initialized' flag) and the chosen config. The count stayed non-zero,
  so every later InitSwapchain retry was refused.
- Resize detection: CheckScreenResolutionChange always returned true,
  so PresentCurrentSwapchainFrame hid the callback behind a static
  once-only flag. The display-changed callback then fired once,
  spuriously, on the first frame and never for real resizes. It now
  reports only real size changes, ignores failed queries and
  non-positive sizes, and updates the orientation. The static flag is
  removed.
- GetScreenResolutions clears its output and rejects failed queries
  and non-positive sizes instead of reporting 0x0.
- Orientation: integer division ((width / height) >= 4.0f / 3.0f)
  misclassified e.g. 1920x1080 as portrait and could divide by zero.
  It is now width >= height of the surface (as displayed), so a
  side-by-side split-screen pane reports portrait.

Tested on a Pixel 10 Pro with agdktunnel forced to GLES via temporary
test code, logging the actual config/colorspace of the current surface:
- RGBA8 sRGB request: 8888/D24S8 config, sRGB surface. Before, no sRGB
  format was offered.
- RGB565 request: 565 config (id 233). Before this change it got an
  8888 config (id 23).
- RGBA8 linear: 8888/D24S8, linear.
- For each: resizing the display (wm size 1080x2000, then reset) gives
  exactly one display-changed callback per resize, and the UI re-lays
  out. After background/resume, the restored surface uses the same
  config as the context.
- Landscape <-> reverse-landscape rotation: no spurious callbacks or
  EGL errors (tested on the first revision of this change).
The default Vulkan build starts and renders normally. RGBA5551/RGBA4
(no such configs on this device) and the InitSwapchain failure path
were not exercised.
@natetrost
natetrost merged commit 7b7ad67 into android:main Nov 16, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant