def test_compile_fail(self): if magnum.TARGET_GLES2: a = gl.Shader(gl.Version.GLES200, gl.Shader.Type.VERTEX) elif magnum.TARGET_GLES: a = gl.Shader(gl.Version.GLES300, gl.Shader.Type.VERTEX) else: a = gl.Shader(gl.Version.GL300, gl.Shader.Type.VERTEX) a.add_source("error!!!!") with self.assertRaisesRegex(RuntimeError, "compilation failed"): a.compile()
def test(self): if magnum.TARGET_GLES2: a = gl.Shader(gl.Version.GLES200, gl.Shader.Type.VERTEX) elif magnum.TARGET_GLES: a = gl.Shader(gl.Version.GLES300, gl.Shader.Type.VERTEX) else: a = gl.Shader(gl.Version.GL300, gl.Shader.Type.VERTEX) a.add_source(""" void main() { gl_Position = vec4(0.0); } """) a.compile()
def __init__(self): super().__init__() vert = gl.Shader(gl.Version.GL330, gl.Shader.Type.VERTEX) vert.add_source(""" layout(location = 0) in vec4 position; layout(location = 1) in vec2 textureCoordinates; out vec2 interpolatedTextureCoordinates; void main() { interpolatedTextureCoordinates = textureCoordinates; gl_Position = position; } """.lstrip()) vert.compile() self.attach_shader(vert) frag = gl.Shader(gl.Version.GL330, gl.Shader.Type.FRAGMENT) frag.add_source(""" uniform vec3 color = vec3(1.0, 1.0, 1.0); uniform sampler2D textureData; in vec2 interpolatedTextureCoordinates; out vec4 fragmentColor; void main() { fragmentColor.rgb = color*texture(textureData, interpolatedTextureCoordinates).rgb; fragmentColor.a = 1.0; } """.lstrip()) frag.compile() self.attach_shader(frag) self.link() self._color_uniform = self.uniform_location('color') self.set_uniform(self.uniform_location('textureData'), self._texture_unit)
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())