Skip to content

Commit

Permalink
examples: Support GL >= 3.1 and GLES >= 3.0 in the glium example
Browse files Browse the repository at this point in the history
Fixes #1731
  • Loading branch information
sdroege authored and bilelmoussaoui committed May 13, 2024
1 parent 424392c commit f0386ef
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions examples/glium_gl_area/glium_gl_area/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,22 @@ impl Renderer {
let index_buffer =
IndexBuffer::new(&context, PrimitiveType::TrianglesList, &[0u16, 1, 2]).unwrap();
let program = program!(&context,
// This example includes a shader that requires GLSL 140 or above.
// This example includes a shader that requires GLSL 1.40 or above.
//
// Emmanuele Bassi explains:
// GLSL 1.40 is supported by GL 3.1 or above, but not by GLES 2.0 which only supports
// GLSL 1.00. GLES 3.0 supports GLSL 3.00 ES, which also supports the shader below but
// requires the floating point precision to be specified.
//
// The version of the shaders depend on the version of GL; currently, GTK4 uses:
//
// - 100 on GLES
// - 110 on GL2 legacy
// - 130 on GL3 legacy
// - 150 on GL3.2+
// GL < 3.1 and GLES < 3.0 are not supported by the example.
//
// In practice, the version of GLSL for the shaders inside your application depends on
// the GL context you're either creating or usingi.e. if you support multiple versions
// the GL context you're either creating or usingi.e. if you support multiple versions
// of GL then you should load different shaders.
//
// If you only care about recent GL, as you should, then going for GLSL 1.50 is
// perfectly fine; anything else will error out, and you can catch that error and fall
// back to something else.
// back to something else. This example simply unwrap()s on error and does not
// implement a fallback or error reporting.
140 => {
vertex: "
#version 140
Expand All @@ -86,6 +84,29 @@ impl Renderer {
}
"
},
300 es => {
vertex: "
#version 300 es
uniform mat4 matrix;
in vec2 position;
in vec3 color;
out vec3 vColor;
void main() {
gl_Position = vec4(position, 0.0, 1.0) * matrix;
vColor = color;
}
",

fragment: "
#version 300 es
precision mediump float;
in vec3 vColor;
out vec4 f_color;
void main() {
f_color = vec4(vColor, 1.0);
}
"
},
)
.unwrap();

Expand Down

0 comments on commit f0386ef

Please sign in to comment.