File: test_framebuffer_masks.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 (49 lines) | stat: -rw-r--r-- 1,462 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

def test_1(ctx):
    fbo = ctx.framebuffer(ctx.renderbuffer((4, 4)))

    fbo.clear(0.0, 0.0, 0.0, 0.0)

    assert fbo.read(components=4) == b'\x00\x00\x00\x00' * 16

    fbo.color_mask = (True, False, True, False)
    fbo.clear(0x19 / 255, 0x33 / 255, 0x4c / 255, 0x66 / 255)

    assert fbo.read(components=4) == b'\x19\x00\x4c\x00' * 16

    fbo.color_mask = (False, True, False, True)
    fbo.clear(0x7f / 255, 0x99 / 255, 0xb2 / 255, 0xcc / 255)

    assert fbo.read(components=4) == b'\x19\x99\x4c\xcc' * 16


def test_2(ctx):
    fbo = ctx.framebuffer([
        ctx.renderbuffer((4, 4)),
        ctx.renderbuffer((4, 4)),
    ])

    fbo.clear(1.0, 1.0, 1.0, 1.0)

    assert fbo.read(components=4, attachment=0) == b'\xff\xff\xff\xff' * 16
    assert fbo.read(components=4, attachment=1) == b'\xff\xff\xff\xff' * 16

    fbo.color_mask = (
        (True, False, True, False),
        (False, True, False, True),
    )

    fbo.clear(0x19 / 255, 0x33 / 255, 0x4c / 255, 0x66 / 255)

    assert fbo.read(components=4, attachment=0) == b'\x19\xff\x4c\xff' * 16
    assert fbo.read(components=4, attachment=1) == b'\xff\x33\xff\x66' * 16

    fbo.color_mask = (
        (False, True, False, True),
        (True, False, True, False),
    )

    fbo.clear(0x7f / 255, 0x99 / 255, 0xb2 / 255, 0xcc / 255)

    assert fbo.read(components=4, attachment=0) == b'\x19\x99\x4c\xcc' * 16
    assert fbo.read(components=4, attachment=1) == b'\x7f\x33\xb2\x66' * 16