File: test_unnamed_01.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 (50 lines) | stat: -rw-r--r-- 1,186 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
import struct
import pytest
import moderngl


def test_1(ctx):
    prog = ctx.program(
        vertex_shader='''
            #version 330

            in mat2 in_m;
            in vec2 in_v;

            out vec2 out_v;

            uniform float mult;

            void main() {
                out_v = in_m * in_v * mult;
            }
        ''',
        varyings=['out_v']
    )

    buf_m = ctx.buffer(struct.pack('4f', 1, 1, 1, 2))
    buf_v = ctx.buffer(struct.pack('2f', 4, 7))
    res = ctx.buffer(reserve=buf_v.size)

    vao = ctx.vertex_array(prog, [
        (buf_m, '4f', 'in_m'),
        (buf_v, '2f', 'in_v'),
    ])

    prog['mult'].value = 0.0
    vao.transform(res, moderngl.POINTS)
    x, y = struct.unpack('2f', res.read())
    assert pytest.approx(x) == 0.0
    assert pytest.approx(y) == 0.0

    prog['mult'].value = 1.0
    vao.transform(res, moderngl.POINTS)
    x, y = struct.unpack('2f', res.read())
    assert pytest.approx(x) == 11.0
    assert pytest.approx(y) == 18.0

    prog['mult'].value = 2.0
    vao.transform(res, moderngl.POINTS)
    x, y = struct.unpack('2f', res.read())
    assert pytest.approx(x) == 22.0
    assert pytest.approx(y) == 36.0