1
0
Fork 0

Fix X11 OpenGL issue

This commit is contained in:
Joakim Frostegård 2022-11-23 23:52:19 +01:00 committed by Robbert van der Helm
parent 6f32584149
commit 10c970a329
2 changed files with 10 additions and 23 deletions

View file

@ -1,8 +1,6 @@
use std::ffi::{c_void, CString};
use std::os::raw::{c_int, c_ulong};
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use x11::glx;
use x11::xlib;
@ -80,19 +78,13 @@ impl GlContext {
///
/// Use [Self::get_fb_config_and_visual] to create both of these things.
pub unsafe fn create(
parent: &impl HasRawWindowHandle, config: FbConfig,
window: c_ulong, display: *mut c_void, config: FbConfig,
) -> Result<GlContext, GlError> {
let handle = if let RawWindowHandle::Xlib(handle) = parent.raw_window_handle() {
handle
} else {
return Err(GlError::InvalidWindowHandle);
};
if handle.display.is_null() {
if display.is_null() {
return Err(GlError::InvalidWindowHandle);
}
let display = handle.display as *mut xlib::_XDisplay;
let display = display as *mut xlib::_XDisplay;
errors::XErrorHandler::handle(display, |error_handler| {
#[allow(non_snake_case)]
@ -144,13 +136,13 @@ impl GlContext {
return Err(GlError::CreationFailed(CreationFailedError::ContextCreationFailed));
}
let res = glx::glXMakeCurrent(display, handle.window, context);
let res = glx::glXMakeCurrent(display, window, context);
error_handler.check()?;
if res == 0 {
return Err(GlError::CreationFailed(CreationFailedError::MakeCurrentFailed));
}
glXSwapIntervalEXT(display, handle.window, config.gl_config.vsync as i32);
glXSwapIntervalEXT(display, window, config.gl_config.vsync as i32);
error_handler.check()?;
if glx::glXMakeCurrent(display, 0, std::ptr::null_mut()) == 0 {
@ -158,7 +150,7 @@ impl GlContext {
return Err(GlError::CreationFailed(CreationFailedError::MakeCurrentFailed));
}
Ok(GlContext { window: handle.window, display, context })
Ok(GlContext { window, display, context })
})
}

View file

@ -22,10 +22,7 @@ use crate::{
use super::keyboard::{convert_key_press_event, convert_key_release_event, key_mods};
#[cfg(feature = "opengl")]
use crate::{
gl::{platform, GlContext},
window::RawWindowHandleWrapper,
};
use crate::gl::{platform, GlContext};
pub struct WindowHandle {
raw_window_handle: Option<RawWindowHandle>,
@ -326,13 +323,11 @@ impl Window {
// compared to when raw-gl-context was a separate crate.
#[cfg(feature = "opengl")]
let gl_context = fb_config.map(|fb_config| {
let mut handle = XlibWindowHandle::empty();
handle.window = window_id as c_ulong;
handle.display = xcb_connection.conn.get_raw_dpy() as *mut c_void;
let handle = RawWindowHandleWrapper { handle: RawWindowHandle::Xlib(handle) };
let window = window_id as c_ulong;
let display = xcb_connection.conn.get_raw_dpy() as *mut c_void;
// Because of the visual negotation we had to take some extra steps to create this context
let context = unsafe { platform::GlContext::create(&handle, fb_config) }
let context = unsafe { platform::GlContext::create(window, display, fb_config) }
.expect("Could not create OpenGL context");
GlContext::new(context)
});