Make output format of iced_wgpu
configurable
This commit is contained in:
parent
e680fd27e7
commit
be14aca075
@ -40,11 +40,12 @@ pub fn main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let surface = wgpu::Surface::create(&window);
|
let surface = wgpu::Surface::create(&window);
|
||||||
|
let format = wgpu::TextureFormat::Bgra8UnormSrgb;
|
||||||
|
|
||||||
let mut swap_chain = {
|
let mut swap_chain = {
|
||||||
let size = window.inner_size();
|
let size = window.inner_size();
|
||||||
|
|
||||||
SwapChain::new(&device, &surface, size.width, size.height)
|
SwapChain::new(&device, &surface, format, size.width, size.height)
|
||||||
};
|
};
|
||||||
let mut resized = false;
|
let mut resized = false;
|
||||||
|
|
||||||
@ -163,6 +164,7 @@ pub fn main() {
|
|||||||
swap_chain = SwapChain::new(
|
swap_chain = SwapChain::new(
|
||||||
&device,
|
&device,
|
||||||
&surface,
|
&surface,
|
||||||
|
format,
|
||||||
size.width,
|
size.width,
|
||||||
size.height,
|
size.height,
|
||||||
);
|
);
|
||||||
|
@ -183,6 +183,7 @@ pub trait Application: Sized {
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
|
..iced_wgpu::Settings::default()
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ pub struct Pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Pipeline {
|
impl Pipeline {
|
||||||
pub fn new(device: &wgpu::Device) -> Self {
|
pub fn new(device: &wgpu::Device, format: wgpu::TextureFormat) -> Self {
|
||||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||||
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
address_mode_u: wgpu::AddressMode::ClampToEdge,
|
||||||
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
address_mode_v: wgpu::AddressMode::ClampToEdge,
|
||||||
@ -135,7 +135,7 @@ impl Pipeline {
|
|||||||
}),
|
}),
|
||||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||||
color_states: &[wgpu::ColorStateDescriptor {
|
color_states: &[wgpu::ColorStateDescriptor {
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format,
|
||||||
color_blend: wgpu::BlendDescriptor {
|
color_blend: wgpu::BlendDescriptor {
|
||||||
src_factor: wgpu::BlendFactor::SrcAlpha,
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
||||||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
||||||
|
@ -14,7 +14,10 @@ pub struct Pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Pipeline {
|
impl Pipeline {
|
||||||
pub fn new(device: &mut wgpu::Device) -> Pipeline {
|
pub fn new(
|
||||||
|
device: &mut wgpu::Device,
|
||||||
|
format: wgpu::TextureFormat,
|
||||||
|
) -> Pipeline {
|
||||||
let constant_layout =
|
let constant_layout =
|
||||||
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
||||||
bindings: &[wgpu::BindGroupLayoutBinding {
|
bindings: &[wgpu::BindGroupLayoutBinding {
|
||||||
@ -79,7 +82,7 @@ impl Pipeline {
|
|||||||
}),
|
}),
|
||||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||||
color_states: &[wgpu::ColorStateDescriptor {
|
color_states: &[wgpu::ColorStateDescriptor {
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format,
|
||||||
color_blend: wgpu::BlendDescriptor {
|
color_blend: wgpu::BlendDescriptor {
|
||||||
src_factor: wgpu::BlendFactor::SrcAlpha,
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
||||||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
||||||
|
@ -48,11 +48,16 @@ impl Renderer {
|
|||||||
///
|
///
|
||||||
/// [`Renderer`]: struct.Renderer.html
|
/// [`Renderer`]: struct.Renderer.html
|
||||||
pub fn new(device: &mut wgpu::Device, settings: Settings) -> Self {
|
pub fn new(device: &mut wgpu::Device, settings: Settings) -> Self {
|
||||||
let text_pipeline = text::Pipeline::new(device, settings.default_font);
|
let text_pipeline =
|
||||||
let quad_pipeline = quad::Pipeline::new(device);
|
text::Pipeline::new(device, settings.format, settings.default_font);
|
||||||
let image_pipeline = crate::image::Pipeline::new(device);
|
let quad_pipeline = quad::Pipeline::new(device, settings.format);
|
||||||
let triangle_pipeline =
|
let image_pipeline =
|
||||||
triangle::Pipeline::new(device, settings.antialiasing);
|
crate::image::Pipeline::new(device, settings.format);
|
||||||
|
let triangle_pipeline = triangle::Pipeline::new(
|
||||||
|
device,
|
||||||
|
settings.format,
|
||||||
|
settings.antialiasing,
|
||||||
|
);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
quad_pipeline,
|
quad_pipeline,
|
||||||
|
@ -5,8 +5,13 @@
|
|||||||
/// The settings of a [`Renderer`].
|
/// The settings of a [`Renderer`].
|
||||||
///
|
///
|
||||||
/// [`Renderer`]: ../struct.Renderer.html
|
/// [`Renderer`]: ../struct.Renderer.html
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
|
/// The output format of the [`Renderer`].
|
||||||
|
///
|
||||||
|
/// [`Renderer`]: ../struct.Renderer.html
|
||||||
|
pub format: wgpu::TextureFormat,
|
||||||
|
|
||||||
/// The bytes of the font that will be used by default.
|
/// The bytes of the font that will be used by default.
|
||||||
///
|
///
|
||||||
/// If `None` is provided, a default system font will be chosen.
|
/// If `None` is provided, a default system font will be chosen.
|
||||||
@ -16,6 +21,16 @@ pub struct Settings {
|
|||||||
pub antialiasing: Option<Antialiasing>,
|
pub antialiasing: Option<Antialiasing>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Settings {
|
||||||
|
fn default() -> Settings {
|
||||||
|
Settings {
|
||||||
|
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
||||||
|
default_font: None,
|
||||||
|
antialiasing: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// An antialiasing strategy.
|
/// An antialiasing strategy.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum Antialiasing {
|
pub enum Antialiasing {
|
||||||
|
@ -22,7 +22,11 @@ pub struct Pipeline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Pipeline {
|
impl Pipeline {
|
||||||
pub fn new(device: &mut wgpu::Device, default_font: Option<&[u8]>) -> Self {
|
pub fn new(
|
||||||
|
device: &mut wgpu::Device,
|
||||||
|
format: wgpu::TextureFormat,
|
||||||
|
default_font: Option<&[u8]>,
|
||||||
|
) -> Self {
|
||||||
// TODO: Font customization
|
// TODO: Font customization
|
||||||
let font_source = font::Source::new();
|
let font_source = font::Source::new();
|
||||||
|
|
||||||
@ -54,7 +58,7 @@ impl Pipeline {
|
|||||||
|
|
||||||
let draw_brush = brush_builder
|
let draw_brush = brush_builder
|
||||||
.initial_cache_size((2048, 2048))
|
.initial_cache_size((2048, 2048))
|
||||||
.build(device, wgpu::TextureFormat::Bgra8UnormSrgb);
|
.build(device, format);
|
||||||
|
|
||||||
Pipeline {
|
Pipeline {
|
||||||
draw_brush: RefCell::new(draw_brush),
|
draw_brush: RefCell::new(draw_brush),
|
||||||
|
@ -61,6 +61,7 @@ impl<T> Buffer<T> {
|
|||||||
impl Pipeline {
|
impl Pipeline {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
device: &mut wgpu::Device,
|
device: &mut wgpu::Device,
|
||||||
|
format: wgpu::TextureFormat,
|
||||||
antialiasing: Option<settings::Antialiasing>,
|
antialiasing: Option<settings::Antialiasing>,
|
||||||
) -> Pipeline {
|
) -> Pipeline {
|
||||||
let constant_layout =
|
let constant_layout =
|
||||||
@ -127,7 +128,7 @@ impl Pipeline {
|
|||||||
}),
|
}),
|
||||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||||
color_states: &[wgpu::ColorStateDescriptor {
|
color_states: &[wgpu::ColorStateDescriptor {
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format,
|
||||||
color_blend: wgpu::BlendDescriptor {
|
color_blend: wgpu::BlendDescriptor {
|
||||||
src_factor: wgpu::BlendFactor::SrcAlpha,
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
||||||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
||||||
@ -169,7 +170,7 @@ impl Pipeline {
|
|||||||
|
|
||||||
Pipeline {
|
Pipeline {
|
||||||
pipeline,
|
pipeline,
|
||||||
blit: antialiasing.map(|a| msaa::Blit::new(device, a)),
|
blit: antialiasing.map(|a| msaa::Blit::new(device, format, a)),
|
||||||
constants: constant_bind_group,
|
constants: constant_bind_group,
|
||||||
uniforms_buffer: constants_buffer,
|
uniforms_buffer: constants_buffer,
|
||||||
vertex_buffer: Buffer::new(
|
vertex_buffer: Buffer::new(
|
||||||
|
@ -2,6 +2,7 @@ use crate::settings;
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Blit {
|
pub struct Blit {
|
||||||
|
format: wgpu::TextureFormat,
|
||||||
pipeline: wgpu::RenderPipeline,
|
pipeline: wgpu::RenderPipeline,
|
||||||
constants: wgpu::BindGroup,
|
constants: wgpu::BindGroup,
|
||||||
texture_layout: wgpu::BindGroupLayout,
|
texture_layout: wgpu::BindGroupLayout,
|
||||||
@ -12,6 +13,7 @@ pub struct Blit {
|
|||||||
impl Blit {
|
impl Blit {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
|
format: wgpu::TextureFormat,
|
||||||
antialiasing: settings::Antialiasing,
|
antialiasing: settings::Antialiasing,
|
||||||
) -> Blit {
|
) -> Blit {
|
||||||
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
|
||||||
@ -93,7 +95,7 @@ impl Blit {
|
|||||||
}),
|
}),
|
||||||
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
primitive_topology: wgpu::PrimitiveTopology::TriangleList,
|
||||||
color_states: &[wgpu::ColorStateDescriptor {
|
color_states: &[wgpu::ColorStateDescriptor {
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format,
|
||||||
color_blend: wgpu::BlendDescriptor {
|
color_blend: wgpu::BlendDescriptor {
|
||||||
src_factor: wgpu::BlendFactor::SrcAlpha,
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
||||||
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
||||||
@ -115,6 +117,7 @@ impl Blit {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Blit {
|
Blit {
|
||||||
|
format,
|
||||||
pipeline,
|
pipeline,
|
||||||
constants: constant_bind_group,
|
constants: constant_bind_group,
|
||||||
texture_layout: texture_layout,
|
texture_layout: texture_layout,
|
||||||
@ -133,6 +136,7 @@ impl Blit {
|
|||||||
None => {
|
None => {
|
||||||
self.targets = Some(Targets::new(
|
self.targets = Some(Targets::new(
|
||||||
&device,
|
&device,
|
||||||
|
self.format,
|
||||||
&self.texture_layout,
|
&self.texture_layout,
|
||||||
self.sample_count,
|
self.sample_count,
|
||||||
width,
|
width,
|
||||||
@ -143,6 +147,7 @@ impl Blit {
|
|||||||
if targets.width != width || targets.height != height {
|
if targets.width != width || targets.height != height {
|
||||||
self.targets = Some(Targets::new(
|
self.targets = Some(Targets::new(
|
||||||
&device,
|
&device,
|
||||||
|
self.format,
|
||||||
&self.texture_layout,
|
&self.texture_layout,
|
||||||
self.sample_count,
|
self.sample_count,
|
||||||
width,
|
width,
|
||||||
@ -204,6 +209,7 @@ struct Targets {
|
|||||||
impl Targets {
|
impl Targets {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
|
format: wgpu::TextureFormat,
|
||||||
texture_layout: &wgpu::BindGroupLayout,
|
texture_layout: &wgpu::BindGroupLayout,
|
||||||
sample_count: u32,
|
sample_count: u32,
|
||||||
width: u32,
|
width: u32,
|
||||||
@ -221,7 +227,7 @@ impl Targets {
|
|||||||
mip_level_count: 1,
|
mip_level_count: 1,
|
||||||
sample_count,
|
sample_count,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format,
|
||||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -231,7 +237,7 @@ impl Targets {
|
|||||||
mip_level_count: 1,
|
mip_level_count: 1,
|
||||||
sample_count: 1,
|
sample_count: 1,
|
||||||
dimension: wgpu::TextureDimension::D2,
|
dimension: wgpu::TextureDimension::D2,
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format,
|
||||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT
|
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT
|
||||||
| wgpu::TextureUsage::SAMPLED,
|
| wgpu::TextureUsage::SAMPLED,
|
||||||
});
|
});
|
||||||
|
@ -8,6 +8,7 @@ use raw_window_handle::HasRawWindowHandle;
|
|||||||
pub struct Backend {
|
pub struct Backend {
|
||||||
device: wgpu::Device,
|
device: wgpu::Device,
|
||||||
queue: wgpu::Queue,
|
queue: wgpu::Queue,
|
||||||
|
format: wgpu::TextureFormat,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl iced_native::window::Backend for Backend {
|
impl iced_native::window::Backend for Backend {
|
||||||
@ -37,7 +38,14 @@ impl iced_native::window::Backend for Backend {
|
|||||||
|
|
||||||
let renderer = Renderer::new(&mut device, settings);
|
let renderer = Renderer::new(&mut device, settings);
|
||||||
|
|
||||||
(Backend { device, queue }, renderer)
|
(
|
||||||
|
Backend {
|
||||||
|
device,
|
||||||
|
queue,
|
||||||
|
format: settings.format,
|
||||||
|
},
|
||||||
|
renderer,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_surface<W: HasRawWindowHandle>(
|
fn create_surface<W: HasRawWindowHandle>(
|
||||||
@ -53,7 +61,7 @@ impl iced_native::window::Backend for Backend {
|
|||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
) -> SwapChain {
|
) -> SwapChain {
|
||||||
SwapChain::new(&self.device, surface, width, height)
|
SwapChain::new(&self.device, surface, self.format, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw<T: AsRef<str>>(
|
fn draw<T: AsRef<str>>(
|
||||||
|
@ -18,11 +18,12 @@ impl SwapChain {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
surface: &wgpu::Surface,
|
surface: &wgpu::Surface,
|
||||||
|
format: wgpu::TextureFormat,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
) -> SwapChain {
|
) -> SwapChain {
|
||||||
SwapChain {
|
SwapChain {
|
||||||
raw: new_swap_chain(surface, width, height, device),
|
raw: new_swap_chain(surface, format, width, height, device),
|
||||||
viewport: Viewport::new(width, height),
|
viewport: Viewport::new(width, height),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,6 +39,7 @@ impl SwapChain {
|
|||||||
|
|
||||||
fn new_swap_chain(
|
fn new_swap_chain(
|
||||||
surface: &wgpu::Surface,
|
surface: &wgpu::Surface,
|
||||||
|
format: wgpu::TextureFormat,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
@ -46,7 +48,7 @@ fn new_swap_chain(
|
|||||||
&surface,
|
&surface,
|
||||||
&wgpu::SwapChainDescriptor {
|
&wgpu::SwapChainDescriptor {
|
||||||
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
|
||||||
format: wgpu::TextureFormat::Bgra8UnormSrgb,
|
format,
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
present_mode: wgpu::PresentMode::Vsync,
|
present_mode: wgpu::PresentMode::Vsync,
|
||||||
|
Loading…
Reference in New Issue
Block a user