Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenGL version and multisampling fallbacks for pyglet #110

Merged
merged 2 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions pyrender/constants.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
DEFAULT_Z_NEAR = 0.05 # Near clipping plane, in meters
DEFAULT_Z_FAR = 100.0 # Far clipping plane, in meters
DEFAULT_SCENE_SCALE = 2.0 # Default scene scale
MAX_N_LIGHTS = 8 # Maximum number of lights of each type allowed
OPEN_GL_MAJOR = 4 # Target OpenGL Major Version
OPEN_GL_MINOR = 1 # Target OpenGL Minor Version
MAX_N_LIGHTS = 4 # Maximum number of lights of each type allowed
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 = 2048 # Width and Height of Shadow Textures
Expand Down
43 changes: 30 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 Down Expand Up @@ -26,18 +27,34 @@ def init_context(self):
pass

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(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),
pyglet.gl.Config(depth_size=24,
double_buffer=True,
major_version=MIN_OPEN_GL_MAJOR,
minor_version=MIN_OPEN_GL_MINOR)]
for conf in confs:
try:
self._window = pyglet.window.Window(config=conf, visible=False,
resizable=False,
width=1, height=1)
break
except pyglet.window.NoSuchConfigException 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
43 changes: 34 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,38 @@ def _render(self):
self._renderer.render(self.scene, flags)

def _init_and_start_app(self):
# Try multiple configs starting with target OpenGL version
# and multisampling and removing these options if exception
# Note: multisampling not available on all hardware
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(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),
Config(depth_size=24,
double_buffer=True,
major_version=MIN_OPEN_GL_MAJOR,
minor_version=MIN_OPEN_GL_MINOR)]
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.NoSuchConfigException:
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