File: array.py

package info (click to toggle)
python-moderngl-window 2.4.6-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 69,220 kB
  • sloc: python: 11,387; makefile: 21
file content (47 lines) | stat: -rw-r--r-- 1,443 bytes parent folder | download | duplicates (2)
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
from moderngl_window.loaders.texture.pillow import PillowLoader, image_data
from moderngl_window.exceptions import ImproperlyConfigured


class Loader(PillowLoader):
    kind = "array"

    def __init__(self, meta):
        super().__init__(meta)
        self.layers = self.meta.layers

        if self.layers is None:
            raise ImproperlyConfigured("TextureArray requires layers parameter")

    def load(self):
        """Load a texture array as described by the supplied ``TextureDescription```

        Returns:
            moderngl.TextureArray: The TextureArray instance
        """
        self._open_image()

        width, height, depth = (
            self.image.size[0],
            self.image.size[1] // self.layers,
            self.layers,
        )
        components, data = image_data(self.image)

        texture = self.ctx.texture_array((width, height, depth), components, data,)
        texture.extra = {"meta": self.meta}

        if self.meta.mipmap_levels is not None:
            self.meta.mipmap = True

        if self.meta.mipmap:
            if isinstance(self.meta.mipmap_levels, tuple):
                texture.build_mipmaps(*self.meta.mipmap_levels)
            else:
                texture.build_mipmaps()

            if self.meta.anisotropy:
                texture.anisotropy = self.meta.anisotropy

        self._close_image()

        return texture