sync pyglet
This commit is contained in:
parent
81015756f0
commit
3dab607d19
@ -31,8 +31,10 @@ _enable_optimisations = not __debug__
|
||||
if getattr(sys, 'frozen', None):
|
||||
_enable_optimisations = True
|
||||
|
||||
#: Global dict of pyglet options. To change an option from its default, you
|
||||
#: must import ``pyglet`` before any sub-packages. For example::
|
||||
#: Global dict of pyglet options.
|
||||
#:
|
||||
#: To change an option from its default, you must import
|
||||
#: ``pyglet`` before any sub-packages. For example::
|
||||
#:
|
||||
#: import pyglet
|
||||
#: pyglet.options['debug_gl'] = False
|
||||
@ -48,14 +50,20 @@ if getattr(sys, 'frozen', None):
|
||||
#: The non-development options are:
|
||||
#:
|
||||
#: audio
|
||||
#: A sequence of the names of audio modules to attempt to load, in
|
||||
#: order of preference. Valid driver names are:
|
||||
#: A :py:class:`~typing.Sequence` of valid audio modules names. They will
|
||||
#: be tried from first to last until either a driver loads or no entries
|
||||
#: remain. See :ref:`guide-audio-driver-order` for more information.
|
||||
#:
|
||||
#: Valid driver names are:
|
||||
#:
|
||||
#: * ``'xaudio2'``, the Windows Xaudio2 audio module (Windows only)
|
||||
#: * ``'directsound'``, the Windows DirectSound audio module (Windows only)
|
||||
#: * ``'pulse'``, the :ref:`guide-pulseaudio` module (Linux only, otherwise
|
||||
#: nearly ubiquitous. Limited features; use ``'openal'`` for more.)
|
||||
#: * ``'openal'``, the :ref:`guide-openal` audio module (A library may need to be
|
||||
#: installed on Windows and Linux)
|
||||
#: * ``'silent'``, no audio
|
||||
#:
|
||||
#: * xaudio2, the Windows Xaudio2 audio module (Windows only)
|
||||
#: * directsound, the Windows DirectSound audio module (Windows only)
|
||||
#: * pulse, the PulseAudio module (Linux only)
|
||||
#: * openal, the OpenAL audio module
|
||||
#: * silent, no audio
|
||||
#: debug_lib
|
||||
#: If True, prints the path of each dynamic library loaded.
|
||||
#: debug_gl
|
||||
|
@ -1,6 +1,7 @@
|
||||
import weakref
|
||||
|
||||
from enum import Enum
|
||||
from typing import Tuple
|
||||
from functools import lru_cache
|
||||
|
||||
import pyglet
|
||||
|
||||
@ -241,9 +242,17 @@ class Context:
|
||||
else:
|
||||
self.object_space = ObjectSpace()
|
||||
|
||||
self._cached_programs = weakref.WeakValueDictionary()
|
||||
|
||||
def __repr__(self):
|
||||
return f"{self.__class__.__name__}(id={id(self)}, share={self.context_share})"
|
||||
|
||||
def __enter__(self):
|
||||
self.set_current()
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
return
|
||||
|
||||
def attach(self, canvas):
|
||||
if self.canvas is not None:
|
||||
self.detach()
|
||||
@ -309,7 +318,6 @@ class Context:
|
||||
if gl._shadow_window is not None:
|
||||
gl._shadow_window.switch_to()
|
||||
|
||||
@lru_cache()
|
||||
def create_program(self, *sources: Tuple[str, str], program_class=None):
|
||||
"""Create a ShaderProgram from OpenGL GLSL source.
|
||||
|
||||
@ -328,9 +336,15 @@ class Context:
|
||||
|
||||
.. versionadded:: 2.0.10
|
||||
"""
|
||||
if program := self._cached_programs.get(str(sources)):
|
||||
return program
|
||||
|
||||
program_class = program_class or pyglet.graphics.shader.ShaderProgram
|
||||
shaders = (pyglet.graphics.shader.Shader(src, srctype) for (src, srctype) in sources)
|
||||
return program_class(*shaders)
|
||||
program = program_class(*shaders)
|
||||
self._cached_programs[str(sources)] = program
|
||||
|
||||
return program
|
||||
|
||||
def delete_texture(self, texture_id):
|
||||
"""Safely delete a Texture belonging to this context.
|
||||
|
@ -63,10 +63,12 @@ class GLInfo:
|
||||
|
||||
This method is called automatically for the default context.
|
||||
"""
|
||||
from pyglet.gl.gl import glGetString, glGetStringi, GL_NUM_EXTENSIONS
|
||||
|
||||
self._have_context = True
|
||||
|
||||
if not self._have_info:
|
||||
|
||||
from pyglet.gl.gl import glGetString, glGetStringi, GL_NUM_EXTENSIONS
|
||||
|
||||
self.vendor = asstr(cast(glGetString(GL_VENDOR), c_char_p).value)
|
||||
self.renderer = asstr(cast(glGetString(GL_RENDERER), c_char_p).value)
|
||||
self.version = asstr(cast(glGetString(GL_VERSION), c_char_p).value)
|
||||
|
Loading…
Reference in New Issue
Block a user