move the GPU initialization out of the bridge
This commit is contained in:
parent
f27dcdbfa4
commit
ea8b3c92a1
42
src/lib.rs
42
src/lib.rs
|
|
@ -1,6 +1,7 @@
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
use glam::{Mat4, UVec2, Vec3, Vec4, vec3, vec4};
|
use glam::{Mat4, UVec2, Vec3, Vec4, vec3, vec4};
|
||||||
|
use wgpu::rwh::{RawDisplayHandle, RawWindowHandle};
|
||||||
|
|
||||||
pub use crate::ffi::RedrawArgs;
|
pub use crate::ffi::RedrawArgs;
|
||||||
|
|
||||||
|
|
@ -246,27 +247,11 @@ pub async fn init_gpu_inner<E: Error + 'static>(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[diplomat::bridge]
|
impl Gpu {
|
||||||
mod ffi {
|
unsafe fn new_raw(
|
||||||
use std::{num::NonZero, ptr::NonNull};
|
|
||||||
|
|
||||||
use crate::{Gpu, init_gpu_inner};
|
|
||||||
use glam::uvec2;
|
|
||||||
use wgpu::rwh::{RawDisplayHandle, RawWindowHandle, XcbDisplayHandle, XcbWindowHandle};
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
#[repr(C)]
|
|
||||||
pub struct RedrawArgs {
|
|
||||||
pub cam_yaw: f32,
|
|
||||||
pub cam_pitch: f32,
|
|
||||||
pub cam_distance: f32,
|
|
||||||
pub cam_fovy: f32,
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe fn create_gpu(
|
|
||||||
display: impl Into<RawDisplayHandle>,
|
display: impl Into<RawDisplayHandle>,
|
||||||
window: impl Into<RawWindowHandle>,
|
window: impl Into<RawWindowHandle>,
|
||||||
) -> Gpu {
|
) -> Self {
|
||||||
let target = wgpu::SurfaceTargetUnsafe::RawHandle {
|
let target = wgpu::SurfaceTargetUnsafe::RawHandle {
|
||||||
raw_display_handle: display.into(),
|
raw_display_handle: display.into(),
|
||||||
raw_window_handle: window.into(),
|
raw_window_handle: window.into(),
|
||||||
|
|
@ -277,6 +262,23 @@ mod ffi {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
gpu
|
gpu
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[diplomat::bridge]
|
||||||
|
mod ffi {
|
||||||
|
use std::{num::NonZero, ptr::NonNull};
|
||||||
|
|
||||||
|
use glam::uvec2;
|
||||||
|
use wgpu::rwh::{XcbDisplayHandle, XcbWindowHandle};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct RedrawArgs {
|
||||||
|
pub cam_yaw: f32,
|
||||||
|
pub cam_pitch: f32,
|
||||||
|
pub cam_distance: f32,
|
||||||
|
pub cam_fovy: f32,
|
||||||
|
}
|
||||||
|
|
||||||
#[diplomat::opaque_mut]
|
#[diplomat::opaque_mut]
|
||||||
pub struct Core(crate::Core);
|
pub struct Core(crate::Core);
|
||||||
|
|
@ -286,7 +288,7 @@ mod ffi {
|
||||||
let display =
|
let display =
|
||||||
XcbDisplayHandle::new(Some(NonNull::new(connection as *mut _).unwrap()), 0);
|
XcbDisplayHandle::new(Some(NonNull::new(connection as *mut _).unwrap()), 0);
|
||||||
let window = XcbWindowHandle::new(NonZero::new(window).unwrap());
|
let window = XcbWindowHandle::new(NonZero::new(window).unwrap());
|
||||||
let gpu = unsafe { create_gpu(display, window) };
|
let gpu = unsafe { crate::Gpu::new_raw(display, window) };
|
||||||
let size = uvec2(width, height);
|
let size = uvec2(width, height);
|
||||||
Box::new(Self(crate::Core::new(gpu, size)))
|
Box::new(Self(crate::Core::new(gpu, size)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user