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"
def test_setitem(self): vert = VertexShader("") frag = FragmentShader("") program = Program(vert, frag) with self.assertRaises(NameError): program["A"] = 1
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
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
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
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"
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()
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)
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"
def test_delete_no_context(self): shader = VertexShader() shader.delete()
def test_attribute_float(self): shader = VertexShader("attribute float color;") attributes = shader._get_attributes() assert attributes == [("color", gl.GL_FLOAT)]
def test_attribute_vec4(self): shader = VertexShader("attribute vec4 color;") attributes = shader._get_attributes() assert attributes == [("color", gl.GL_FLOAT_VEC4)]
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
def test_attribute_vec4(self): shader = VertexShader("attribute vec4 color;") attributes = shader._get_attributes() assert attributes == [ ("color", gl.GL_FLOAT_VEC4) ]
def test_uniform_float(self): shader = VertexShader("uniform float color;") uniforms = shader._get_uniforms() assert uniforms == [ ("color", gl.GL_FLOAT) ]
def test_setcode(self): shader = VertexShader() shader.code = "" assert shader._need_update == True
def test_uniform_vec4(self): shader = VertexShader("uniform vec4 color;") uniforms = shader._get_uniforms() assert uniforms == [ ("color", gl.GL_FLOAT_VEC4) ]
def test_sourcecode(self): code = "/* Code */" shader = VertexShader(code) assert shader.code == code assert shader.source == "<string>"
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) ]
def test_init(self): shader = VertexShader() assert shader._target == gl.GL_VERTEX_SHADER
def test_unique_shader(self): vert = VertexShader("A") frag = FragmentShader("B") program = Program([vert, vert], [frag, frag, frag]) assert len(program.shaders) == 2
def test_uniform_vec4(self): shader = VertexShader("uniform vec4 color;") uniforms = shader._get_uniforms() assert uniforms == [("color", gl.GL_FLOAT_VEC4)]
def test_empty_build(self): shader = VertexShader() with self.assertRaises(ShaderError): shader.activate()
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)]
def test_attribute_float(self): shader = VertexShader("attribute float color;") attributes = shader._get_attributes() assert attributes == [ ("color", gl.GL_FLOAT) ]
def test_uniform_float(self): shader = VertexShader("uniform float color;") uniforms = shader._get_uniforms() assert uniforms == [("color", gl.GL_FLOAT)]
def test_set_uniform_vec4(self): vert = VertexShader("uniform vec4 color;") frag = FragmentShader("") program = Program(vert, frag) program["color"] = 1, 1, 1, 1
def test_setcode(self): shader = VertexShader() shader.set_code("") assert shader._need_update == True