Store wgpu::Backend in image::Atlas
This commit is contained in:
parent
16703ccdef
commit
2d2888ee03
5 changed files with 11 additions and 22 deletions
|
|
@ -19,6 +19,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Atlas {
|
pub struct Atlas {
|
||||||
|
backend: wgpu::Backend,
|
||||||
texture: wgpu::Texture,
|
texture: wgpu::Texture,
|
||||||
texture_view: wgpu::TextureView,
|
texture_view: wgpu::TextureView,
|
||||||
texture_bind_group: wgpu::BindGroup,
|
texture_bind_group: wgpu::BindGroup,
|
||||||
|
|
@ -79,6 +80,7 @@ impl Atlas {
|
||||||
});
|
});
|
||||||
|
|
||||||
Atlas {
|
Atlas {
|
||||||
|
backend,
|
||||||
texture,
|
texture,
|
||||||
texture_view,
|
texture_view,
|
||||||
texture_bind_group,
|
texture_bind_group,
|
||||||
|
|
@ -98,7 +100,6 @@ impl Atlas {
|
||||||
pub fn upload(
|
pub fn upload(
|
||||||
&mut self,
|
&mut self,
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
backend: wgpu::Backend,
|
|
||||||
encoder: &mut wgpu::CommandEncoder,
|
encoder: &mut wgpu::CommandEncoder,
|
||||||
width: u32,
|
width: u32,
|
||||||
height: u32,
|
height: u32,
|
||||||
|
|
@ -110,7 +111,7 @@ impl Atlas {
|
||||||
|
|
||||||
// We grow the internal texture after allocating if necessary
|
// We grow the internal texture after allocating if necessary
|
||||||
let new_layers = self.layers.len() - current_size;
|
let new_layers = self.layers.len() - current_size;
|
||||||
self.grow(new_layers, device, backend, encoder);
|
self.grow(new_layers, device, encoder);
|
||||||
|
|
||||||
entry
|
entry
|
||||||
};
|
};
|
||||||
|
|
@ -371,7 +372,6 @@ impl Atlas {
|
||||||
&mut self,
|
&mut self,
|
||||||
amount: usize,
|
amount: usize,
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
backend: wgpu::Backend,
|
|
||||||
encoder: &mut wgpu::CommandEncoder,
|
encoder: &mut wgpu::CommandEncoder,
|
||||||
) {
|
) {
|
||||||
if amount == 0 {
|
if amount == 0 {
|
||||||
|
|
@ -383,7 +383,7 @@ impl Atlas {
|
||||||
// some unused memory on GL, but it's better than not being able to grow the atlas past a depth
|
// some unused memory on GL, but it's better than not being able to grow the atlas past a depth
|
||||||
// of 6!
|
// of 6!
|
||||||
// https://github.com/gfx-rs/wgpu/blob/004e3efe84a320d9331371ed31fa50baa2414911/wgpu-hal/src/gles/mod.rs#L371
|
// https://github.com/gfx-rs/wgpu/blob/004e3efe84a320d9331371ed31fa50baa2414911/wgpu-hal/src/gles/mod.rs#L371
|
||||||
let depth_or_array_layers = match backend {
|
let depth_or_array_layers = match self.backend {
|
||||||
wgpu::Backend::Gl if self.layers.len() == 6 => 7,
|
wgpu::Backend::Gl if self.layers.len() == 6 => 7,
|
||||||
_ => self.layers.len() as u32,
|
_ => self.layers.len() as u32,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -49,19 +49,16 @@ impl Cache {
|
||||||
pub fn upload_raster(
|
pub fn upload_raster(
|
||||||
&mut self,
|
&mut self,
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
backend: wgpu::Backend,
|
|
||||||
encoder: &mut wgpu::CommandEncoder,
|
encoder: &mut wgpu::CommandEncoder,
|
||||||
handle: &core::image::Handle,
|
handle: &core::image::Handle,
|
||||||
) -> Option<&atlas::Entry> {
|
) -> Option<&atlas::Entry> {
|
||||||
self.raster
|
self.raster.upload(device, encoder, handle, &mut self.atlas)
|
||||||
.upload(device, backend, encoder, handle, &mut self.atlas)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "svg")]
|
#[cfg(feature = "svg")]
|
||||||
pub fn upload_vector(
|
pub fn upload_vector(
|
||||||
&mut self,
|
&mut self,
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
backend: wgpu::Backend,
|
|
||||||
encoder: &mut wgpu::CommandEncoder,
|
encoder: &mut wgpu::CommandEncoder,
|
||||||
handle: &core::svg::Handle,
|
handle: &core::svg::Handle,
|
||||||
color: Option<core::Color>,
|
color: Option<core::Color>,
|
||||||
|
|
@ -70,7 +67,6 @@ impl Cache {
|
||||||
) -> Option<&atlas::Entry> {
|
) -> Option<&atlas::Entry> {
|
||||||
self.vector.upload(
|
self.vector.upload(
|
||||||
device,
|
device,
|
||||||
backend,
|
|
||||||
encoder,
|
encoder,
|
||||||
handle,
|
handle,
|
||||||
color,
|
color,
|
||||||
|
|
|
||||||
|
|
@ -235,12 +235,9 @@ impl State {
|
||||||
match &image {
|
match &image {
|
||||||
#[cfg(feature = "image")]
|
#[cfg(feature = "image")]
|
||||||
Image::Raster(image, bounds) => {
|
Image::Raster(image, bounds) => {
|
||||||
if let Some(atlas_entry) = cache.upload_raster(
|
if let Some(atlas_entry) =
|
||||||
device,
|
cache.upload_raster(device, encoder, &image.handle)
|
||||||
pipeline.backend,
|
{
|
||||||
encoder,
|
|
||||||
&image.handle,
|
|
||||||
) {
|
|
||||||
add_instances(
|
add_instances(
|
||||||
[bounds.x, bounds.y],
|
[bounds.x, bounds.y],
|
||||||
[bounds.width, bounds.height],
|
[bounds.width, bounds.height],
|
||||||
|
|
@ -268,7 +265,6 @@ impl State {
|
||||||
|
|
||||||
if let Some(atlas_entry) = cache.upload_vector(
|
if let Some(atlas_entry) = cache.upload_vector(
|
||||||
device,
|
device,
|
||||||
pipeline.backend,
|
|
||||||
encoder,
|
encoder,
|
||||||
&svg.handle,
|
&svg.handle,
|
||||||
svg.color,
|
svg.color,
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,6 @@ impl Cache {
|
||||||
pub fn upload(
|
pub fn upload(
|
||||||
&mut self,
|
&mut self,
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
backend: wgpu::Backend,
|
|
||||||
encoder: &mut wgpu::CommandEncoder,
|
encoder: &mut wgpu::CommandEncoder,
|
||||||
handle: &image::Handle,
|
handle: &image::Handle,
|
||||||
atlas: &mut Atlas,
|
atlas: &mut Atlas,
|
||||||
|
|
@ -76,8 +75,7 @@ impl Cache {
|
||||||
if let Memory::Host(image) = memory {
|
if let Memory::Host(image) = memory {
|
||||||
let (width, height) = image.dimensions();
|
let (width, height) = image.dimensions();
|
||||||
|
|
||||||
let entry =
|
let entry = atlas.upload(device, encoder, width, height, image)?;
|
||||||
atlas.upload(device, backend, encoder, width, height, image)?;
|
|
||||||
|
|
||||||
*memory = Memory::Device(entry);
|
*memory = Memory::Device(entry);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,6 @@ impl Cache {
|
||||||
pub fn upload(
|
pub fn upload(
|
||||||
&mut self,
|
&mut self,
|
||||||
device: &wgpu::Device,
|
device: &wgpu::Device,
|
||||||
backend: wgpu::Backend,
|
|
||||||
encoder: &mut wgpu::CommandEncoder,
|
encoder: &mut wgpu::CommandEncoder,
|
||||||
handle: &svg::Handle,
|
handle: &svg::Handle,
|
||||||
color: Option<Color>,
|
color: Option<Color>,
|
||||||
|
|
@ -168,8 +167,8 @@ impl Cache {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let allocation = atlas
|
let allocation =
|
||||||
.upload(device, backend, encoder, width, height, &rgba)?;
|
atlas.upload(device, encoder, width, height, &rgba)?;
|
||||||
|
|
||||||
log::debug!("allocating {id} {width}x{height}");
|
log::debug!("allocating {id} {width}x{height}");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue