Skip to content
Open
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
59 changes: 39 additions & 20 deletions glcontext/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@
__version__ = '2.3.7'


def default_backend():
"""Get default backend based on the detected platform.
Supports detecting an existing context and standalone contexts.
If no context if found for the platform we return the linux backend.

Example::

# Get the available backend
backend = get_default_backend(standalone=False/True)
# Create an opengl 3.3 context or detect the currently active
# context requiring at least opengl 3.3 support.
ctx = backend(330)
def get_default_backend_name():
"""Get the default backend name based on the detected platform.

Returns:
A backend object for creating and/or detecting context
str: The name of the default backend ('wgl', 'x11', or 'darwin')
"""
PLATFORMS = {'windows', 'linux', 'darwin'}

Expand All @@ -32,23 +22,52 @@ def default_backend():
target = 'linux'

if target == 'windows':
return _wgl()
return 'wgl'

if target == 'linux':
return _x11()
return 'x11'

if target == 'darwin':
return _darwin()
return 'darwin'

raise ValueError("Cannot find suitable default backend")


def default_backend():
"""Get default backend based on the detected platform.
Supports detecting an existing context and standalone contexts.
If no context if found for the platform we return the linux backend.

Example::

# Get the available backend
backend = get_default_backend(standalone=False/True)
# Create an opengl 3.3 context or detect the currently active
# context requiring at least opengl 3.3 support.
ctx = backend(330)

Returns:
A backend object for creating and/or detecting context
"""
return get_backend_by_name(get_default_backend_name())


def get_backend_by_name(name: str):
"""Request a specific backend by name"""
if name == 'egl':
return _egl()

raise ValueError("Cannot find supported backend: '{}'".format(name))
BACKENDS = {
'wgl': _wgl,
'x11': _x11,
'darwin': _darwin,
'egl': _egl,
}

backend = BACKENDS.get(name)
if backend:
return backend()

raise ValueError("Cannot find supported backend: '{}'. Supported backends: {}".format(
name, ', '.join(BACKENDS.keys())
))


def _wgl():
Expand Down
Loading