gles2: Make proper use of formats to avoid unnecessary shaders

This commit is contained in:
Victor Brekenfeld 2021-05-16 23:05:44 +02:00
parent 55b4d4b89a
commit 0025f13adc
2 changed files with 9 additions and 49 deletions

View File

@ -373,8 +373,6 @@ impl Gles2Renderer {
let programs = [
texture_program(&gl, shaders::FRAGMENT_SHADER_ABGR)?,
texture_program(&gl, shaders::FRAGMENT_SHADER_XBGR)?,
texture_program(&gl, shaders::FRAGMENT_SHADER_BGRA)?,
texture_program(&gl, shaders::FRAGMENT_SHADER_BGRX)?,
texture_program(&gl, shaders::FRAGMENT_SHADER_EXTERNAL)?,
];
@ -459,8 +457,8 @@ impl Gles2Renderer {
let (gl_format, shader_idx) = match data.format {
wl_shm::Format::Abgr8888 => (ffi::RGBA, 0),
wl_shm::Format::Xbgr8888 => (ffi::RGBA, 1),
wl_shm::Format::Argb8888 => (ffi::BGRA_EXT, 2),
wl_shm::Format::Xrgb8888 => (ffi::BGRA_EXT, 3),
wl_shm::Format::Argb8888 => (ffi::BGRA_EXT, 0),
wl_shm::Format::Xrgb8888 => (ffi::BGRA_EXT, 1),
format => return Err(Gles2Error::UnsupportedPixelFormat(format)),
};
@ -493,7 +491,7 @@ impl Gles2Renderer {
width,
height,
0,
ffi::RGBA,
gl_format,
ffi::UNSIGNED_BYTE as u32,
slice.as_ptr() as *const _,
);
@ -551,9 +549,9 @@ impl Gles2Renderer {
Gles2Texture(Rc::new(Gles2TextureInternal {
texture: tex,
texture_kind: match new_buffer.format {
EGLFormat::RGB => 3,
EGLFormat::RGBA => 2,
EGLFormat::External => 4,
EGLFormat::RGB => 1,
EGLFormat::RGBA => 0,
EGLFormat::External => 2,
_ => unreachable!("EGLBuffer currenly does not expose multi-planar buffers to us"),
},
is_external: new_buffer.format == EGLFormat::External,

View File

@ -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;
}
"#;