Ejemplo n.º 1
0
 def test_int(self):
     a1 = create_argument('p1', 2)
     args = {a1.name: a1}
     code = "p1 = 4"
     shader = create_shader(code, args)
     runtimes = [Runtime()]
     shader.prepare(runtimes)
     shader.execute()
     self.assertIsInstance(shader.get_value("p1"), int)
     self.assertEqual(shader.get_value('p1'), 4)
Ejemplo n.º 2
0
 def test_int(self):
     a1 = create_argument('p1', 2)
     args = {a1.name:a1}
     code = "p1 = 4"
     shader = create_shader(code, args)
     runtimes = [Runtime()]
     shader.prepare(runtimes)
     shader.execute()
     self.assertIsInstance(shader.get_value("p1"), int)
     self.assertEqual(shader.get_value('p1'), 4)
Ejemplo n.º 3
0
    def test_float(self):
        a1 = create_argument('p1', 2.0)
        a2 = create_argument('p2', 2.0)
        args = {a1.name: a1, a2.name: a2}
        code = """
p1 = 4.4
p2 = 8
        """
        shader = create_shader(code, args)
        runtimes = [Runtime()]
        shader.prepare(runtimes)
        shader.execute()
        self.assertIsInstance(shader.get_value("p1"), float)
        self.assertIsInstance(shader.get_value("p2"), float)
        self.assertAlmostEqual(shader.get_value("p1"), 4.4, places=5)
        self.assertAlmostEqual(shader.get_value("p2"), 8.0, places=5)
Ejemplo n.º 4
0
    def test_float(self):
        a1 = create_argument('p1', 2.0)
        a2 = create_argument('p2', 2.0)
        args = {a1.name:a1, a2.name:a2}
        code = """
p1 = 4.4
p2 = 8
        """
        shader = create_shader(code, args)
        runtimes = [Runtime()]
        shader.prepare(runtimes)
        shader.execute()
        self.assertIsInstance(shader.get_value("p1"), float)
        self.assertIsInstance(shader.get_value("p2"), float)
        self.assertAlmostEqual(shader.get_value("p1"), 4.4, places=5)
        self.assertAlmostEqual(shader.get_value("p2"), 8.0, places=5)
Ejemplo n.º 5
0
    def test_vector3(self):
        a1 = create_argument('p1', (4, 5, 6))
        a2 = create_argument('p2', [1, 1, 1])
        args = {a1.name: a1, a2.name: a2}
        code = """
p1 = [2, 4.4, 7] 
p2 = (11, 33, 1.1) 
        """
        shader = create_shader(code, args)
        runtimes = [Runtime()]
        shader.prepare(runtimes)
        shader.execute()
        v1 = shader.get_value("p1")
        v2 = shader.get_value("p2")
        self.assertIsInstance(v1, Vector3)
        self.assertIsInstance(v2, Vector3)

        self.assertAlmostEqual(v1.x, 2.0, places=5)
        self.assertAlmostEqual(v1.y, 4.4, places=5)
        self.assertAlmostEqual(v1.z, 7.0, places=5)
        self.assertAlmostEqual(v2.x, 11.0, places=5)
        self.assertAlmostEqual(v2.y, 33.0, places=5)
        self.assertAlmostEqual(v2.z, 1.1, places=5)
Ejemplo n.º 6
0
    def test_vector3(self):
        a1 = create_argument('p1', (4,5,6))
        a2 = create_argument('p2', [1,1,1])
        args = {a1.name:a1, a2.name:a2}
        code = """
p1 = [2, 4.4, 7] 
p2 = (11, 33, 1.1) 
        """
        shader = create_shader(code, args)
        runtimes = [Runtime()]
        shader.prepare(runtimes)
        shader.execute()
        v1 = shader.get_value("p1")
        v2 = shader.get_value("p2")
        self.assertIsInstance(v1, Vector3)
        self.assertIsInstance(v2, Vector3)

        self.assertAlmostEqual(v1.x, 2.0, places=5)
        self.assertAlmostEqual(v1.y, 4.4, places=5)
        self.assertAlmostEqual(v1.z, 7.0, places=5)
        self.assertAlmostEqual(v2.x, 11.0, places=5)
        self.assertAlmostEqual(v2.y, 33.0, places=5)
        self.assertAlmostEqual(v2.z, 1.1, places=5)
Ejemplo n.º 7
0
a2 = create_argument('p2', 1)
a3 = create_argument('p3', 5.0)
#a4 = create_argument('p4', Vector3(2,5,6))
a4 = create_argument('p4', [2,5,6])
a5 = create_struct_argument(typ="point", name="ps", fields=[('x', 5.5), ('y', (4,5,6))])
a6 = create_argument('p6', 99)
a7 = create_argument('p7', 8.3)
a8 = create_argument('p8', (4,5,6))
args = {a1.name:a1, a2.name: a2, a3.name: a3, a4.name: a4, a5.name: a5}
code = """
ps.x = 8.33
ps.y = (9,9,8)
p2 = p6
"""

shader = create_shader("test", code, args, input_args=[a6], func=True)

runtimes = [Runtime()]
shader.prepare(runtimes)

m1 = create_argument('m1', 2)
code2 = """
a = 44
test(a)
"""
args2 = {m1.name:m1}
shader2 = create_shader("test2", code2, args2, shaders=[shader], func=False)
shader2.prepare(runtimes)

#shader.execute()
shader2.execute()