Example #1
0
    def test(self):
        a = gl.AbstractShaderProgram()

        if magnum.TARGET_GLES2:
            vert = gl.Shader(gl.Version.GLES200, gl.Shader.Type.VERTEX)
        elif magnum.TARGET_GLES:
            vert = gl.Shader(gl.Version.GLES300, gl.Shader.Type.VERTEX)
        else:
            vert = gl.Shader(gl.Version.GL300, gl.Shader.Type.VERTEX)
        if magnum.TARGET_GLES2:
            vert.add_source("""
attribute lowp vec4 position;
uniform lowp mat4 transformationProjectionMatrix;

void main() {
    gl_Position = transformationProjectionMatrix*position;
}
            """.strip())
        else:
            vert.add_source("""
in lowp vec4 position;
uniform lowp mat4 transformationProjectionMatrix;

void main() {
    gl_Position = transformationProjectionMatrix*position;
}
            """.strip())

        vert.compile()
        a.attach_shader(vert)

        if magnum.TARGET_GLES2:
            frag = gl.Shader(gl.Version.GLES200, gl.Shader.Type.FRAGMENT)
        elif magnum.TARGET_GLES:
            frag = gl.Shader(gl.Version.GLES300, gl.Shader.Type.FRAGMENT)
        else:
            frag = gl.Shader(gl.Version.GL300, gl.Shader.Type.FRAGMENT)
        if magnum.TARGET_GLES2:
            frag.add_source("""
void main() {
    gl_FragColor = vec4(0.0);
}
            """.strip())
        else:
            frag.add_source("""
out lowp vec4 color;

void main() {
    color = vec4(0.0);
}
            """.strip())
        frag.compile()
        a.attach_shader(frag)

        a.bind_attribute_location(0, "position")
        a.link()
        location = a.uniform_location("transformationProjectionMatrix")
        self.assertGreaterEqual(location, 0)
        a.set_uniform(location, Matrix4())
Example #2
0
    def test_uniform_fail(self):
        a = gl.AbstractShaderProgram()
        with self.assertRaisesRegex(ValueError, "location of uniform 'nonexistent' cannot be retrieved"):
            a.uniform_location("nonexistent")
        # Asking for uniform on a non-linked program is an error, eat it so the
        # setup/teardown checks don't complain
        self.assertEqual(gl.Renderer.error, gl.Renderer.Error.INVALID_OPERATION)

        if not magnum.TARGET_GLES2:
            with self.assertRaisesRegex(ValueError, "index of uniform block 'nonexistent' cannot be retrieved"):
                a.uniform_block_index("nonexistent")
Example #3
0
 def test_link_fail(self):
     a = gl.AbstractShaderProgram()
     # Link of an empty shader will always fail
     with self.assertRaisesRegex(RuntimeError, "linking failed"):
         a.link()