File: textures.py

package info (click to toggle)
python-moderngl-window 3.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 69,096 kB
  • sloc: python: 12,076; makefile: 21
file content (47 lines) | stat: -rw-r--r-- 1,252 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Shader Registry
"""

from typing import Union

import moderngl

from moderngl_window.meta import ResourceDescription, TextureDescription
from moderngl_window.resources.base import BaseRegistry

TextureAny = Union[
    moderngl.Texture,
    moderngl.TextureArray,
    moderngl.TextureCube,
    moderngl.Texture3D,
]


class Textures(BaseRegistry):
    """Handles texture resources"""

    settings_attr = "TEXTURE_LOADERS"
    meta: TextureDescription

    def load(self, meta: ResourceDescription) -> TextureAny:
        """Loads a texture with the configured loaders.

        Args:
            meta (:py:class:`~moderngl_window.meta.texture.TextureDescription`):
            The resource description
        Returns:
            moderngl.Texture: 2d texture
        Returns:
            moderngl.TextureArray: texture array if ``layers`` is supplied
        """
        texture = super().load(meta)
        assert (
            isinstance(texture, moderngl.Texture)
            or isinstance(texture, moderngl.TextureArray)
            or isinstance(texture, moderngl.TextureCube)
            or isinstance(texture, moderngl.Texture3D)
        ), f"{meta} did not load a texture. Please correct it"
        return texture


textures = Textures()