1
0
Fork 0

Patch up the raw-gl-context modules for a feature

This only needed a couple changes for the raw-window-handle migration,
and for the different module paths.
This commit is contained in:
Robbert van der Helm 2022-02-07 17:31:19 +01:00
parent 45e29b4891
commit 0f1b8353d0
6 changed files with 28 additions and 47 deletions

View file

@ -14,6 +14,10 @@ authors = [
edition = "2018"
license = "MIT OR Apache-2.0"
[features]
default = ["opengl"]
opengl = ["uuid"]
[dependencies]
keyboard-types = { version = "0.6.1", default-features = false }
raw-window-handle = "0.4.2"
@ -26,6 +30,7 @@ nix = "0.22.0"
[target.'cfg(target_os="windows")'.dependencies]
winapi = { version = "0.3.8", features = ["libloaderapi", "winuser", "windef", "minwindef", "guiddef", "combaseapi", "wingdi", "errhandlingapi"] }
uuid = { version = "0.8", features = ["v4"], optional = true }
[target.'cfg(target_os="macos")'.dependencies]
cocoa = "0.24.0"

View file

@ -18,7 +18,7 @@ use core_foundation::string::CFString;
use objc::{msg_send, sel, sel_impl};
use crate::{GlConfig, GlError, Profile};
use super::{GlConfig, GlError, Profile};
pub type CreationFailedError = ();
pub struct GlContext {
@ -28,10 +28,9 @@ pub struct GlContext {
impl GlContext {
pub unsafe fn create(
parent: &impl HasRawWindowHandle,
config: GlConfig,
parent: &impl HasRawWindowHandle, config: GlConfig,
) -> Result<GlContext, GlError> {
let handle = if let RawWindowHandle::MacOS(handle) = parent.raw_window_handle() {
let handle = if let RawWindowHandle::AppKit(handle) = parent.raw_window_handle() {
handle
} else {
return Err(GlError::InvalidWindowHandle);

View file

@ -11,7 +11,7 @@ use win as platform;
#[cfg(target_os = "linux")]
mod x11;
#[cfg(target_os = "linux")]
use crate::x11 as platform;
use self::x11 as platform;
#[cfg(target_os = "macos")]
mod macos;
@ -73,13 +73,10 @@ pub struct GlContext {
impl GlContext {
pub unsafe fn create(
parent: &impl HasRawWindowHandle,
config: GlConfig,
parent: &impl HasRawWindowHandle, config: GlConfig,
) -> Result<GlContext, GlError> {
platform::GlContext::create(parent, config).map(|context| GlContext {
context,
phantom: PhantomData,
})
platform::GlContext::create(parent, config)
.map(|context| GlContext { context, phantom: PhantomData })
}
pub unsafe fn make_current(&self) {

View file

@ -18,7 +18,7 @@ use winapi::um::winuser::{
UnregisterClassW, CS_OWNDC, CW_USEDEFAULT, WNDCLASSW,
};
use crate::{GlConfig, GlError, Profile};
use super::{GlConfig, GlError, Profile};
// See https://www.khronos.org/registry/OpenGL/extensions/ARB/WGL_ARB_create_context.txt
@ -78,10 +78,9 @@ extern "C" {
impl GlContext {
pub unsafe fn create(
parent: &impl HasRawWindowHandle,
config: GlConfig,
parent: &impl HasRawWindowHandle, config: GlConfig,
) -> Result<GlContext, GlError> {
let handle = if let RawWindowHandle::Windows(handle) = parent.raw_window_handle() {
let handle = if let RawWindowHandle::Win32(handle) = parent.raw_window_handle() {
handle
} else {
return Err(GlError::InvalidWindowHandle);
@ -267,12 +266,7 @@ impl GlContext {
wglSwapIntervalEXT.unwrap()(config.vsync as i32);
wglMakeCurrent(hdc, std::ptr::null_mut());
Ok(GlContext {
hwnd,
hdc,
hglrc,
gl_library,
})
Ok(GlContext { hwnd, hdc, hglrc, gl_library })
}
pub unsafe fn make_current(&self) {

View file

@ -6,7 +6,7 @@ use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use x11::glx;
use x11::xlib;
use crate::{GlConfig, GlError, Profile};
use super::{GlConfig, GlError, Profile};
mod errors;
@ -57,8 +57,7 @@ pub struct GlContext {
impl GlContext {
pub unsafe fn create(
parent: &impl HasRawWindowHandle,
config: GlConfig,
parent: &impl HasRawWindowHandle, config: GlConfig,
) -> Result<GlContext, GlError> {
let handle = if let RawWindowHandle::Xlib(handle) = parent.raw_window_handle() {
handle
@ -102,18 +101,14 @@ impl GlContext {
error_handler.check()?;
if n_configs <= 0 {
return Err(GlError::CreationFailed(
CreationFailedError::InvalidFBConfig,
));
return Err(GlError::CreationFailed(CreationFailedError::InvalidFBConfig));
}
#[allow(non_snake_case)]
let glXCreateContextAttribsARB: GlXCreateContextAttribsARB = unsafe {
let addr = get_proc_address("glXCreateContextAttribsARB");
if addr.is_null() {
return Err(GlError::CreationFailed(
CreationFailedError::GetProcAddressFailed,
));
return Err(GlError::CreationFailed(CreationFailedError::GetProcAddressFailed));
} else {
std::mem::transmute(addr)
}
@ -123,9 +118,7 @@ impl GlContext {
let glXSwapIntervalEXT: GlXSwapIntervalEXT = unsafe {
let addr = get_proc_address("glXSwapIntervalEXT");
if addr.is_null() {
return Err(GlError::CreationFailed(
CreationFailedError::GetProcAddressFailed,
));
return Err(GlError::CreationFailed(CreationFailedError::GetProcAddressFailed));
} else {
std::mem::transmute(addr)
}
@ -159,18 +152,14 @@ impl GlContext {
error_handler.check()?;
if context.is_null() {
return Err(GlError::CreationFailed(
CreationFailedError::ContextCreationFailed,
));
return Err(GlError::CreationFailed(CreationFailedError::ContextCreationFailed));
}
unsafe {
let res = glx::glXMakeCurrent(display, handle.window, context);
error_handler.check()?;
if res == 0 {
return Err(GlError::CreationFailed(
CreationFailedError::MakeCurrentFailed,
));
return Err(GlError::CreationFailed(CreationFailedError::MakeCurrentFailed));
}
glXSwapIntervalEXT(display, handle.window, config.vsync as i32);
@ -178,17 +167,11 @@ impl GlContext {
if glx::glXMakeCurrent(display, 0, std::ptr::null_mut()) == 0 {
error_handler.check()?;
return Err(GlError::CreationFailed(
CreationFailedError::MakeCurrentFailed,
));
return Err(GlError::CreationFailed(CreationFailedError::MakeCurrentFailed));
}
}
Ok(GlContext {
window: handle.window,
display,
context,
})
Ok(GlContext { window: handle.window, display, context })
})
}

View file

@ -12,6 +12,9 @@ mod window;
mod window_info;
mod window_open_options;
#[cfg(feature = "opengl")]
pub mod gl;
pub use event::*;
pub use mouse_cursor::MouseCursor;
pub use window::*;