summaryrefslogtreecommitdiffstats
path: root/wgpu
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-03 00:23:08 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-03 00:23:08 +0200
commit8bb33cd5a0b876a5e24108604be2cecd4efad3ef (patch)
tree5446cf485f0d8b708c9ce55f163ba91c500e1148 /wgpu
parent63294088ad6e1523c6b7623c08f82af2812a5531 (diff)
downloadiced-8bb33cd5a0b876a5e24108604be2cecd4efad3ef.tar.gz
iced-8bb33cd5a0b876a5e24108604be2cecd4efad3ef.tar.bz2
iced-8bb33cd5a0b876a5e24108604be2cecd4efad3ef.zip
Initialize `wgpu`
We only enable the `vulkan` feature for now.
Diffstat (limited to 'wgpu')
-rw-r--r--wgpu/Cargo.toml4
-rw-r--r--wgpu/src/lib.rs39
2 files changed, 42 insertions, 1 deletions
diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml
index 0ab7a955..879def28 100644
--- a/wgpu/Cargo.toml
+++ b/wgpu/Cargo.toml
@@ -7,6 +7,10 @@ description = "A wgpu renderer for Iced"
license = "MIT"
repository = "https://github.com/hecrj/iced"
+[features]
+vulkan = ["wgpu/vulkan"]
+
[dependencies]
iced_native = { version = "0.1.0-alpha", path = "../native" }
wgpu = "0.3"
+raw-window-handle = "0.1"
diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs
index 7aa053bc..502a2614 100644
--- a/wgpu/src/lib.rs
+++ b/wgpu/src/lib.rs
@@ -4,7 +4,44 @@ use iced_native::{
Style, Text,
};
-pub struct Renderer;
+use raw_window_handle::HasRawWindowHandle;
+use wgpu::{
+ Adapter, Device, DeviceDescriptor, Extensions, Instance, Limits,
+ PowerPreference, RequestAdapterOptions, Surface,
+};
+
+pub struct Renderer {
+ instance: Instance,
+ surface: Surface,
+ adapter: Adapter,
+ device: Device,
+}
+
+impl Renderer {
+ pub fn new<W: HasRawWindowHandle>(window: &W) -> Self {
+ let instance = Instance::new();
+
+ let adapter = instance.request_adapter(&RequestAdapterOptions {
+ power_preference: PowerPreference::LowPower,
+ });
+
+ let device = adapter.request_device(&DeviceDescriptor {
+ extensions: Extensions {
+ anisotropic_filtering: false,
+ },
+ limits: Limits { max_bind_groups: 1 },
+ });
+
+ let surface = instance.create_surface(window.raw_window_handle());
+
+ Self {
+ instance,
+ surface,
+ adapter,
+ device,
+ }
+ }
+}
impl text::Renderer for Renderer {
fn node(&self, _text: &Text) -> Node {