Skip to content

Commit d96ab49

Browse files
committed
Add robust fallback for OpenGL on Windows based on OSMesa.
1 parent c670822 commit d96ab49

File tree

7 files changed

+56
-10
lines changed

7 files changed

+56
-10
lines changed

genesis/ext/pyrender/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from . import _pyopengl
12
from .camera import Camera, PerspectiveCamera, OrthographicCamera, IntrinsicsCamera
23
from .light import Light, PointLight, DirectionalLight, SpotLight
34
from .sampler import Sampler

genesis/ext/pyrender/_pyopengl.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import ctypes
2+
import sys
3+
import types
4+
5+
import OpenGL.platform as _platform
6+
from OpenGL.platform.baseplatform import BasePlatform as _BasePlatform
7+
from OpenGL.platform.osmesa import OSMesaPlatform as _OSMesaPlatform
8+
9+
10+
# Fix broken loading of OpenGL extension functions when using OSMesa on Windows OS
11+
if sys.platform == "win32" and isinstance(_platform.PLATFORM, _OSMesaPlatform):
12+
if _platform.PLATFORM.constructFunction.__func__ == _BasePlatform.constructFunction:
13+
def constructFunction(
14+
self,
15+
functionName,
16+
dll,
17+
resultType = ctypes.c_int,
18+
argTypes = (),
19+
doc = None,
20+
argNames = (),
21+
extension = None,
22+
deprecated = False,
23+
module = None,
24+
force_extension = False,
25+
error_checker = None,
26+
):
27+
"""Override construct function to do win32-specific hacks to find entry points"""
28+
for force_extension_ in (force_extension, True):
29+
try:
30+
return _BasePlatform.constructFunction(
31+
self,
32+
functionName,
33+
dll,
34+
resultType,
35+
argTypes,
36+
doc,
37+
argNames,
38+
extension,
39+
deprecated,
40+
module,
41+
force_extension=force_extension_,
42+
error_checker=error_checker,
43+
)
44+
break
45+
except AttributeError:
46+
if force_extension:
47+
raise
48+
49+
_platform.PLATFORM.constructFunction = types.MethodType(constructFunction, _platform.PLATFORM)

genesis/ext/pyrender/font.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
33
Author: Matthew Matl
44
"""
5+
import os
56

67
import freetype
78
import numpy as np
8-
import os
99

1010
import OpenGL
1111
from OpenGL.GL import *
@@ -122,7 +122,6 @@ def font_pt(self, value):
122122
self._font_pt = int(value)
123123

124124
def _add_to_context(self):
125-
126125
self._vao = glGenVertexArrays(1)
127126
glBindVertexArray(self._vao)
128127
self._vbo = glGenBuffers(1)

genesis/ext/pyrender/numba_gl_wrapper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from contextlib import ExitStack
2+
13
import numpy as np
24
from numba import *
35
from numba import types
@@ -11,7 +13,7 @@
1113
NativeValue,
1214
)
1315
from numba.core import cgutils
14-
from contextlib import ExitStack
16+
1517
import OpenGL.GL as GL
1618
from OpenGL._bytes import as_8_bit
1719
from OpenGL.GL import GLint, GLuint, GLvoidp, GLvoid, GLfloat, GLsizei, GLboolean, GLenum, GLsizeiptr, GLintptr

genesis/ext/pyrender/primitive.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
44
Author: Matthew Matl
55
"""
6-
76
import numpy as np
87
from OpenGL.GL import *
98

@@ -330,8 +329,8 @@ def calc_vertex_normal(self):
330329

331330
def _add_to_context(self):
332331
if self._vaid is not None:
333-
return
334332
# raise ValueError('Mesh is already bound to a context')
333+
return
335334

336335
# Generate and bind VAO
337336
self._vaid = glGenVertexArrays(1)

genesis/ext/pyrender/renderer.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
33
Author: Matthew Matl
44
"""
5-
65
import sys
7-
from time import time
86

97
import PIL
108
import pyglet
@@ -25,7 +23,6 @@
2523
TextAlign,
2624
)
2725
from .font import FontCache
28-
from .jit_render import JITRenderer
2926
from .light import DirectionalLight, PointLight, SpotLight
3027
from .material import MetallicRoughnessMaterial, SpecularGlossinessMaterial
3128
from .shader_program import ShaderProgramCache

genesis/ext/pyrender/shader_program.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from OpenGL.GL import *
1010
from OpenGL.platform import ctypesloader
1111
from OpenGL.GL import shaders as gl_shader_utils
12-
from time import time
12+
1313

1414
func = None
1515

@@ -91,7 +91,6 @@ class ShaderProgram(object):
9191
"""
9292

9393
def __init__(self, vertex_shader, fragment_shader, geometry_shader=None, defines=None):
94-
9594
self.vertex_shader = vertex_shader
9695
self.fragment_shader = fragment_shader
9796
self.geometry_shader = geometry_shader

0 commit comments

Comments
 (0)