Skip to content

replace EGL with Mesa for CPU off-screen rendering#61

Open
m-reuter wants to merge 10 commits intomainfrom
mesa
Open

replace EGL with Mesa for CPU off-screen rendering#61
m-reuter wants to merge 10 commits intomainfrom
mesa

Conversation

@m-reuter
Copy link
Member

Refactor headless rendering: EGL → OSMesa, clean up GL subpackage

  • Replace EGL with OSMesa for headless rendering on Linux. OSMesa requires no GPU, no /dev/dri/ devices, and no display server. Installed via libosmesa6 (system package, no new Python dependency).
  • Delete gl/egl_context.py, add gl/osmesa_context.py as a cross-platform drop-in with the same public API (make_current, read_pixels, destroy). Raises a clear RuntimeError with a platform-specific install hint if libOSMesa is not found.
  • Delete gl/_platform.py — the PYOPENGL_PLATFORM=egl env-var setter is no longer needed; OSMesa sets the context implicitly via OSMesaMakeCurrent.
  • Delete gl/views.py — redistributed its contents to their natural homes:
    • get_view_matrices / get_view_matrix → utils/types.py (pure numpy, no GL, lives alongside ViewType which it maps over)
    • ViewState, arcball_*, compute_view_matrix → cli/whippersnap.py (only consumer; no reason to be in a shared module)
    • Rename _egl_context → _offscreen_context in gl/utils.py — the old name was a historical artefact.
  • CI (pytest.yml): Ubuntu installs libosmesa6 for headless rendering. macOS and Windows runners use a GLFW invisible window backed by their GPU drivers — no OSMesa needed, rendering tests expected to run on all three platforms (not skip).
  • Docs: Remove all EGL mentions from README.md, DOCKER.md, and Dockerfile; replace with accurate OSMesa descriptions.

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

❌ Patch coverage is 50.96774% with 76 lines in your changes missing coverage. Please review.
✅ Project coverage is 37.93%. Comparing base (34d1514) to head (3111537).

Files with missing lines Patch % Lines
whippersnappy/cli/whippersnap.py 0.00% 39 Missing ⚠️
whippersnappy/gl/utils.py 43.58% 16 Missing and 6 partials ⚠️
whippersnappy/gl/osmesa_context.py 80.28% 9 Missing and 5 partials ⚠️
whippersnappy/utils/types.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #61      +/-   ##
==========================================
- Coverage   40.02%   37.93%   -2.09%     
==========================================
  Files          23       21       -2     
  Lines        2131     2019     -112     
  Branches      327      311      -16     
==========================================
- Hits          853      766      -87     
+ Misses       1177     1163      -14     
+ Partials      101       90      -11     
Flag Coverage Δ
unittests 37.93% <50.96%> (-2.09%) ⬇️

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.

@m-reuter m-reuter requested a review from Copilot February 27, 2026 23:30
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

Refactors WhipperSnapPy’s headless OpenGL rendering path to use Mesa OSMesa (CPU software rendering) instead of EGL, and reorganizes view-matrix utilities out of the gl subpackage while updating CI/Docker/docs accordingly.

Changes:

  • Replace EGL headless context with a new OSMesa-based offscreen context and update GL context creation/teardown paths.
  • Move canonical view-matrix helpers into utils.types and relocate GUI-only view state/arcball utilities into the CLI module.
  • Update CI workflows, Docker image dependencies, and documentation to reflect OSMesa-based headless rendering.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
whippersnappy/utils/types.py Adds canonical per-view 4×4 numpy view matrices + accessors alongside ViewType.
whippersnappy/snap.py Updates imports to use get_view_matrices from utils.types.
whippersnappy/gl/views.py Removes view matrices + interactive view state helpers from gl package.
whippersnappy/gl/utils.py Switches fallback headless rendering path from EGL to OSMesa; adds platform selection env var logic; updates context handling.
whippersnappy/gl/osmesa_context.py Introduces new OSMesa offscreen context implementation via ctypes.
whippersnappy/gl/egl_context.py Removes EGL headless context implementation.
whippersnappy/gl/_platform.py Removes EGL-specific PyOpenGL platform bootstrapper.
whippersnappy/gl/__init__.py Updates package exports/docs now that views/EGL are removed and view matrices live in utils.
whippersnappy/cli/whippersnap.py Moves GUI-only ViewState + arcball helpers into CLI (only consumer) and updates view-matrix usage.
whippersnappy/__init__.py Removes previous EGL platform selection / display probing logic.
tests/test_array_and_rendering.py Adjusts rendering test behavior and introduces macOS CI skip for rendering tests.
doc/conf.py Tweaks numpydoc configuration for dataclass attribute documentation and ignore patterns.
README.md Updates user-facing docs from EGL to OSMesa headless rendering description.
Dockerfile Swaps EGL system dependency for libosmesa6 to support headless CPU rendering.
DOCKER.md Updates Docker guide to describe OSMesa-based headless rendering.
.github/workflows/pytest.yml Installs libosmesa6 on Ubuntu; adds Windows Mesa software OpenGL setup; documents platform strategy.
.github/workflows/publish.yml Updates Ubuntu system deps from EGL to OSMesa.
.github/workflows/doc.yml Updates Ubuntu system deps from EGL to OSMesa.
.github/workflows/build.yml Updates Ubuntu system deps from EGL to OSMesa.

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

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