Skip to content

Egl2#73

Merged
m-reuter merged 6 commits intomainfrom
egl2
Mar 6, 2026
Merged

Egl2#73
m-reuter merged 6 commits intomainfrom
egl2

Conversation

@m-reuter
Copy link
Member

@m-reuter m-reuter commented Mar 5, 2026

minor fixes to EGL support

m-reuter added 6 commits March 6, 2026 00:49
Previously the module silently overwrote any existing PYOPENGL_PLATFORM
value (other than 'egl') when imported, which could cause hard-to-debug
mixed-platform GL state if e.g. 'osmesa' had already been set.
Now:
- If PYOPENGL_PLATFORM is unset: set it to 'egl' (existing behaviour).
- If PYOPENGL_PLATFORM == 'egl': no-op (already correct).
- If PYOPENGL_PLATFORM is set to anything else: raise RuntimeError with
  a clear explanation, instead of silently overwriting it.
Both docstrings said window=None only when 'an OSMesa context is active',
but EGL offscreen contexts also return window=None from init_offscreen_context.
Updated both Parameters sections to say 'EGL or OSMesa offscreen context'.
Previously only mentioned OSMesa. Now describes all three paths:
1. GLFW invisible window (display available)
2. EGL GPU rendering (no display, /dev/dri/renderD* accessible) — new
3. OSMesa CPU fallback
Adds install hint for libegl1 and notes EGL as the recommended path
for SSH servers with a GPU. Docker section clarified to say OSMesa is
used there specifically (no GPU device in standard containers).
- Opening paragraph: note GPU rendering is possible with --device
- Notes section: split into 'default OSMesa' and 'optional EGL GPU'
  bullets, add --device example and libegl1 install note.
  OSMesa remains the default since no /dev/dri/ device is exposed in
  standard Docker containers.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes EGL support by correcting the timing of the PYOPENGL_PLATFORM=egl environment variable assignment. Previously, the EGL platform was set lazily inside egl_context.py (which could be imported after OpenGL.GL was already bound to a different backend). Now it is set eagerly in _headless.py at package import time — before any OpenGL.GL import can occur — eliminating silent GL function-pointer mismatches.

Changes:

  • _headless.py now immediately sets PYOPENGL_PLATFORM=egl when a headless EGL device is detected, instead of deferring to egl_context.py
  • context.py and egl_context.py update their EGL guard logic to rely on the environment variable being already set, and documentation is updated throughout to describe the new platform-selection semantics
  • Dockerfile and documentation (README.md, DOCKER.md) are updated to document EGL GPU rendering as a first-class headless option alongside OSMesa

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
whippersnappy/gl/_headless.py Sets PYOPENGL_PLATFORM=egl eagerly; updates module docstring
whippersnappy/gl/egl_context.py Adds RuntimeError guard for wrong platform at direct-import time
whippersnappy/gl/context.py Replaces egl_device_is_available() runtime check with PYOPENGL_PLATFORM=="egl" env check; updates docstrings
whippersnappy/gl/__init__.py Updates package-level docstring to reflect new EGL/OSMesa selection logic
README.md Documents three-path Linux headless fallback including EGL
Dockerfile Adds libegl1 dependency for EGL GPU rendering support
DOCKER.md Documents EGL GPU Docker usage with --device /dev/dri/renderD*

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@m-reuter m-reuter merged commit de8d092 into main Mar 6, 2026
31 checks passed
@m-reuter m-reuter deleted the egl2 branch March 6, 2026 00:13
@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 11.11111% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 34.85%. Comparing base (0e2704e) to head (9f0f9da).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
whippersnappy/gl/egl_context.py 0.00% 6 Missing ⚠️
whippersnappy/gl/_headless.py 0.00% 1 Missing ⚠️
whippersnappy/gl/context.py 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #73      +/-   ##
==========================================
- Coverage   34.91%   34.85%   -0.07%     
==========================================
  Files          24       24              
  Lines        2237     2241       +4     
  Branches      340      341       +1     
==========================================
  Hits          781      781              
- Misses       1362     1366       +4     
  Partials       94       94              
Flag Coverage Δ
unittests 34.85% <11.11%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants