summaryrefslogtreecommitdiffstats
path: root/third_party/rust/wgpu-hal/src/gles/egl.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/wgpu-hal/src/gles/egl.rs')
-rw-r--r--third_party/rust/wgpu-hal/src/gles/egl.rs74
1 files changed, 57 insertions, 17 deletions
diff --git a/third_party/rust/wgpu-hal/src/gles/egl.rs b/third_party/rust/wgpu-hal/src/gles/egl.rs
index b166f4f102..00ef70ba88 100644
--- a/third_party/rust/wgpu-hal/src/gles/egl.rs
+++ b/third_party/rust/wgpu-hal/src/gles/egl.rs
@@ -526,28 +526,51 @@ impl Inner {
}
let (config, supports_native_window) = choose_config(&egl, display, srgb_kind)?;
- egl.bind_api(khronos_egl::OPENGL_ES_API).unwrap();
+
+ let supports_opengl = if version >= (1, 4) {
+ let client_apis = egl
+ .query_string(Some(display), khronos_egl::CLIENT_APIS)
+ .unwrap()
+ .to_string_lossy();
+ client_apis
+ .split(' ')
+ .any(|client_api| client_api == "OpenGL")
+ } else {
+ false
+ };
+ egl.bind_api(if supports_opengl {
+ khronos_egl::OPENGL_API
+ } else {
+ khronos_egl::OPENGL_ES_API
+ })
+ .unwrap();
let needs_robustness = true;
let mut khr_context_flags = 0;
let supports_khr_context = display_extensions.contains("EGL_KHR_create_context");
- //TODO: make it so `Device` == EGL Context
- let mut context_attributes = vec![
- khronos_egl::CONTEXT_MAJOR_VERSION,
- 3, // Request GLES 3.0 or higher
- ];
-
- if force_gles_minor_version != wgt::Gles3MinorVersion::Automatic {
+ let mut context_attributes = vec![];
+ if supports_opengl {
+ context_attributes.push(khronos_egl::CONTEXT_MAJOR_VERSION);
+ context_attributes.push(3);
context_attributes.push(khronos_egl::CONTEXT_MINOR_VERSION);
- context_attributes.push(match force_gles_minor_version {
- wgt::Gles3MinorVersion::Version0 => 0,
- wgt::Gles3MinorVersion::Version1 => 1,
- wgt::Gles3MinorVersion::Version2 => 2,
- _ => unreachable!(),
- });
+ context_attributes.push(3);
+ if force_gles_minor_version != wgt::Gles3MinorVersion::Automatic {
+ log::warn!("Ignoring specified GLES minor version as OpenGL is used");
+ }
+ } else {
+ context_attributes.push(khronos_egl::CONTEXT_MAJOR_VERSION);
+ context_attributes.push(3); // Request GLES 3.0 or higher
+ if force_gles_minor_version != wgt::Gles3MinorVersion::Automatic {
+ context_attributes.push(khronos_egl::CONTEXT_MINOR_VERSION);
+ context_attributes.push(match force_gles_minor_version {
+ wgt::Gles3MinorVersion::Automatic => unreachable!(),
+ wgt::Gles3MinorVersion::Version0 => 0,
+ wgt::Gles3MinorVersion::Version1 => 1,
+ wgt::Gles3MinorVersion::Version2 => 2,
+ });
+ }
}
-
if flags.contains(wgt::InstanceFlags::DEBUG) {
if version >= (1, 5) {
log::debug!("\tEGL context: +debug");
@@ -577,8 +600,6 @@ impl Inner {
// because it's for desktop GL only, not GLES.
log::warn!("\tEGL context: -robust access");
}
-
- //TODO do we need `khronos_egl::CONTEXT_OPENGL_NOTIFICATION_STRATEGY_EXT`?
}
if khr_context_flags != 0 {
context_attributes.push(EGL_CONTEXT_FLAGS_KHR);
@@ -977,6 +998,7 @@ impl crate::Instance for Instance {
srgb_kind: inner.srgb_kind,
})
}
+
unsafe fn destroy_surface(&self, _surface: Surface) {}
unsafe fn enumerate_adapters(&self) -> Vec<crate::ExposedAdapter<super::Api>> {
@@ -993,6 +1015,12 @@ impl crate::Instance for Instance {
})
};
+ // In contrast to OpenGL ES, OpenGL requires explicitly enabling sRGB conversions,
+ // as otherwise the user has to do the sRGB conversion.
+ if !matches!(inner.srgb_kind, SrgbFrameBufferKind::None) {
+ unsafe { gl.enable(glow::FRAMEBUFFER_SRGB) };
+ }
+
if self.flags.contains(wgt::InstanceFlags::DEBUG) && gl.supports_debug() {
log::debug!("Max label length: {}", unsafe {
gl.get_parameter_i32(glow::MAX_LABEL_LENGTH)
@@ -1106,6 +1134,13 @@ impl Surface {
unsafe { gl.bind_framebuffer(glow::DRAW_FRAMEBUFFER, None) };
unsafe { gl.bind_framebuffer(glow::READ_FRAMEBUFFER, Some(sc.framebuffer)) };
+
+ if !matches!(self.srgb_kind, SrgbFrameBufferKind::None) {
+ // Disable sRGB conversions for `glBlitFramebuffer` as behavior does diverge between
+ // drivers and formats otherwise and we want to ensure no sRGB conversions happen.
+ unsafe { gl.disable(glow::FRAMEBUFFER_SRGB) };
+ }
+
// Note the Y-flipping here. GL's presentation is not flipped,
// but main rendering is. Therefore, we Y-flip the output positions
// in the shader, and also this blit.
@@ -1123,6 +1158,11 @@ impl Surface {
glow::NEAREST,
)
};
+
+ if !matches!(self.srgb_kind, SrgbFrameBufferKind::None) {
+ unsafe { gl.enable(glow::FRAMEBUFFER_SRGB) };
+ }
+
unsafe { gl.bind_framebuffer(glow::READ_FRAMEBUFFER, None) };
self.egl