mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Upgrade to wgpu from this PR: gfx-rs/wgpu#3657 (#272)
This commit is contained in:
parent
bca19c8ace
commit
4945edcd0b
@ -55,7 +55,8 @@ geozero = { version = "0.9.7", default-features = false, features = ["with-mvt",
|
|||||||
tile-grid = "0.3.0"
|
tile-grid = "0.3.0"
|
||||||
|
|
||||||
# Rendering
|
# Rendering
|
||||||
wgpu = "0.15.0"
|
#wgpu = "0.15.0"
|
||||||
|
wgpu = { git = "https://github.com/gfx-rs/wgpu.git", rev = "cfc038aeb9b732019dc03fa7eeaac1c7f37fc71f" }
|
||||||
# wgpu = { git = "https://github.com/gfx-rs/wgpu" }
|
# wgpu = { git = "https://github.com/gfx-rs/wgpu" }
|
||||||
lyon = { version = "1.0.0", features = [] }
|
lyon = { version = "1.0.0", features = [] }
|
||||||
raw-window-handle = "0.5.0"
|
raw-window-handle = "0.5.0"
|
||||||
|
|||||||
@ -93,8 +93,8 @@ fn upload_raster_layer(
|
|||||||
image,
|
image,
|
||||||
wgpu::ImageDataLayout {
|
wgpu::ImageDataLayout {
|
||||||
offset: 0,
|
offset: 0,
|
||||||
bytes_per_row: std::num::NonZeroU32::new(4 * width),
|
bytes_per_row: Some(4 * width),
|
||||||
rows_per_image: std::num::NonZeroU32::new(height),
|
rows_per_image: Some(height),
|
||||||
},
|
},
|
||||||
texture.size,
|
texture.size,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
//! Utilities for handling surfaces which can be either headless or headed. A headed surface has
|
//! Utilities for handling surfaces which can be either headless or headed. A headed surface has
|
||||||
//! a handle to a window. A headless surface renders to a texture.
|
//! a handle to a window. A headless surface renders to a texture.
|
||||||
|
|
||||||
use std::{mem::size_of, num::NonZeroU32, sync::Arc};
|
use std::{mem::size_of, sync::Arc};
|
||||||
|
|
||||||
use wgpu::TextureFormatFeatures;
|
use wgpu::TextureFormatFeatures;
|
||||||
|
|
||||||
@ -18,8 +18,8 @@ use crate::{
|
|||||||
pub struct BufferDimensions {
|
pub struct BufferDimensions {
|
||||||
pub width: u32,
|
pub width: u32,
|
||||||
pub height: u32,
|
pub height: u32,
|
||||||
pub unpadded_bytes_per_row: NonZeroU32,
|
pub unpadded_bytes_per_row: u32,
|
||||||
pub padded_bytes_per_row: NonZeroU32,
|
pub padded_bytes_per_row: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BufferDimensions {
|
impl BufferDimensions {
|
||||||
@ -33,9 +33,8 @@ impl BufferDimensions {
|
|||||||
Self {
|
Self {
|
||||||
width: size.width(),
|
width: size.width(),
|
||||||
height: size.height(),
|
height: size.height(),
|
||||||
unpadded_bytes_per_row: NonZeroU32::new(unpadded_bytes_per_row)
|
unpadded_bytes_per_row,
|
||||||
.expect("can not be zero"), // expect is fine because this can never happen
|
padded_bytes_per_row,
|
||||||
padded_bytes_per_row: NonZeroU32::new(padded_bytes_per_row).expect("can not be zero"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,16 +132,14 @@ impl BufferedTextureHead {
|
|||||||
);
|
);
|
||||||
png_encoder.set_depth(png::BitDepth::Eight);
|
png_encoder.set_depth(png::BitDepth::Eight);
|
||||||
png_encoder.set_color(png::ColorType::Rgba);
|
png_encoder.set_color(png::ColorType::Rgba);
|
||||||
let mut png_writer = png_encoder.write_header()?.into_stream_writer_with_size(
|
let mut png_writer = png_encoder
|
||||||
self.buffer_dimensions.unpadded_bytes_per_row.get() as usize,
|
.write_header()?
|
||||||
)?;
|
.into_stream_writer_with_size(self.buffer_dimensions.unpadded_bytes_per_row as usize)?;
|
||||||
|
|
||||||
// from the padded_buffer we write just the unpadded bytes into the image
|
// from the padded_buffer we write just the unpadded bytes into the image
|
||||||
for chunk in
|
for chunk in padded_buffer.chunks(self.buffer_dimensions.padded_bytes_per_row as usize) {
|
||||||
padded_buffer.chunks(self.buffer_dimensions.padded_bytes_per_row.get() as usize)
|
|
||||||
{
|
|
||||||
png_writer
|
png_writer
|
||||||
.write_all(&chunk[..self.buffer_dimensions.unpadded_bytes_per_row.get() as usize])?
|
.write_all(&chunk[..self.buffer_dimensions.unpadded_bytes_per_row as usize])?
|
||||||
}
|
}
|
||||||
png_writer.finish()?;
|
png_writer.finish()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -156,7 +153,7 @@ impl BufferedTextureHead {
|
|||||||
&self.output_buffer
|
&self.output_buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bytes_per_row(&self) -> NonZeroU32 {
|
pub fn bytes_per_row(&self) -> u32 {
|
||||||
self.buffer_dimensions.padded_bytes_per_row
|
self.buffer_dimensions.padded_bytes_per_row
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -190,7 +187,7 @@ impl Surface {
|
|||||||
.texture_format
|
.texture_format
|
||||||
.or_else(|| capabilities.formats.first().cloned())
|
.or_else(|| capabilities.formats.first().cloned())
|
||||||
.unwrap_or(wgpu::TextureFormat::Rgba8Unorm);
|
.unwrap_or(wgpu::TextureFormat::Rgba8Unorm);
|
||||||
log::info!("format description: {:?}", texture_format.describe());
|
log::info!("format description: {:?}", texture_format);
|
||||||
|
|
||||||
let texture_format_features = adapter.get_texture_format_features(texture_format);
|
let texture_format_features = adapter.get_texture_format_features(texture_format);
|
||||||
log::info!("format features: {:?}", texture_format_features);
|
log::info!("format features: {:?}", texture_format_features);
|
||||||
@ -223,7 +220,7 @@ impl Surface {
|
|||||||
// The output buffer lets us retrieve the data as an array
|
// The output buffer lets us retrieve the data as an array
|
||||||
let output_buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
let output_buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
||||||
label: Some("BufferedTextureHead buffer"),
|
label: Some("BufferedTextureHead buffer"),
|
||||||
size: (buffer_dimensions.padded_bytes_per_row.get() * buffer_dimensions.height) as u64,
|
size: (buffer_dimensions.padded_bytes_per_row * buffer_dimensions.height) as u64,
|
||||||
usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
|
usage: wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST,
|
||||||
mapped_at_creation: false,
|
mapped_at_creation: false,
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user