File: test_geometry.py

package info (click to toggle)
python-moderngl-window 3.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 69,096 kB
  • sloc: python: 12,076; makefile: 21
file content (65 lines) | stat: -rw-r--r-- 3,583 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
56
57
58
59
60
61
62
63
64
65
from headless import HeadlessTestCase

from moderngl_window import geometry
from moderngl_window.geometry import AttributeNames
from moderngl_window.opengl.vao import BufferInfo


class GeomtryTestCase(HeadlessTestCase):
    custom_attrs = AttributeNames(
        position="test_pos",
        normal="test_normal",
        texcoord_0="test_uv0",
    )

    def test_bbox(self):
        """Create a bounding box"""
        mesh = geometry.bbox(size=(1.0, 1.0, 1.0), name="test_bbox")
        self.assertEqual(mesh.name, "test_bbox")
        self.assertIsInstance(mesh.get_buffer_by_name(AttributeNames.POSITION), BufferInfo)

        # Use custom buffer/attribute names
        mesh = geometry.bbox(size=(1.0, 1.0, 1.0), name="test_bbox", attr_names=self.custom_attrs)
        self.assertIsInstance(mesh.get_buffer_by_name(self.custom_attrs.POSITION), BufferInfo)

    def test_cube(self):
        """Create a cube"""
        mesh = geometry.cube(size=(1.0, 1.0, 1.0), name="test_cube")
        self.assertEqual(mesh.name, "test_cube")
        self.assertIsInstance(mesh.get_buffer_by_name(AttributeNames.POSITION), BufferInfo)
        self.assertIsInstance(mesh.get_buffer_by_name(AttributeNames.NORMAL), BufferInfo)
        self.assertIsInstance(mesh.get_buffer_by_name(AttributeNames.TEXCOORD_0), BufferInfo)

        # Use custom buffer/attribute names
        mesh = geometry.cube(size=(1.0, 1.0, 1.0), name="test_cube", attr_names=self.custom_attrs)
        self.assertIsInstance(mesh.get_buffer_by_name(self.custom_attrs.POSITION), BufferInfo)
        self.assertIsInstance(mesh.get_buffer_by_name(self.custom_attrs.NORMAL), BufferInfo)
        self.assertIsInstance(mesh.get_buffer_by_name(self.custom_attrs.TEXCOORD_0), BufferInfo)

    def test_quad_fs(self):
        """Create a fullscreen quad"""
        mesh = geometry.quad_fs(name="test_quad_fs")
        self.assertEqual(mesh.name, "test_quad_fs")
        self.assertIsInstance(mesh.get_buffer_by_name(AttributeNames.POSITION), BufferInfo)
        self.assertIsInstance(mesh.get_buffer_by_name(AttributeNames.NORMAL), BufferInfo)
        self.assertIsInstance(mesh.get_buffer_by_name(AttributeNames.TEXCOORD_0), BufferInfo)

        # Use custom buffer/attribute names
        mesh = geometry.quad_fs(name="test_quad_fs", attr_names=self.custom_attrs)
        self.assertIsInstance(mesh.get_buffer_by_name(self.custom_attrs.POSITION), BufferInfo)
        self.assertIsInstance(mesh.get_buffer_by_name(self.custom_attrs.NORMAL), BufferInfo)
        self.assertIsInstance(mesh.get_buffer_by_name(self.custom_attrs.TEXCOORD_0), BufferInfo)

    def test_sphere(self):
        """Create a spwhere"""
        mesh = geometry.sphere(radius=2.0, sectors=32, rings=16, name="test_sphere")
        self.assertEqual(mesh.name, "test_sphere")
        self.assertIsInstance(mesh.get_buffer_by_name(AttributeNames.POSITION), BufferInfo)
        self.assertIsInstance(mesh.get_buffer_by_name(AttributeNames.NORMAL), BufferInfo)
        self.assertIsInstance(mesh.get_buffer_by_name(AttributeNames.TEXCOORD_0), BufferInfo)

        # Use custom buffer/attribute names
        mesh = geometry.sphere(radius=2.0, sectors=32, rings=16, name="test_sphere", attr_names=self.custom_attrs)
        self.assertIsInstance(mesh.get_buffer_by_name(self.custom_attrs.POSITION), BufferInfo)
        self.assertIsInstance(mesh.get_buffer_by_name(self.custom_attrs.NORMAL), BufferInfo)
        self.assertIsInstance(mesh.get_buffer_by_name(self.custom_attrs.TEXCOORD_0), BufferInfo)