yt-project / yt_idv

Interactive volume rendering for yt
Other
9 stars 5 forks source link

Off-screen Volume Rendering on macos 14.7 #148

Open HealthyPear opened 1 month ago

HealthyPear commented 1 month ago

Description

Off-screen Volume Rendering example on macos 14.7

What I Did

just ran the example then got

Traceback (most recent call last):
  File "/Users/michele/Software/3D_rendering_radio_data/yt-idv_examples/two.py", line 8, in <module>
    rc = yt_idv.render_context("egl", width=1024, height=1024)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer/lib/python3.12/site-packages/yt_idv/rendering_contexts/__init__.py", line 44, in render_context
    from .egl_context import EGLRenderingContext
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer/lib/python3.12/site-packages/yt_idv/rendering_contexts/egl_context.py", line 4, in <module>
    from OpenGL import EGL, GL
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer/lib/python3.12/site-packages/OpenGL/EGL/__init__.py", line 2, in <module>
    from OpenGL.raw.EGL._types import *
  File "/Users/michele/Software/miniforge3/envs/radio_3d_renderer/lib/python3.12/site-packages/OpenGL/raw/EGL/_types.py", line 77, in <module>
    CALLBACK_TYPE = _p.PLATFORM.functionTypeFor( _p.PLATFORM.EGL )
                                                 ^^^^^^^^^^^^^^^
AttributeError: 'DarwinPlatform' object has no attribute 'EGL'. Did you mean: 'CGL'?

same with "cgl"

chrishavlin commented 1 month ago

Thanks for the report, @HealthyPear . It's possible that some extra setup is required off screen rendering on a mac -- I'll check it out later today on my laptop, will let you know what I find!

chrishavlin commented 1 month ago

Ok, so on the yt_idv side, I do think there's an issue with how environment variables are being set (this issue actually). Before importing yt_idv, you'll need to set PYOPENGL_PLATFORM='egl'. You can do this as an environment variable from your shell (e.g., export PYOPENGL_PLATFORM='egl') before starting your python session or from within your python session/script, just make sure it happens before all other imports:

import os
os.environ['PYOPENGL_PLATFORM'] = 'egl'

import yt_idv 
# etc.. 

If you've not separately installed any EGL-related libraries, you'll get a new error related to EGL not being found. For headless rendering, you'll need to separately install EGL or osmesa. We do need some improved documentation for this in yt_idv (at a minimum describing the requirements for headless rendering that yt_idv does not install for you). Unfortunately I don't yet have good instructions for you on a mac (working on it.... hopefully soon...). On my linux machines, I usually install the required packages as system level installs: for osmesa on ubuntu it's just sudo apt-get install libosmesa6-dev, for egl I follow these instructions. On a mac things don't seem quite as straightforward so far. There is a brew recipe for the mesa libraries that installed OK for me but i haven't yet got it working with yt_idv. I also just noticed the mesalib conda package that may also work but I haven't tested it yet. In any case, I'll update here if I actually get the headless rendering working on a mac.

chrishavlin commented 1 month ago

Well one update! With the mesalib conda package it's very easy to setup osmesa headless rendering:

conda create --name yt_idv_mac python=3.10
conda activate yt_idv_mac
conda install mesalib
pip install yt_idv yt[enzo] pooch h5py 

export PYOPENGL_PLATFORM='osmesa'
python amr_osmesa.py

no luck with egl yet.