Check if surface type is matching context type
This commit is contained in:
parent
eef617258e
commit
5155b44946
|
@ -67,6 +67,13 @@ pub enum NativeSurface {
|
||||||
Gbm(ffi::NativeWindowType),
|
Gbm(ffi::NativeWindowType),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(PartialEq)]
|
||||||
|
enum NativeType {
|
||||||
|
X11,
|
||||||
|
Wayland,
|
||||||
|
Gbm,
|
||||||
|
}
|
||||||
|
|
||||||
/// Error that can happen while creating an `EGLContext` or `EGLSurface`
|
/// Error that can happen while creating an `EGLContext` or `EGLSurface`
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum CreationError {
|
pub enum CreationError {
|
||||||
|
@ -78,6 +85,10 @@ pub enum CreationError {
|
||||||
OpenGlVersionNotSupported,
|
OpenGlVersionNotSupported,
|
||||||
/// There is no pixel format available that fulfills all requirements
|
/// There is no pixel format available that fulfills all requirements
|
||||||
NoAvailablePixelFormat,
|
NoAvailablePixelFormat,
|
||||||
|
/// Surface creation from an unsupport combination
|
||||||
|
///
|
||||||
|
/// E.g creating a surface from an X11 window on a context created from a wayland display
|
||||||
|
NonMatchingSurfaceType,
|
||||||
/// Context creation is not supported on this system
|
/// Context creation is not supported on this system
|
||||||
NotSupported,
|
NotSupported,
|
||||||
}
|
}
|
||||||
|
@ -106,10 +117,13 @@ impl error::Error for CreationError {
|
||||||
CreationError::OpenGlVersionNotSupported => {
|
CreationError::OpenGlVersionNotSupported => {
|
||||||
"The requested OpenGL version is not \
|
"The requested OpenGL version is not \
|
||||||
supported."
|
supported."
|
||||||
}
|
},
|
||||||
CreationError::NoAvailablePixelFormat => {
|
CreationError::NoAvailablePixelFormat => {
|
||||||
"Couldn't find any pixel format that matches \
|
"Couldn't find any pixel format that matches \
|
||||||
the criterias."
|
the criterias."
|
||||||
|
},
|
||||||
|
CreationError::NonMatchingSurfaceType => {
|
||||||
|
"Surface type does not match the context type."
|
||||||
}
|
}
|
||||||
CreationError::NotSupported => "Context creation is not supported on the current window system",
|
CreationError::NotSupported => "Context creation is not supported on the current window system",
|
||||||
}
|
}
|
||||||
|
@ -132,6 +146,7 @@ pub struct EGLContext {
|
||||||
config_id: ffi::egl::types::EGLConfig,
|
config_id: ffi::egl::types::EGLConfig,
|
||||||
surface_attributes: Vec<c_int>,
|
surface_attributes: Vec<c_int>,
|
||||||
pixel_format: PixelFormat,
|
pixel_format: PixelFormat,
|
||||||
|
backend_type: NativeType,
|
||||||
logger: slog::Logger,
|
logger: slog::Logger,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,6 +550,11 @@ impl EGLContext {
|
||||||
config_id: config_id,
|
config_id: config_id,
|
||||||
surface_attributes: surface_attributes,
|
surface_attributes: surface_attributes,
|
||||||
pixel_format: desc,
|
pixel_format: desc,
|
||||||
|
backend_type: match native {
|
||||||
|
NativeDisplay::X11(_) => NativeType::X11,
|
||||||
|
NativeDisplay::Wayland(_) => NativeType::Wayland,
|
||||||
|
NativeDisplay::Gbm(_) => NativeType::Gbm,
|
||||||
|
},
|
||||||
logger: log,
|
logger: log,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -549,6 +569,14 @@ impl EGLContext {
|
||||||
-> Result<EGLSurface<'a>, CreationError> {
|
-> Result<EGLSurface<'a>, CreationError> {
|
||||||
trace!(self.logger, "Creating EGL window surface...");
|
trace!(self.logger, "Creating EGL window surface...");
|
||||||
|
|
||||||
|
match native {
|
||||||
|
NativeSurface::X11(_) if self.backend_type != NativeType::X11 => return Err(CreationError::NonMatchingSurfaceType),
|
||||||
|
NativeSurface::Wayland(_) if self.backend_type != NativeType::Wayland => return Err(CreationError::NonMatchingSurfaceType),
|
||||||
|
NativeSurface::Gbm(_) if self.backend_type != NativeType::Gbm =>
|
||||||
|
return Err(CreationError::NonMatchingSurfaceType),
|
||||||
|
_ => {},
|
||||||
|
};
|
||||||
|
|
||||||
let surface = {
|
let surface = {
|
||||||
let surface = match native {
|
let surface = match native {
|
||||||
NativeSurface::X11(window) |
|
NativeSurface::X11(window) |
|
||||||
|
|
Loading…
Reference in New Issue