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_uniform(self): vert = VertexShader("uniform float A;") frag = FragmentShader("uniform float A; uniform vec4 B;") program = Program(vert, frag) assert ("A", gl.GL_FLOAT) in program.all_uniforms assert ("B", gl.GL_FLOAT_VEC4) in program.all_uniforms assert len(program.all_uniforms) == 2
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(verts=vert) self.assertRaises(ValueError, program.activate) program = Program(frags=frag) self.assertRaises(ValueError, program.activate)
def test_uniform_array(self): shader = VertexShader("uniform float color[2];") assert shader.uniforms == [("color[0]", gl.GL_FLOAT), ("color[1]", gl.GL_FLOAT)]
def test_uniform_vec4(self): shader = VertexShader("uniform vec4 color;") assert shader.uniforms == [("color", gl.GL_FLOAT_VEC4)]
def test_uniform_float(self): shader = VertexShader("uniform float color;") assert shader.uniforms == [("color", gl.GL_FLOAT)]
def test_delete_no_context(self): shader = VertexShader() shader.delete()
def test_empty_build(self): shader = VertexShader() #with self.assertRaises(RuntimeError): # shader.activate() self.assertRaises(RuntimeError, shader.activate)
def test_sourcecode(self): code = "/* Code */" shader = VertexShader(code) assert shader.code == code assert shader.source == "<string>"
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_init(self): shader = VertexShader() assert shader._target == gl.GL_VERTEX_SHADER
def test_setitem(self): vert = VertexShader("") frag = FragmentShader("") program = Program(vert, frag) self.assertRaises(ValueError, program.__setitem__, "A", 1)
def test_attributes(self): vert = VertexShader("attribute float A;") frag = FragmentShader("") program = Program(vert, frag) assert program.all_attributes == [("A", gl.GL_FLOAT)]
def test_attribute_float(self): shader = VertexShader("attribute float color;") assert shader.attributes == [("color", gl.GL_FLOAT)]
def test_init(self): shader = VertexShader() assert shader._handle == -1 assert shader.code is None assert shader.source is None
def test_attribute_vec4(self): shader = VertexShader("attribute vec4 color;") assert shader.attributes == [("color", gl.GL_FLOAT_VEC4)]
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"