File: test_texture_array.py

package info (click to toggle)
python-moderngl 5.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,700 kB
  • sloc: python: 15,758; cpp: 14,665; makefile: 14
file content (55 lines) | stat: -rw-r--r-- 1,770 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
48
49
50
51
52
53
54
55
import moderngl


def test_create(ctx):
    size = (64, 32, 8)
    texture = ctx.texture_array(size, 4)

    # Basic attributes
    assert texture.size == size
    assert texture.width == 64
    assert texture.height == 32
    assert texture.layers == 8
    assert texture.dtype == 'f1'
    assert texture.components == 4
    assert texture.anisotropy == 0.0

    # Texture parameters
    assert texture.repeat_x is True
    assert texture.repeat_y is True
    assert texture.filter == (moderngl.LINEAR, moderngl.LINEAR)
    assert texture.swizzle == "RGBA"
    assert texture == texture

    texture.repeat_x = False
    texture.repeat_y = False
    assert texture.repeat_x is False
    assert texture.repeat_y is False

    assert texture.swizzle == "RGBA"
    texture.swizzle = "RGBA"
    assert texture.swizzle == "RGBA"

    texture.anisotropy = ctx.max_anisotropy
    assert texture.anisotropy == ctx.max_anisotropy

    assert texture.filter == (moderngl.LINEAR, moderngl.LINEAR)
    texture.filter = moderngl.NEAREST, moderngl.NEAREST
    assert texture.filter == (moderngl.NEAREST, moderngl.NEAREST)
    texture.build_mipmaps()
    assert texture.filter == (moderngl.LINEAR_MIPMAP_LINEAR, moderngl.LINEAR)

    texture.label = "best texture array"
    assert texture.label == "best texture array"


def test_texture_default_filter(ctx):
    """Ensure default filter is correct"""
    # Float types
    for dtype in ["f1", "f2", "f4"]:
        texture = ctx.texture_array((10, 10, 10), 4, dtype=dtype)
        assert texture.filter == (moderngl.LINEAR, moderngl.LINEAR)

    for dtype in ["u1", "u2", "u4", "i1", "i2", "i4"]:
        texture = ctx.texture_array((10, 10, 10), 4, dtype=dtype)
        assert texture.filter == (moderngl.NEAREST, moderngl.NEAREST)