switch to safer api using HasRawWindowHandle
This commit is contained in:
@@ -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 _);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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 {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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(());
|
||||
|
||||
@@ -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(());
|
||||
|
||||
Reference in New Issue
Block a user