Skip to content

Commit

Permalink
target/min opengl versions for pyglet config
Browse files Browse the repository at this point in the history
  • Loading branch information
mjd3 committed Apr 27, 2020
1 parent 31bd020 commit 1f55ea3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 24 deletions.
6 changes: 4 additions & 2 deletions pyrender/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
DEFAULT_Z_FAR = 100.0 # Far clipping plane, in meters
DEFAULT_SCENE_SCALE = 2.0 # Default scene scale
MAX_N_LIGHTS = 4 # Maximum number of lights of each type allowed
OPEN_GL_MAJOR = 4 # Target OpenGL Major Version
OPEN_GL_MINOR = 1 # Target OpenGL Minor Version
TARGET_OPEN_GL_MAJOR = 4 # Target OpenGL Major Version
TARGET_OPEN_GL_MINOR = 1 # Target OpenGL Minor Version
MIN_OPEN_GL_MAJOR = 3 # Minimum OpenGL Major Version
MIN_OPEN_GL_MINOR = 3 # Minimum OpenGL Minor Version
FLOAT_SZ = 4 # Byte size of GL float32
UINT_SZ = 4 # Byte size of GL uint32
SHADOW_TEX_SZ = 1024 # Width and Height of Shadow Textures
Expand Down
37 changes: 24 additions & 13 deletions pyrender/platforms/pyglet_platform.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pyrender.constants import OPEN_GL_MAJOR, OPEN_GL_MINOR
from pyrender.constants import (TARGET_OPEN_GL_MAJOR, TARGET_OPEN_GL_MINOR,
MIN_OPEN_GL_MAJOR, MIN_OPEN_GL_MINOR)
from .base import Platform

import OpenGL
Expand All @@ -20,19 +21,29 @@ def init_context(self):
import pyglet
pyglet.options['shadow_window'] = False

# Try multiple configs starting with target
self._window = None
conf = pyglet.gl.Config(
sample_buffers=1, samples=4,
depth_size=24,
double_buffer=True,
major_version=OPEN_GL_MAJOR,
minor_version=OPEN_GL_MINOR
)
try:
self._window = pyglet.window.Window(config=conf, visible=False,
resizable=False,
width=1, height=1)
except Exception as e:
confs = [pyglet.gl.Config(sample_buffers=1, samples=4,
depth_size=24,
double_buffer=True,
major_version=TARGET_OPEN_GL_MAJOR,
minor_version=TARGET_OPEN_GL_MINOR),
pyglet.gl.Config(sample_buffers=1, samples=4,
depth_size=24,
double_buffer=True,
major_version=MIN_OPEN_GL_MAJOR,
minor_version=MIN_OPEN_GL_MINOR),
None]
for conf in confs:
try:
self._window = pyglet.window.Window(config=conf, visible=False,
resizable=False,
width=1, height=1)
break
except pyglet.window.WindowException as e:
pass

if not self._window:
raise ValueError(
'Failed to initialize Pyglet window with an OpenGL >= 3+ '
'context. If you\'re logged in via SSH, ensure that you\'re '
Expand Down
34 changes: 25 additions & 9 deletions pyrender/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
except Exception:
pass

from .constants import (OPEN_GL_MAJOR, OPEN_GL_MINOR, TEXT_PADDING, DEFAULT_SCENE_SCALE,
from .constants import (TARGET_OPEN_GL_MAJOR, TARGET_OPEN_GL_MINOR,
MIN_OPEN_GL_MAJOR, MIN_OPEN_GL_MINOR,
TEXT_PADDING, DEFAULT_SCENE_SCALE,
DEFAULT_Z_FAR, DEFAULT_Z_NEAR, RenderFlags, TextAlign)
from .light import DirectionalLight
from .node import Node
Expand Down Expand Up @@ -987,15 +989,29 @@ def _render(self):
self._renderer.render(self.scene, flags)

def _init_and_start_app(self):
# Try multiple configs starting with target
from pyglet.gl import Config
conf = Config(sample_buffers=1, samples=4,
depth_size=24, double_buffer=True,
major_version=OPEN_GL_MAJOR,
minor_version=OPEN_GL_MINOR)
super(Viewer, self).__init__(config=conf, resizable=True,
width=self._viewport_size[0],
height=self._viewport_size[1])
if self.context.config.major_version < 3:
confs = [Config(sample_buffers=1, samples=4,
depth_size=24,
double_buffer=True,
major_version=TARGET_OPEN_GL_MAJOR,
minor_version=TARGET_OPEN_GL_MINOR),
Config(sample_buffers=1, samples=4,
depth_size=24,
double_buffer=True,
major_version=MIN_OPEN_GL_MAJOR,
minor_version=MIN_OPEN_GL_MINOR),
None]
for conf in confs:
try:
super(Viewer, self).__init__(config=conf, resizable=True,
width=self._viewport_size[0],
height=self._viewport_size[1])
break
except pyglet.window.WindowException as e:
pass

if not self.context:
raise ValueError('Unable to initialize an OpenGL 3+ context')
clock.schedule_interval(
Viewer._time_event, 1.0 / self.viewer_flags['refresh_rate'], self
Expand Down

0 comments on commit 1f55ea3

Please sign in to comment.