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:
parent
45e29b4891
commit
0f1b8353d0
|
@ -14,6 +14,10 @@ authors = [
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
|
|
||||||
|
[features]
|
||||||
|
default = ["opengl"]
|
||||||
|
opengl = ["uuid"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
keyboard-types = { version = "0.6.1", default-features = false }
|
keyboard-types = { version = "0.6.1", default-features = false }
|
||||||
raw-window-handle = "0.4.2"
|
raw-window-handle = "0.4.2"
|
||||||
|
@ -26,6 +30,7 @@ nix = "0.22.0"
|
||||||
|
|
||||||
[target.'cfg(target_os="windows")'.dependencies]
|
[target.'cfg(target_os="windows")'.dependencies]
|
||||||
winapi = { version = "0.3.8", features = ["libloaderapi", "winuser", "windef", "minwindef", "guiddef", "combaseapi", "wingdi", "errhandlingapi"] }
|
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]
|
[target.'cfg(target_os="macos")'.dependencies]
|
||||||
cocoa = "0.24.0"
|
cocoa = "0.24.0"
|
||||||
|
|
|
@ -18,7 +18,7 @@ use core_foundation::string::CFString;
|
||||||
|
|
||||||
use objc::{msg_send, sel, sel_impl};
|
use objc::{msg_send, sel, sel_impl};
|
||||||
|
|
||||||
use crate::{GlConfig, GlError, Profile};
|
use super::{GlConfig, GlError, Profile};
|
||||||
|
|
||||||
pub type CreationFailedError = ();
|
pub type CreationFailedError = ();
|
||||||
pub struct GlContext {
|
pub struct GlContext {
|
||||||
|
@ -28,10 +28,9 @@ pub struct GlContext {
|
||||||
|
|
||||||
impl GlContext {
|
impl GlContext {
|
||||||
pub unsafe fn create(
|
pub unsafe fn create(
|
||||||
parent: &impl HasRawWindowHandle,
|
parent: &impl HasRawWindowHandle, config: GlConfig,
|
||||||
config: GlConfig,
|
|
||||||
) -> Result<GlContext, GlError> {
|
) -> 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
|
handle
|
||||||
} else {
|
} else {
|
||||||
return Err(GlError::InvalidWindowHandle);
|
return Err(GlError::InvalidWindowHandle);
|
||||||
|
|
|
@ -11,7 +11,7 @@ use win as platform;
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
mod x11;
|
mod x11;
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
use crate::x11 as platform;
|
use self::x11 as platform;
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
mod macos;
|
mod macos;
|
||||||
|
@ -73,13 +73,10 @@ pub struct GlContext {
|
||||||
|
|
||||||
impl GlContext {
|
impl GlContext {
|
||||||
pub unsafe fn create(
|
pub unsafe fn create(
|
||||||
parent: &impl HasRawWindowHandle,
|
parent: &impl HasRawWindowHandle, config: GlConfig,
|
||||||
config: GlConfig,
|
|
||||||
) -> Result<GlContext, GlError> {
|
) -> Result<GlContext, GlError> {
|
||||||
platform::GlContext::create(parent, config).map(|context| GlContext {
|
platform::GlContext::create(parent, config)
|
||||||
context,
|
.map(|context| GlContext { context, phantom: PhantomData })
|
||||||
phantom: PhantomData,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn make_current(&self) {
|
pub unsafe fn make_current(&self) {
|
|
@ -18,7 +18,7 @@ use winapi::um::winuser::{
|
||||||
UnregisterClassW, CS_OWNDC, CW_USEDEFAULT, WNDCLASSW,
|
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
|
// See https://www.khronos.org/registry/OpenGL/extensions/ARB/WGL_ARB_create_context.txt
|
||||||
|
|
||||||
|
@ -78,10 +78,9 @@ extern "C" {
|
||||||
|
|
||||||
impl GlContext {
|
impl GlContext {
|
||||||
pub unsafe fn create(
|
pub unsafe fn create(
|
||||||
parent: &impl HasRawWindowHandle,
|
parent: &impl HasRawWindowHandle, config: GlConfig,
|
||||||
config: GlConfig,
|
|
||||||
) -> Result<GlContext, GlError> {
|
) -> 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
|
handle
|
||||||
} else {
|
} else {
|
||||||
return Err(GlError::InvalidWindowHandle);
|
return Err(GlError::InvalidWindowHandle);
|
||||||
|
@ -267,12 +266,7 @@ impl GlContext {
|
||||||
wglSwapIntervalEXT.unwrap()(config.vsync as i32);
|
wglSwapIntervalEXT.unwrap()(config.vsync as i32);
|
||||||
wglMakeCurrent(hdc, std::ptr::null_mut());
|
wglMakeCurrent(hdc, std::ptr::null_mut());
|
||||||
|
|
||||||
Ok(GlContext {
|
Ok(GlContext { hwnd, hdc, hglrc, gl_library })
|
||||||
hwnd,
|
|
||||||
hdc,
|
|
||||||
hglrc,
|
|
||||||
gl_library,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn make_current(&self) {
|
pub unsafe fn make_current(&self) {
|
||||||
|
|
|
@ -6,7 +6,7 @@ use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
|
||||||
use x11::glx;
|
use x11::glx;
|
||||||
use x11::xlib;
|
use x11::xlib;
|
||||||
|
|
||||||
use crate::{GlConfig, GlError, Profile};
|
use super::{GlConfig, GlError, Profile};
|
||||||
|
|
||||||
mod errors;
|
mod errors;
|
||||||
|
|
||||||
|
@ -57,8 +57,7 @@ pub struct GlContext {
|
||||||
|
|
||||||
impl GlContext {
|
impl GlContext {
|
||||||
pub unsafe fn create(
|
pub unsafe fn create(
|
||||||
parent: &impl HasRawWindowHandle,
|
parent: &impl HasRawWindowHandle, config: GlConfig,
|
||||||
config: GlConfig,
|
|
||||||
) -> Result<GlContext, GlError> {
|
) -> Result<GlContext, GlError> {
|
||||||
let handle = if let RawWindowHandle::Xlib(handle) = parent.raw_window_handle() {
|
let handle = if let RawWindowHandle::Xlib(handle) = parent.raw_window_handle() {
|
||||||
handle
|
handle
|
||||||
|
@ -102,18 +101,14 @@ impl GlContext {
|
||||||
error_handler.check()?;
|
error_handler.check()?;
|
||||||
|
|
||||||
if n_configs <= 0 {
|
if n_configs <= 0 {
|
||||||
return Err(GlError::CreationFailed(
|
return Err(GlError::CreationFailed(CreationFailedError::InvalidFBConfig));
|
||||||
CreationFailedError::InvalidFBConfig,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
let glXCreateContextAttribsARB: GlXCreateContextAttribsARB = unsafe {
|
let glXCreateContextAttribsARB: GlXCreateContextAttribsARB = unsafe {
|
||||||
let addr = get_proc_address("glXCreateContextAttribsARB");
|
let addr = get_proc_address("glXCreateContextAttribsARB");
|
||||||
if addr.is_null() {
|
if addr.is_null() {
|
||||||
return Err(GlError::CreationFailed(
|
return Err(GlError::CreationFailed(CreationFailedError::GetProcAddressFailed));
|
||||||
CreationFailedError::GetProcAddressFailed,
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
std::mem::transmute(addr)
|
std::mem::transmute(addr)
|
||||||
}
|
}
|
||||||
|
@ -123,9 +118,7 @@ impl GlContext {
|
||||||
let glXSwapIntervalEXT: GlXSwapIntervalEXT = unsafe {
|
let glXSwapIntervalEXT: GlXSwapIntervalEXT = unsafe {
|
||||||
let addr = get_proc_address("glXSwapIntervalEXT");
|
let addr = get_proc_address("glXSwapIntervalEXT");
|
||||||
if addr.is_null() {
|
if addr.is_null() {
|
||||||
return Err(GlError::CreationFailed(
|
return Err(GlError::CreationFailed(CreationFailedError::GetProcAddressFailed));
|
||||||
CreationFailedError::GetProcAddressFailed,
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
std::mem::transmute(addr)
|
std::mem::transmute(addr)
|
||||||
}
|
}
|
||||||
|
@ -159,18 +152,14 @@ impl GlContext {
|
||||||
error_handler.check()?;
|
error_handler.check()?;
|
||||||
|
|
||||||
if context.is_null() {
|
if context.is_null() {
|
||||||
return Err(GlError::CreationFailed(
|
return Err(GlError::CreationFailed(CreationFailedError::ContextCreationFailed));
|
||||||
CreationFailedError::ContextCreationFailed,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let res = glx::glXMakeCurrent(display, handle.window, context);
|
let res = glx::glXMakeCurrent(display, handle.window, context);
|
||||||
error_handler.check()?;
|
error_handler.check()?;
|
||||||
if res == 0 {
|
if res == 0 {
|
||||||
return Err(GlError::CreationFailed(
|
return Err(GlError::CreationFailed(CreationFailedError::MakeCurrentFailed));
|
||||||
CreationFailedError::MakeCurrentFailed,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glXSwapIntervalEXT(display, handle.window, config.vsync as i32);
|
glXSwapIntervalEXT(display, handle.window, config.vsync as i32);
|
||||||
|
@ -178,17 +167,11 @@ impl GlContext {
|
||||||
|
|
||||||
if glx::glXMakeCurrent(display, 0, std::ptr::null_mut()) == 0 {
|
if glx::glXMakeCurrent(display, 0, std::ptr::null_mut()) == 0 {
|
||||||
error_handler.check()?;
|
error_handler.check()?;
|
||||||
return Err(GlError::CreationFailed(
|
return Err(GlError::CreationFailed(CreationFailedError::MakeCurrentFailed));
|
||||||
CreationFailedError::MakeCurrentFailed,
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(GlContext {
|
Ok(GlContext { window: handle.window, display, context })
|
||||||
window: handle.window,
|
|
||||||
display,
|
|
||||||
context,
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,9 @@ mod window;
|
||||||
mod window_info;
|
mod window_info;
|
||||||
mod window_open_options;
|
mod window_open_options;
|
||||||
|
|
||||||
|
#[cfg(feature = "opengl")]
|
||||||
|
pub mod gl;
|
||||||
|
|
||||||
pub use event::*;
|
pub use event::*;
|
||||||
pub use mouse_cursor::MouseCursor;
|
pub use mouse_cursor::MouseCursor;
|
||||||
pub use window::*;
|
pub use window::*;
|
||||||
|
|
Loading…
Reference in a new issue