File: test_framebuffer_half_float.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 (37 lines) | stat: -rw-r--r-- 905 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
import numpy as np
import numpy.testing as npt
import moderngl


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

            in vec2 in_vert;

            void main() {
                gl_Position = vec4(in_vert, 0.0, 1.0);
            }
        ''',
        fragment_shader='''
            #version 330

            out vec4 f_color;

            void main() {
                f_color = vec4(0.0, 0.5, 1.0, 1.0);
            }
        ''',
    )

    vbo = ctx.buffer(np.array([-1, -1, -1, 1, 1, -1, 1, 1], dtype='f4'))
    vao = ctx.simple_vertex_array(prog, vbo, 'in_vert')
    fbo = ctx.simple_framebuffer((4, 4), dtype='f2')

    fbo.use()
    fbo.clear()
    vao.render(moderngl.TRIANGLE_STRIP)
    res = np.frombuffer(fbo.read(dtype='f2'), dtype='f2')
    expected = np.tile([0.0, 0.5, 1.0], 4 * 4)
    npt.assert_almost_equal(res, expected, decimal=2)