gles2: Make proper use of formats to avoid unnecessary shaders
This commit is contained in:
parent
55b4d4b89a
commit
0025f13adc
|
@ -373,8 +373,6 @@ impl Gles2Renderer {
|
||||||
let programs = [
|
let programs = [
|
||||||
texture_program(&gl, shaders::FRAGMENT_SHADER_ABGR)?,
|
texture_program(&gl, shaders::FRAGMENT_SHADER_ABGR)?,
|
||||||
texture_program(&gl, shaders::FRAGMENT_SHADER_XBGR)?,
|
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)?,
|
texture_program(&gl, shaders::FRAGMENT_SHADER_EXTERNAL)?,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -459,8 +457,8 @@ impl Gles2Renderer {
|
||||||
let (gl_format, shader_idx) = match data.format {
|
let (gl_format, shader_idx) = match data.format {
|
||||||
wl_shm::Format::Abgr8888 => (ffi::RGBA, 0),
|
wl_shm::Format::Abgr8888 => (ffi::RGBA, 0),
|
||||||
wl_shm::Format::Xbgr8888 => (ffi::RGBA, 1),
|
wl_shm::Format::Xbgr8888 => (ffi::RGBA, 1),
|
||||||
wl_shm::Format::Argb8888 => (ffi::BGRA_EXT, 2),
|
wl_shm::Format::Argb8888 => (ffi::BGRA_EXT, 0),
|
||||||
wl_shm::Format::Xrgb8888 => (ffi::BGRA_EXT, 3),
|
wl_shm::Format::Xrgb8888 => (ffi::BGRA_EXT, 1),
|
||||||
format => return Err(Gles2Error::UnsupportedPixelFormat(format)),
|
format => return Err(Gles2Error::UnsupportedPixelFormat(format)),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -493,7 +491,7 @@ impl Gles2Renderer {
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
0,
|
0,
|
||||||
ffi::RGBA,
|
gl_format,
|
||||||
ffi::UNSIGNED_BYTE as u32,
|
ffi::UNSIGNED_BYTE as u32,
|
||||||
slice.as_ptr() as *const _,
|
slice.as_ptr() as *const _,
|
||||||
);
|
);
|
||||||
|
@ -551,9 +549,9 @@ impl Gles2Renderer {
|
||||||
Gles2Texture(Rc::new(Gles2TextureInternal {
|
Gles2Texture(Rc::new(Gles2TextureInternal {
|
||||||
texture: tex,
|
texture: tex,
|
||||||
texture_kind: match new_buffer.format {
|
texture_kind: match new_buffer.format {
|
||||||
EGLFormat::RGB => 3,
|
EGLFormat::RGB => 1,
|
||||||
EGLFormat::RGBA => 2,
|
EGLFormat::RGBA => 0,
|
||||||
EGLFormat::External => 4,
|
EGLFormat::External => 2,
|
||||||
_ => unreachable!("EGLBuffer currenly does not expose multi-planar buffers to us"),
|
_ => unreachable!("EGLBuffer currenly does not expose multi-planar buffers to us"),
|
||||||
},
|
},
|
||||||
is_external: new_buffer.format == EGLFormat::External,
|
is_external: new_buffer.format == EGLFormat::External,
|
||||||
|
|
|
@ -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#"
|
pub const FRAGMENT_SHADER_ABGR: &str = r#"
|
||||||
#version 100
|
#version 100
|
||||||
|
@ -26,11 +26,7 @@ uniform sampler2D tex;
|
||||||
uniform float alpha;
|
uniform float alpha;
|
||||||
varying vec2 v_tex_coords;
|
varying vec2 v_tex_coords;
|
||||||
void main() {
|
void main() {
|
||||||
vec4 color = texture2D(tex, v_tex_coords);
|
gl_FragColor = texture2D(tex, v_tex_coords) * alpha;
|
||||||
gl_FragColor.r = color.w;
|
|
||||||
gl_FragColor.g = color.z;
|
|
||||||
gl_FragColor.b = color.y;
|
|
||||||
gl_FragColor.a = color.x * alpha;
|
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
|
@ -41,41 +37,7 @@ uniform sampler2D tex;
|
||||||
uniform float alpha;
|
uniform float alpha;
|
||||||
varying vec2 v_tex_coords;
|
varying vec2 v_tex_coords;
|
||||||
void main() {
|
void main() {
|
||||||
vec4 color = texture2D(tex, v_tex_coords);
|
gl_FragColor = vec4(texture2D(tex, v_tex_coords).rgb, 1.0) * alpha;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue