Merge pull request #270 from cmeissl/shm_unpack_subimage_gles3

check for gl version in gles renderer...
This commit is contained in:
Victor Brekenfeld 2021-05-15 20:55:09 +02:00 committed by GitHub
commit a6e7db1344
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 104 additions and 1 deletions

View File

@ -37,6 +37,7 @@ wayland-server = { version = "0.28.3", optional = true }
wayland-sys = { version = "0.28", optional = true } wayland-sys = { version = "0.28", optional = true }
winit = { version = "0.24.0", optional = true } winit = { version = "0.24.0", optional = true }
xkbcommon = "0.4.0" xkbcommon = "0.4.0"
scan_fmt = { version = "0.2", default-features = false }
[dev-dependencies] [dev-dependencies]
slog-term = "2.3" slog-term = "2.3"

View File

@ -10,10 +10,13 @@ use std::sync::{
mpsc::{channel, Receiver, Sender}, mpsc::{channel, Receiver, Sender},
}; };
use std::{collections::HashSet, os::raw::c_char}; use std::{collections::HashSet, os::raw::c_char};
use std::convert::TryFrom;
use cgmath::{prelude::*, Matrix3}; use cgmath::{prelude::*, Matrix3};
mod shaders; mod shaders;
mod version;
use super::{Bind, Renderer, Texture, Transform, Unbind}; use super::{Bind, Renderer, Texture, Transform, Unbind};
use crate::backend::allocator::{ use crate::backend::allocator::{
dmabuf::{Dmabuf, WeakDmabuf}, dmabuf::{Dmabuf, WeakDmabuf},
@ -331,6 +334,11 @@ impl Gles2Renderer {
); );
info!(log, "Supported GL Extensions: {:?}", exts); info!(log, "Supported GL Extensions: {:?}", exts);
let gl_version = version::GlVersion::try_from(&gl).unwrap_or_else(|_| {
warn!(log, "Failed to detect GLES version, defaulting to 2.0");
version::GLES_2_0
});
// required for the manditory wl_shm formats // required for the manditory wl_shm formats
if !exts.iter().any(|ext| ext == "GL_EXT_texture_format_BGRA8888") { if !exts.iter().any(|ext| ext == "GL_EXT_texture_format_BGRA8888") {
return Err(Gles2Error::GLExtensionNotSupported(&[ return Err(Gles2Error::GLExtensionNotSupported(&[
@ -338,7 +346,7 @@ impl Gles2Renderer {
])); ]));
} }
// required for buffers without linear memory layout // required for buffers without linear memory layout
if !exts.iter().any(|ext| ext == "GL_EXT_unpack_subimage") { if gl_version < version::GLES_3_0 && !exts.iter().any(|ext| ext == "GL_EXT_unpack_subimage") {
return Err(Gles2Error::GLExtensionNotSupported(&["GL_EXT_unpack_subimage"])); return Err(Gles2Error::GLExtensionNotSupported(&["GL_EXT_unpack_subimage"]));
} }

View File

@ -0,0 +1,94 @@
use std::{convert::TryFrom, ffi::CStr, os::raw::c_char};
use scan_fmt::scan_fmt;
use super::ffi::{self, Gles2};
pub const GLES_3_0: GlVersion = GlVersion::new(3, 0);
pub const GLES_2_0: GlVersion = GlVersion::new(2, 0);
#[derive(Debug, PartialEq, Clone, Copy)]
pub struct GlVersion {
pub major: i32,
pub minor: i32,
}
impl GlVersion {
pub const fn new(major: i32, minor: i32) -> Self {
GlVersion { major, minor }
}
}
impl Eq for GlVersion {}
impl Ord for GlVersion {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
match self.major.cmp(&other.major) {
std::cmp::Ordering::Equal => self.minor.cmp(&other.minor),
ord => ord,
}
}
}
impl PartialOrd for GlVersion {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl TryFrom<&CStr> for GlVersion {
type Error = scan_fmt::parse::ScanError;
fn try_from(value: &CStr) -> Result<Self, Self::Error> {
scan_fmt!(&value.to_string_lossy(), "{d}.{d}", i32, i32)
.or_else(|_| scan_fmt!(&value.to_string_lossy(), "OpenGL ES {d}.{d}", i32, i32))
.map(|(major, minor)| GlVersion::new(major, minor))
}
}
impl TryFrom<&Gles2> for GlVersion {
type Error = scan_fmt::parse::ScanError;
fn try_from(value: &Gles2) -> Result<Self, Self::Error> {
let version = unsafe { CStr::from_ptr(value.GetString(ffi::VERSION) as *const c_char) };
GlVersion::try_from(version)
}
}
#[cfg(test)]
mod tests {
use super::GlVersion;
use std::{convert::TryFrom, ffi::CStr, os::raw::c_char};
#[test]
fn test_parse_mesa_3_2() {
let gl_version = "OpenGL ES 3.2 Mesa 20.3.5";
let gl_version_str = unsafe { CStr::from_ptr(gl_version.as_ptr() as *const c_char) };
assert_eq!(GlVersion::try_from(gl_version_str), Ok(GlVersion::new(3, 2)))
}
#[test]
fn test_3_2_greater_3_0() {
assert!(GlVersion::new(3, 2) > GlVersion::new(3, 0))
}
#[test]
fn test_3_0_greater_or_equal_3_0() {
assert!(GlVersion::new(3, 0) >= GlVersion::new(3, 0))
}
#[test]
fn test_3_0_less_or_equal_3_0() {
assert!(GlVersion::new(3, 0) <= GlVersion::new(3, 0))
}
#[test]
fn test_3_0_eq_3_0() {
assert!(GlVersion::new(3, 0) == GlVersion::new(3, 0))
}
#[test]
fn test_2_0_less_3_0() {
assert!(GlVersion::new(2, 0) < GlVersion::new(3, 0))
}
}