Swapchain exposed on Rust side

This commit is contained in:
Dzmitry Malyshau committed 2019-01-16 09:15:56 -05:00
1 parent 90154fb6f5
commit e32112a89a
5 files changed
+59 -7

No files matched your search

+8 -1
View File
@@ -50,7 +50,14 @@ pub extern "C" fn wgpu_create_instance() -> InstanceId {
}
}
#[cfg(not(feature = "remote"))]
#[cfg(all(
not(feature = "remote"),
any(
feature = "gfx-backend-vulkan",
feature = "gfx-backend-dx12",
feature = "gfx-backend-metal"
)
))]
#[no_mangle]
pub extern "C" fn wgpu_instance_create_surface_from_winit(
instance_id: InstanceId,
+1 -1
View File
@@ -1,5 +1,5 @@
#[cfg(not(feature = "remote"))]
extern crate winit;
pub extern crate winit;
#[cfg(feature = "gfx-backend-dx12")]
extern crate gfx_backend_dx12 as back;
+11 -2
View File
@@ -52,10 +52,16 @@ pub struct SwapChainDescriptor {
pub height: u32,
}
#[repr(C)]
pub struct SwapChainOutput {
pub texture_id: TextureId,
pub view_id: TextureViewId,
}
#[no_mangle]
pub extern "C" fn wgpu_swap_chain_get_next_texture(
swap_chain_id: SwapChainId,
) -> TextureId {
) -> SwapChainOutput {
let mut swap_chain_guard = HUB.swap_chains.write();
let swap_chain = swap_chain_guard.get_mut(swap_chain_id);
let device_guard = HUB.devices.read();
@@ -81,7 +87,10 @@ pub extern "C" fn wgpu_swap_chain_get_next_texture(
None => unreachable!(),
}
frame.texture_id.value
SwapChainOutput {
texture_id: frame.texture_id.value,
view_id: frame.view_id.value,
}
}
#[no_mangle]
+4 -3
View File
@@ -11,9 +11,10 @@ edition = "2018"
[features]
default = []
metal = ["wgpu-native/gfx-backend-metal"]
dx12 = ["wgpu-native/gfx-backend-dx12"]
vulkan = ["wgpu-native/gfx-backend-vulkan"]
backed = []
metal = ["wgpu-native/gfx-backend-metal", "backed"]
dx12 = ["wgpu-native/gfx-backend-dx12", "backed"]
vulkan = ["wgpu-native/gfx-backend-vulkan", "backed"]
[dependencies]
wgpu-native = { path = "../wgpu-native" }
+35
View File
@@ -13,6 +13,7 @@ pub use wgn::{
RenderPassColorAttachmentDescriptor, RenderPassDepthStencilAttachmentDescriptor,
RenderPassDescriptor, ShaderModuleDescriptor, ShaderStage, ShaderStageFlags, StoreOp,
TextureDescriptor, TextureDimension, TextureFormat, TextureUsageFlags, TextureViewDescriptor,
SwapChainDescriptor,
};
pub struct Instance {
@@ -35,6 +36,14 @@ pub struct TextureView {
id: wgn::TextureViewId,
}
pub struct Surface {
id: wgn::SurfaceId,
}
pub struct SwapChain {
id: wgn::SwapChainId,
}
pub struct BindGroupLayout {
id: wgn::BindGroupLayoutId,
}
@@ -125,6 +134,13 @@ impl Instance {
id: wgn::wgpu_instance_get_adapter(self.id, desc),
}
}
#[cfg(feature = "backed")]
pub fn create_surface(&self, window: &::winit::Window) -> Surface {
Surface {
id: wgn::wgpu_instance_create_surface_from_winit(self.id, window)
}
}
}
impl Adapter {
@@ -148,6 +164,7 @@ impl Device {
}
}
//TODO: borrow instead of new object?
pub fn get_queue(&self) -> Queue {
Queue {
id: wgn::wgpu_device_get_queue(self.id),
@@ -255,6 +272,12 @@ impl Device {
id: wgn::wgpu_device_create_texture(self.id, &desc),
}
}
pub fn create_swap_chain(&self, surface: &Surface, desc: &SwapChainDescriptor) -> SwapChain {
SwapChain {
id: wgn::wgpu_device_create_swap_chain(self.id, surface.id, desc),
}
}
}
impl Texture {
@@ -351,3 +374,15 @@ impl Queue {
);
}
}
impl SwapChain {
//TODO: borrow instead of new object?
pub fn get_next_texture(&self) -> (Texture, TextureView) {
let output = wgn::wgpu_swap_chain_get_next_texture(self.id);
(Texture { id: output.texture_id} , TextureView { id: output.view_id })
}
pub fn present(&self) {
wgn::wgpu_swap_chain_present(self.id);
}
}