First bits of wgpu-rs

This commit is contained in:
Dzmitry Malyshau 2018-09-26 10:54:09 -04:00
parent fc3b6fc3cb
commit 53c75d6aed
6 changed files with 90 additions and 6 deletions

7
Cargo.lock generated
View File

@ -908,6 +908,13 @@ dependencies = [
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "wgpu"
version = "0.1.0"
dependencies = [
"wgpu-native 0.1.0",
]
[[package]]
name = "wgpu-bindings"
version = "0.1.0"

View File

@ -2,5 +2,6 @@
members = [
"wgpu-native",
"wgpu-bindings",
"wgpu-rs",
"examples",
]

View File

@ -14,9 +14,9 @@ path = "hello_triangle_rust/main.rs"
[features]
default = []
remote = ["wgpu-native/remote"]
metal = ["wgpu-native/metal"]
dx12 = ["wgpu-native/dx12"]
vulkan = ["wgpu-native/vulkan"]
metal = ["wgpu-native/gfx-backend-metal"]
dx12 = ["wgpu-native/gfx-backend-dx12"]
vulkan = ["wgpu-native/gfx-backend-vulkan"]
[dependencies]
wgpu-native = { path = "../wgpu-native" }

View File

@ -12,9 +12,6 @@ crate-type = ["lib", "cdylib", "staticlib"]
[features]
default = []
remote = ["parking_lot"]
metal = ["gfx-backend-metal"]
dx12 = ["gfx-backend-dx12"]
vulkan = ["gfx-backend-vulkan"]
[dependencies]
bitflags = "1.0"

18
wgpu-rs/Cargo.toml Normal file
View File

@ -0,0 +1,18 @@
[package]
name = "wgpu"
version = "0.1.0"
authors = [
"Dzmitry Malyshau <kvark@mozilla.com>",
"Joshua Groves <josh@joshgroves.com>",
]
[lib]
[features]
default = []
metal = ["wgpu-native/gfx-backend-metal"]
dx12 = ["wgpu-native/gfx-backend-dx12"]
vulkan = ["wgpu-native/gfx-backend-vulkan"]
[dependencies]
wgpu-native = { path = "../wgpu-native" }

61
wgpu-rs/src/lib.rs Normal file
View File

@ -0,0 +1,61 @@
extern crate wgpu_native as wgn;
pub use wgn::{
Color, Origin3d, Extent3d,
AdapterDescriptor, Extensions, DeviceDescriptor,
ShaderModuleDescriptor,
};
pub struct Instance {
id: wgn::InstanceId,
}
pub struct Adapter {
id: wgn::AdapterId,
}
pub struct Device {
id: wgn::DeviceId,
}
pub struct ShaderModule {
id: wgn::ShaderModuleId,
}
impl Instance {
pub fn new() -> Self {
Instance {
id: wgn::wgpu_create_instance(),
}
}
pub fn get_adapter(&self, desc: AdapterDescriptor) -> Adapter {
Adapter {
id: wgn::wgpu_instance_get_adapter(self.id, desc),
}
}
}
impl Adapter {
pub fn create_device(&self, desc: DeviceDescriptor) -> Device {
Device {
id: wgn::wgpu_adapter_create_device(self.id, desc),
}
}
}
impl Device {
pub fn create_shader_module(&self, spv: &[u8]) -> ShaderModule {
let desc = wgn::ShaderModuleDescriptor{
code: wgn::ByteArray {
bytes: spv.as_ptr(),
length: spv.len(),
},
};
ShaderModule {
id: wgn::wgpu_device_create_shader_module(self.id, desc),
}
}
}