diff --git a/surfman/src/connection.rs b/surfman/src/connection.rs index bb35502..04e3685 100644 --- a/surfman/src/connection.rs +++ b/surfman/src/connection.rs @@ -3,6 +3,7 @@ //! The abstract interface that all connections conform to. use crate::Error; +use crate::GLApi; #[cfg(feature = "sm-winit")] use winit::Window; @@ -26,6 +27,9 @@ pub trait Connection: Sized { /// Returns the native connection corresponding to this connection. fn native_connection(&self) -> Self::NativeConnection; + /// Returns the OpenGL API flavor that this connection supports (OpenGL or OpenGL ES). + fn gl_api(&self) -> GLApi; + /// Returns the "best" adapter on this system, preferring high-performance hardware adapters. /// /// This is an alias for `Connection::create_hardware_adapter()`. diff --git a/surfman/src/implementation/connection.rs b/surfman/src/implementation/connection.rs index b14b44a..defb797 100644 --- a/surfman/src/implementation/connection.rs +++ b/surfman/src/implementation/connection.rs @@ -5,6 +5,7 @@ use crate::Error; use crate::connection::Connection as ConnectionInterface; +use crate::info::GLApi; use super::super::connection::{Connection, NativeConnection}; use super::super::device::{Adapter, Device, NativeDevice}; use super::super::surface::NativeWidget; @@ -29,6 +30,11 @@ impl ConnectionInterface for Connection { Connection::native_connection(self) } + #[inline] + fn gl_api(&self) -> GLApi { + Connection::gl_api(self) + } + #[inline] fn create_adapter(&self) -> Result { Connection::create_adapter(self) diff --git a/surfman/src/platform/android/connection.rs b/surfman/src/platform/android/connection.rs index 8764e5b..c5d3fbe 100644 --- a/surfman/src/platform/android/connection.rs +++ b/surfman/src/platform/android/connection.rs @@ -5,6 +5,7 @@ //! FIXME(pcwalton): Should this instead wrap `EGLDisplay`? Is that thread-safe on Android? use crate::Error; +use crate::GLApi; use super::device::{Adapter, Device, NativeDevice}; use super::surface::NativeWidget; @@ -38,6 +39,12 @@ impl Connection { NativeConnection } + /// Returns the OpenGL API flavor that this connection supports (OpenGL or OpenGL ES). + #[inline] + pub fn gl_api(&self) -> GLApi { + GLApi::GLES + } + /// Returns the "best" adapter on this system. /// /// This is an alias for `Connection::create_hardware_adapter()`. diff --git a/surfman/src/platform/generic/multi/connection.rs b/surfman/src/platform/generic/multi/connection.rs index 0552b5e..6166c6d 100644 --- a/surfman/src/platform/generic/multi/connection.rs +++ b/surfman/src/platform/generic/multi/connection.rs @@ -3,6 +3,7 @@ //! A connection abstraction that allows the choice of backends dynamically. use crate::Error; +use crate::GLApi; use crate::connection::Connection as ConnectionInterface; use crate::device::Device as DeviceInterface; use super::device::{Adapter, Device, NativeDevice}; @@ -73,6 +74,14 @@ impl Connection } } + /// Returns the OpenGL API flavor that this connection supports (OpenGL or OpenGL ES). + pub fn gl_api(&self) -> GLApi { + match *self { + Connection::Default(ref connection) => connection.gl_api(), + Connection::Alternate(ref connection) => connection.gl_api(), + } + } + /// Returns the "best" adapter on this system. /// /// This is an alias for `Connection::create_hardware_adapter()`. @@ -213,6 +222,11 @@ impl ConnectionInterface for Connection Connection::native_connection(self) } + #[inline] + fn gl_api(&self) -> GLApi { + Connection::gl_api(self) + } + #[inline] fn create_adapter(&self) -> Result, Error> { Connection::create_adapter(self) diff --git a/surfman/src/platform/macos/cgl/connection.rs b/surfman/src/platform/macos/cgl/connection.rs index 69d54d6..213a474 100644 --- a/surfman/src/platform/macos/cgl/connection.rs +++ b/surfman/src/platform/macos/cgl/connection.rs @@ -6,6 +6,7 @@ //! global window server connection. use crate::Error; +use crate::GLApi; use crate::platform::macos::system::connection::Connection as SystemConnection; use crate::platform::macos::system::device::NativeDevice; use crate::platform::macos::system::surface::NativeWidget; @@ -40,6 +41,12 @@ impl Connection { self.0.native_connection() } + /// Returns the OpenGL API flavor that this connection supports (OpenGL or OpenGL ES). + #[inline] + pub fn gl_api(&self) -> GLApi { + GLApi::GL + } + /// Returns the "best" adapter on this system, preferring high-performance hardware adapters. /// /// This is an alias for `Connection::create_hardware_adapter()`. diff --git a/surfman/src/platform/unix/generic/connection.rs b/surfman/src/platform/unix/generic/connection.rs index 1ef563f..38cd55c 100644 --- a/surfman/src/platform/unix/generic/connection.rs +++ b/surfman/src/platform/unix/generic/connection.rs @@ -5,6 +5,7 @@ use crate::Error; use crate::egl::types::{EGLAttrib, EGLDisplay}; use crate::egl; +use crate::info::GLApi; use crate::platform::generic::egl::device::EGL_FUNCTIONS; use crate::platform::generic::egl::ffi::EGL_PLATFORM_SURFACELESS_MESA; use super::device::{Adapter, Device, NativeDevice}; @@ -78,6 +79,12 @@ impl Connection { NativeConnection(self.native_connection.clone()) } + /// Returns the OpenGL API flavor that this connection supports (OpenGL or OpenGL ES). + #[inline] + pub fn gl_api(&self) -> GLApi { + GLApi::GL + } + /// Returns the "best" adapter on this system, preferring high-performance hardware adapters. /// /// This is an alias for `Connection::create_hardware_adapter()`. diff --git a/surfman/src/platform/unix/wayland/connection.rs b/surfman/src/platform/unix/wayland/connection.rs index 8dc1f87..9bac7fe 100644 --- a/surfman/src/platform/unix/wayland/connection.rs +++ b/surfman/src/platform/unix/wayland/connection.rs @@ -5,6 +5,7 @@ use crate::Error; use crate::egl::types::{EGLAttrib, EGLDisplay}; use crate::egl; +use crate::info::GLApi; use crate::platform::generic::egl::device::EGL_FUNCTIONS; use crate::platform::generic::egl::ffi::EGL_PLATFORM_WAYLAND_KHR; use super::device::{Adapter, Device, NativeDevice}; @@ -63,6 +64,12 @@ impl Connection { NativeConnection(self.native_connection.egl_display) } + /// Returns the OpenGL API flavor that this connection supports (OpenGL or OpenGL ES). + #[inline] + pub fn gl_api(&self) -> GLApi { + GLApi::GL + } + /// Returns the "best" adapter on this system, preferring high-performance hardware adapters. /// /// This is an alias for `Connection::create_hardware_adapter()`. diff --git a/surfman/src/platform/unix/x11/connection.rs b/surfman/src/platform/unix/x11/connection.rs index 97a694b..7d71767 100644 --- a/surfman/src/platform/unix/x11/connection.rs +++ b/surfman/src/platform/unix/x11/connection.rs @@ -5,6 +5,7 @@ use crate::egl::types::{EGLAttrib, EGLDisplay}; use crate::egl; use crate::error::Error; +use crate::info::GLApi; use crate::platform::generic::egl::device::EGL_FUNCTIONS; use crate::platform::generic::egl::ffi::EGL_PLATFORM_X11_KHR; use crate::platform::unix::generic::device::Adapter; @@ -136,6 +137,12 @@ impl Connection { } } + /// Returns the OpenGL API flavor that this connection supports (OpenGL or OpenGL ES). + #[inline] + pub fn gl_api(&self) -> GLApi { + GLApi::GL + } + /// Returns the "best" adapter on this system, preferring high-performance hardware adapters. /// /// This is an alias for `Connection::create_hardware_adapter()`. diff --git a/surfman/src/platform/windows/angle/connection.rs b/surfman/src/platform/windows/angle/connection.rs index 09bda61..d3e699a 100644 --- a/surfman/src/platform/windows/angle/connection.rs +++ b/surfman/src/platform/windows/angle/connection.rs @@ -8,6 +8,7 @@ //! implicit in the Win32 API, and as such this type is a no-op. use crate::Error; +use crate::GLApi; use super::device::{Adapter, Device, NativeDevice, VendorPreference}; use super::surface::NativeWidget; @@ -59,6 +60,12 @@ impl Connection { NativeConnection } + /// Returns the OpenGL API flavor that this connection supports (OpenGL or OpenGL ES). + #[inline] + pub fn gl_api(&self) -> GLApi { + GLApi::GLES + } + /// Returns the "best" adapter on this system, preferring high-performance hardware adapters. /// /// This is an alias for `Connection::create_hardware_adapter()`. diff --git a/surfman/src/platform/windows/wgl/connection.rs b/surfman/src/platform/windows/wgl/connection.rs index 305c2e8..e28cdc5 100644 --- a/surfman/src/platform/windows/wgl/connection.rs +++ b/surfman/src/platform/windows/wgl/connection.rs @@ -5,6 +5,7 @@ //! Window server connections are implicit in the Win32 API, so this is a zero-sized type. use crate::Error; +use crate::GLApi; use super::device::{Adapter, Device, NativeDevice}; use super::surface::NativeWidget; @@ -46,6 +47,12 @@ impl Connection { NativeConnection } + /// Returns the OpenGL API flavor that this connection supports (OpenGL or OpenGL ES). + #[inline] + pub fn gl_api(&self) -> GLApi { + GLApi::GL + } + /// Returns the "best" adapter on this system, preferring high-performance hardware adapters. /// /// This is an alias for `Connection::create_hardware_adapter()`.