switch to safer api using HasRawWindowHandle

This commit is contained in:
Micah Johnston
2020-12-12 20:11:47 -06:00
parent d2f3109b2b
commit d143c42200
5 changed files with 11 additions and 9 deletions

View File

@@ -37,7 +37,7 @@ fn main() {
};
Window::open_blocking(window_open_options, |window| {
let context = GlContext::create(window.raw_window_handle()).unwrap();
let context = GlContext::create(window).unwrap();
context.make_current();
gl::load_with(|symbol| context.get_proc_address(symbol) as *const _);

View File

@@ -9,7 +9,7 @@ fn main() {
let event_loop = EventLoop::new();
let window = WindowBuilder::new().build(&event_loop).unwrap();
let context = GlContext::create(window.raw_window_handle()).unwrap();
let context = GlContext::create(&window).unwrap();
context.make_current();

View File

@@ -1,7 +1,9 @@
use raw_window_handle::HasRawWindowHandle;
pub struct GlContext {}
impl GlContext {
pub fn create(raw_window_handle: raw_window_handle::RawWindowHandle) -> GlContext {
pub fn create(parent: &impl HasRawWindowHandle) -> GlContext {
GlContext {}
}
}

View File

@@ -1,6 +1,6 @@
use std::ffi::{c_void, CString};
use raw_window_handle::RawWindowHandle;
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use winapi::shared::minwindef::HMODULE;
use winapi::shared::windef::{HDC, HGLRC, HWND};
@@ -20,8 +20,8 @@ pub struct GlContext {
}
impl GlContext {
pub fn create(raw_window_handle: RawWindowHandle) -> Result<GlContext, ()> {
let handle = if let RawWindowHandle::Windows(handle) = raw_window_handle {
pub fn create(parent: &impl HasRawWindowHandle) -> Result<GlContext, ()> {
let handle = if let RawWindowHandle::Windows(handle) = parent.raw_window_handle() {
handle
} else {
return Err(());

View File

@@ -1,7 +1,7 @@
use std::ffi::{c_void, CString};
use std::os::raw::{c_int, c_ulong};
use raw_window_handle::RawWindowHandle;
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use x11::glx;
use x11::xlib;
@@ -26,8 +26,8 @@ pub struct GlContext {
}
impl GlContext {
pub fn create(raw_window_handle: RawWindowHandle) -> Result<GlContext, ()> {
let handle = if let RawWindowHandle::Xlib(handle) = raw_window_handle {
pub fn create(parent: &impl HasRawWindowHandle) -> Result<GlContext, ()> {
let handle = if let RawWindowHandle::Xlib(handle) = parent.raw_window_handle() {
handle
} else {
return Err(());