Skip to content

Commit 5ef19a5

Browse files
committed
Restore LV_OSMESA standalone build, add LV_OSMESA_EXT
Since standalone OSMesa builds are still being used, we now enable all the new functionality for supporting osmesa as a fallback for other window types with LV_OSMESA_EXT=1 instead. This should provide full backwards compatibility.
1 parent 493afe0 commit 5ef19a5

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed

.github/workflows/osmesa_deploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
LV_INC_DIRS=${HOME}/include
2323
LV_MIN_DEPS=1
2424
LV_PACKAGE=lavavu-osmesa
25-
LV_OSMESA=1
25+
LV_OSMESA_EXT=1
2626
LV_ECHO_FAIL=1
2727
LV_ARGS="-v"
2828
CIBW_BEFORE_BUILD_LINUX: >

.github/workflows/testing.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
run: python -m pip install -r requirements.txt
3535
- name: Build/install
3636
env:
37-
LV_OSMESA: 1
37+
LV_OSMESA_EXT: 1
3838
run: python -m pip install .
3939
- name: Run headless test
4040
env:

lavavu/LavaVuPython.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66

77
from sys import version_info as _swig_python_version_info
88

9-
import os
10-
if 'osmesa' in os.environ.get('LV_CONTEXT', ''):
11-
from osmesa import _LavaVuPython
12-
else:
9+
try:
10+
import os
11+
if 'osmesa' in os.environ.get('LV_CONTEXT', ''):
12+
from osmesa import _LavaVuPython
13+
else:
14+
import _LavaVuPython
15+
except ImportError as e:
1316
import _LavaVuPython
1417

1518

lavavu/lavavu.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@
8888
except (ImportError) as e:
8989
av = None
9090

91-
#import swig module
92-
context = os.environ.get("LV_CONTEXT", "").strip()
91+
#Prepare to import swig module
9392
if platform.system() == 'Linux':
9493
#Default context requires DISPLAY set for X11
9594
display = os.environ.get("DISPLAY", "").strip()
95+
context = os.environ.get("LV_CONTEXT", "").strip()
9696
if len(context) == 0: context = 'default'
9797
if context != 'default' or len(display) == 0:
9898
if context != 'osmesa':
@@ -102,13 +102,10 @@
102102
context = 'moderngl'
103103
except Exception as e:
104104
context = 'osmesa'
105-
os.environ['LV_CONTEXT'] = context
105+
os.environ['LV_CONTEXT'] = context
106106

107-
#Default module if none already loaded
108-
try:
109-
LavaVuPython
110-
except:
111-
import LavaVuPython
107+
#Import swig module
108+
import LavaVuPython
112109

113110
version = LavaVuPython.version
114111
server_ports = []
@@ -3102,7 +3099,8 @@ def gl(self):
31023099
"""
31033100
Return GL version string
31043101
"""
3105-
return self.app.gl_version()
3102+
ctx = os.environ.get("LV_CONTEXT", "")
3103+
return f"[{ctx}] : {self.app.gl_version()}"
31063104

31073105
@property
31083106
def port(self):

setup.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,8 @@ def check_libraries(libraries, headers, extra_lib_dirs=[], extra_inc_dirs=[]):
376376

377377
if P == 'Linux':
378378
#Linux GLFW, X11, EGL or OSMesa
379-
#EGL and OSMesa are built as optional extra modules
380-
'''
381-
if find_library('OpenGL') and find_library('EGL') and check_libraries(['OpenGL', 'EGL'], ['GL/gl.h', 'EGL/egl.h']):
382-
''';
383-
384-
#OSMesa built as optional extra module
385-
if ("LV_OSMESA" in os.environ and find_library('OSMesa')
379+
#OSMesa can be built as optional extra module
380+
if ("LV_OSMESA_EXT" in os.environ and find_library('OSMesa')
386381
and check_libraries(['OSMesa'], ['GL/osmesa.h'])):
387382
#OSMesa for software rendered offscreen OpenGL, build as additional extension
388383
ex = Extension('lavavu.osmesa._LavaVuPython',
@@ -397,8 +392,13 @@ def check_libraries(libraries, headers, extra_lib_dirs=[], extra_inc_dirs=[]):
397392
sources = srcs)
398393
extensions.append(ex)
399394

400-
#Main extension - use X11 or GLFW
401-
if ("LV_EGL" in os.environ and find_library('OpenGL') and find_library('EGL')
395+
#Main extension - use X11 or GLFW (or OSMesa)
396+
if ("LV_OSMESA" in os.environ and find_library('OSMesa')
397+
and check_libraries(['OSMesa'], ['GL/osmesa.h'])):
398+
#OSMesa for software rendered offscreen OpenGL
399+
defines += [('HAVE_OSMESA', '1')]
400+
libs += ['OSMesa']
401+
elif ("LV_EGL" in os.environ and find_library('OpenGL') and find_library('EGL')
402402
and check_libraries(['OpenGL', 'EGL'], ['GL/gl.h', 'EGL/egl.h'])):
403403
#EGL for offscreen OpenGL without X11/GLX - works with NVidia and latest Mesa
404404
defines += [('HAVE_EGL', '1')]

src/LavaVuPython.i

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
**~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*/
44
%define MODULEIMPORT
55
"
6-
import os
7-
if 'osmesa' in os.environ.get('LV_CONTEXT', ''):
8-
from osmesa import $module
9-
else:
6+
try:
7+
import os
8+
if 'osmesa' in os.environ.get('LV_CONTEXT', ''):
9+
from osmesa import $module
10+
else:
11+
import $module
12+
except ImportError as e:
1013
import $module
1114
"
1215
%enddef

0 commit comments

Comments
 (0)