Source code for picogl.backend.gl.state.shader

"""Scoped shader program binding."""

from __future__ import annotations

from contextlib import contextmanager
from typing import Iterator, Protocol


[docs] class _BindableShader(Protocol):
[docs] def bind(self) -> object: ...
[docs] def unbind(self) -> object: ...
@contextmanager
[docs] def gl_shader_bound(shader: _BindableShader) -> Iterator[None]: """Bind *shader* for the duration of the ``with`` block, then unbind.""" shader.bind() try: yield finally: shader.unbind()