Пример #1
0
 def test_detach(self):
     vert = VertexShader("A")
     frag = FragmentShader("B")
     program = Program(vert, frag)
     program.detach(frag)
     assert len(program.shaders) == 1
     assert program.shaders[0].code == "A"
Пример #2
0
    def test_setitem(self):
        vert = VertexShader("")
        frag = FragmentShader("")

        program = Program(vert, frag)
        with self.assertRaises(NameError):
            program["A"] = 1
Пример #3
0
    def test_set_attribute_vec4(self):
        vert = VertexShader("attribute vec4 color;")
        frag = FragmentShader("")

        program = Program(vert, frag)
        with self.assertRaises(ValueError):
            program["color"] = np.array(3, dtype=np.float32)

        program = Program(vert, frag)
        with self.assertRaises(ValueError):
            program["color"] = np.array((100, 5), dtype=np.float32)

        program = Program(vert, frag)
        program["color"] = ClientVertexBuffer(
            np.zeros((100, 4), dtype=np.float32))
        assert program._attributes["color"].count == 100

        program = Program(vert, frag)
        program["color"] = ClientVertexBuffer(
            np.zeros((100, 1, 4), dtype=np.float32))
        assert program._attributes["color"].count == 100

        program = Program(vert, frag)
        program["color"] = ClientVertexBuffer(
            np.zeros(100, dtype=(np.float32, 4)))
        assert program._attributes["color"].count == 100
Пример #4
0
 def test_init(self):
     shader = VertexShader()
     assert shader._handle == 0
     assert shader._need_update == False
     assert shader._valid == False
     assert shader.code == None
     assert shader.source == None
Пример #5
0
 def test_uniform(self):
     vert = VertexShader("uniform float A;")
     frag = FragmentShader("uniform float A; uniform vec4 B;")
     program = Program(vert, frag)
     assert program.uniforms[0].name == 'A'
     assert program.uniforms[0].gtype == gl.GL_FLOAT
     assert program.uniforms[1].name == 'B'
     assert program.uniforms[1].gtype == gl.GL_FLOAT_VEC4
Пример #6
0
 def test_attach(self):
     vert = VertexShader("A")
     frag = FragmentShader("B")
     program = Program(vert)
     program.attach(frag)
     assert len(program.shaders) == 2
     assert program.shaders[0].code == "A"
     assert program.shaders[1].code == "B"
Пример #7
0
    def test_failed_build(self):
        vert = VertexShader("A")
        frag = FragmentShader("B")

        program = Program(vert=vert)
        with self.assertRaises(RuntimeError):
            program.activate()

        program = Program(frag=frag)
        with self.assertRaises(RuntimeError):
            program.activate()
Пример #8
0
    def test_set_attribute_float(self):

        vert = VertexShader("attribute float f;")
        frag = FragmentShader("")

        program = Program(vert, frag)
        program["f"] = VertexBuffer(np.zeros(100, dtype=np.float32))
        assert program._attributes["f"].count == 100

        program = Program(vert, frag)
        program["f"] = ClientVertexBuffer(
            np.zeros((100, 1, 1), dtype=np.float32))
        assert program._attributes["f"].count == 100

        program = Program(vert, frag)
        with self.assertRaises(ValueError):
            program["f"] = np.zeros((100, 1, 1), dtype=np.float32)
Пример #9
0
 def test_init_from_shader(self):
     program = Program(VertexShader("A"), FragmentShader("B"))
     assert len(program.shaders) == 2
     assert program.shaders[0].code == "A"
     assert program.shaders[1].code == "B"
Пример #10
0
 def test_delete_no_context(self):
     shader = VertexShader()
     shader.delete()
Пример #11
0
 def test_attribute_float(self):
     shader = VertexShader("attribute float color;")
     attributes = shader._get_attributes()
     assert attributes == [("color", gl.GL_FLOAT)]
Пример #12
0
 def test_attribute_vec4(self):
     shader = VertexShader("attribute vec4 color;")
     attributes = shader._get_attributes()
     assert attributes == [("color", gl.GL_FLOAT_VEC4)]
Пример #13
0
 def test_attributes(self):
     vert = VertexShader("attribute float A;")
     frag = FragmentShader("")
     program = Program(vert, frag)
     assert program.attributes[0].name == 'A'
     assert program.attributes[0].gtype == gl.GL_FLOAT
Пример #14
0
 def test_attribute_vec4(self):
     shader = VertexShader("attribute vec4 color;")
     attributes = shader._get_attributes()
     assert attributes == [ ("color", gl.GL_FLOAT_VEC4) ]
Пример #15
0
 def test_uniform_float(self):
     shader = VertexShader("uniform float color;")
     uniforms = shader._get_uniforms()
     assert uniforms == [ ("color", gl.GL_FLOAT) ]
Пример #16
0
 def test_setcode(self):
     shader = VertexShader()
     shader.code = ""
     assert shader._need_update == True
Пример #17
0
 def test_setcode(self):
     shader = VertexShader()
     shader.code = ""
     assert shader._need_update == True
Пример #18
0
 def test_uniform_vec4(self):
     shader = VertexShader("uniform vec4 color;")
     uniforms = shader._get_uniforms()
     assert uniforms == [ ("color", gl.GL_FLOAT_VEC4) ]
Пример #19
0
 def test_sourcecode(self):
     code = "/* Code */"
     shader = VertexShader(code)
     assert shader.code == code
     assert shader.source == "<string>"
Пример #20
0
 def test_uniform_array(self):
     shader = VertexShader("uniform float color[2];")
     uniforms=shader._get_uniforms()
     assert uniforms == [ ("color[0]", gl.GL_FLOAT),
                          ("color[1]", gl.GL_FLOAT)  ]
Пример #21
0
 def test_init(self):
     shader = VertexShader()
     assert shader._target == gl.GL_VERTEX_SHADER
Пример #22
0
 def test_unique_shader(self):
     vert = VertexShader("A")
     frag = FragmentShader("B")
     program = Program([vert, vert], [frag, frag, frag])
     assert len(program.shaders) == 2
Пример #23
0
 def test_uniform_vec4(self):
     shader = VertexShader("uniform vec4 color;")
     uniforms = shader._get_uniforms()
     assert uniforms == [("color", gl.GL_FLOAT_VEC4)]
Пример #24
0
 def test_empty_build(self):
     shader = VertexShader()
     with self.assertRaises(ShaderError):
         shader.activate()
Пример #25
0
 def test_uniform_array(self):
     shader = VertexShader("uniform float color[2];")
     uniforms = shader._get_uniforms()
     assert uniforms == [("color[0]", gl.GL_FLOAT),
                         ("color[1]", gl.GL_FLOAT)]
Пример #26
0
 def test_empty_build(self):
     shader = VertexShader()
     with self.assertRaises(ShaderError):
         shader.activate()
Пример #27
0
 def test_attribute_float(self):
     shader = VertexShader("attribute float color;")
     attributes = shader._get_attributes()
     assert attributes == [ ("color", gl.GL_FLOAT) ]
Пример #28
0
 def test_delete_no_context(self):
     shader = VertexShader()
     shader.delete()
Пример #29
0
 def test_uniform_float(self):
     shader = VertexShader("uniform float color;")
     uniforms = shader._get_uniforms()
     assert uniforms == [("color", gl.GL_FLOAT)]
Пример #30
0
    def test_set_uniform_vec4(self):
        vert = VertexShader("uniform vec4 color;")
        frag = FragmentShader("")

        program = Program(vert, frag)
        program["color"] = 1, 1, 1, 1
Пример #31
0
 def test_setcode(self):
     shader = VertexShader()
     shader.set_code("")
     assert shader._need_update == True