<NME> shaders.rs
<BEF> /*
 * OpenGL Shaders
 */
pub const VERTEX_SHADER: &str = r#"
#version 100
uniform mat3 matrix;
uniform mat3 tex_matrix;

attribute vec2 vert;
attribute vec4 vert_position;

varying vec2 v_tex_coords;

mat2 scale(vec2 scale_vec){
    return mat2(
        scale_vec.x, 0.0,
    }
}"#;

pub const FRAGMENT_COUNT: usize = 5;

pub const FRAGMENT_SHADER_ABGR: &str = r#"
#version 100
    vec3 position = vec3(vert * scale(vert_transform_scale) + vert_transform_translation, 1.0);
    v_tex_coords = (tex_matrix * position).xy;
uniform float alpha;
varying vec2 v_tex_coords;
void main() {
    vec4 color = texture2D(tex, v_tex_coords);
    gl_FragColor.r = color.w;
    gl_FragColor.g = color.z;
    gl_FragColor.b = color.y;
    gl_FragColor.a = color.x * alpha;
}
"#;

#version 100

precision mediump float;
uniform sampler2D tex;
uniform float alpha;
varying vec2 v_tex_coords;
void main() {
    vec4 color = texture2D(tex, v_tex_coords);
    gl_FragColor.r = color.w;
    gl_FragColor.g = color.z;
    gl_FragColor.b = color.y;
    gl_FragColor.a = alpha;
}
"#;

pub const FRAGMENT_SHADER_BGRA: &str = r#"
#version 100
precision mediump float;
uniform sampler2D tex;
uniform float alpha;
varying vec2 v_tex_coords;
void main() {
    vec4 color = texture2D(tex, v_tex_coords);
    gl_FragColor.r = color.z;
    gl_FragColor.g = color.y;
    gl_FragColor.b = color.x;
    gl_FragColor.a = color.w * alpha;
}
"#;

pub const FRAGMENT_SHADER_BGRX: &str = r#"
#version 100
precision mediump float;
uniform sampler2D tex;
uniform float alpha;
varying vec2 v_tex_coords;
void main() {
    vec4 color = texture2D(tex, v_tex_coords);
    gl_FragColor.r = color.z;
    gl_FragColor.g = color.y;
    gl_FragColor.b = color.x;
    gl_FragColor.a = alpha;
}
"#;


pub const FRAGMENT_SHADER_XBGR: &str = r#"
#version 100

precision mediump float;
uniform sampler2D tex;
uniform float alpha;
varying vec2 v_tex_coords;

void main() {
    gl_FragColor = vec4(texture2D(tex, v_tex_coords).rgb, 1.0) * alpha;
}
"#;

pub const FRAGMENT_SHADER_EXTERNAL: &str = r#"
#version 100
#extension GL_OES_EGL_image_external : require

precision mediump float;
uniform samplerExternalOES tex;
uniform float alpha;
varying vec2 v_tex_coords;

void main() {
    gl_FragColor = texture2D(tex, v_tex_coords) * alpha;
}
"#;

pub const VERTEX_SHADER_SOLID: &str = r#"
#version 100

uniform mat3 matrix;
attribute vec2 vert;
attribute vec4 position;

mat2 scale(vec2 scale_vec){
    return mat2(
        scale_vec.x, 0.0,
        0.0, scale_vec.y
    );
}

void main() {
    vec2 transform_translation = position.xy;
    vec2 transform_scale = position.zw;
    vec3 position = vec3(vert * scale(transform_scale) + transform_translation, 1.0);
    gl_Position = vec4(matrix * position, 1.0);
}
"#;

pub const FRAGMENT_SHADER_SOLID: &str = r#"
#version 100

precision mediump float;
uniform vec4 color;

void main() {
    gl_FragColor = color;
}
"#;

<MSG> gles2: Make proper use of formats to avoid unnecessary shaders

<DFF> @@ -17,7 +17,7 @@ void main() {
     }
 }"#;
 
-pub const FRAGMENT_COUNT: usize = 5;
+pub const FRAGMENT_COUNT: usize = 3;
 
 pub const FRAGMENT_SHADER_ABGR: &str = r#"
 #version 100
@@ -26,11 +26,7 @@ uniform sampler2D tex;
 uniform float alpha;
 varying vec2 v_tex_coords;
 void main() {
-    vec4 color = texture2D(tex, v_tex_coords);
-    gl_FragColor.r = color.w;
-    gl_FragColor.g = color.z;
-    gl_FragColor.b = color.y;
-    gl_FragColor.a = color.x * alpha;
+    gl_FragColor = texture2D(tex, v_tex_coords) * alpha;
 }
 "#;
 
@@ -41,41 +37,7 @@ uniform sampler2D tex;
 uniform float alpha;
 varying vec2 v_tex_coords;
 void main() {
-    vec4 color = texture2D(tex, v_tex_coords);
-    gl_FragColor.r = color.w;
-    gl_FragColor.g = color.z;
-    gl_FragColor.b = color.y;
-    gl_FragColor.a = alpha;
-}
-"#;
-
-pub const FRAGMENT_SHADER_BGRA: &str = r#"
-#version 100
-precision mediump float;
-uniform sampler2D tex;
-uniform float alpha;
-varying vec2 v_tex_coords;
-void main() {
-    vec4 color = texture2D(tex, v_tex_coords);
-    gl_FragColor.r = color.z;
-    gl_FragColor.g = color.y;
-    gl_FragColor.b = color.x;
-    gl_FragColor.a = color.w * alpha;
-}
-"#;
-
-pub const FRAGMENT_SHADER_BGRX: &str = r#"
-#version 100
-precision mediump float;
-uniform sampler2D tex;
-uniform float alpha;
-varying vec2 v_tex_coords;
-void main() {
-    vec4 color = texture2D(tex, v_tex_coords);
-    gl_FragColor.r = color.z;
-    gl_FragColor.g = color.y;
-    gl_FragColor.b = color.x;
-    gl_FragColor.a = alpha;
+    gl_FragColor = vec4(texture2D(tex, v_tex_coords).rgb, 1.0) * alpha;
 }
 "#;
 

gles2: Make proper use of formats to avoid unnecessary shaders