From 8bb33cd5a0b876a5e24108604be2cecd4efad3ef Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 3 Oct 2019 00:23:08 +0200 Subject: Initialize `wgpu` We only enable the `vulkan` feature for now. --- Cargo.toml | 3 +++ src/lib.rs | 2 ++ wgpu/Cargo.toml | 4 ++++ wgpu/src/lib.rs | 39 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4792b3ad..08d51a0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,9 @@ members = [ "examples/tour", ] +[features] +vulkan = ["iced_wgpu/vulkan"] + [target.'cfg(not(target_arch = "wasm32"))'.dependencies] iced_winit = { version = "0.1.0-alpha", path = "winit" } iced_wgpu = { version = "0.1.0-alpha", path = "wgpu" } diff --git a/src/lib.rs b/src/lib.rs index 4344a50b..197212e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,6 +32,8 @@ pub trait UserInterface { .build(&event_loop) .expect("Open window"); + let renderer = Renderer::new(&window); + event_loop.run(move |event, _, control_flow| match event { Event::EventsCleared => { window.request_redraw(); 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(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 { -- cgit