mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Add builder for TextureDescriptor
This commit is contained in:
parent
9929b8719f
commit
d5f23f9323
45
wgpu-types/src/into_cow.rs
Normal file
45
wgpu-types/src/into_cow.rs
Normal file
@ -0,0 +1,45 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
/// Implements conversion into a cow.
|
||||
pub trait IntoCow<'c, CowType: ?Sized + ToOwned> {
|
||||
fn into_cow(self) -> Cow<'c, CowType>;
|
||||
}
|
||||
|
||||
impl<'c, T: Clone> IntoCow<'c, [T]> for &'c [T] {
|
||||
fn into_cow(self) -> Cow<'c, [T]> {
|
||||
Cow::Borrowed(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'c> IntoCow<'c, str> for &'c str {
|
||||
fn into_cow(self) -> Cow<'c, str> {
|
||||
Cow::Borrowed(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Clone> IntoCow<'static, [T]> for Vec<T> {
|
||||
fn into_cow(self) -> Cow<'static, [T]> {
|
||||
Cow::Owned(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoCow<'static, str> for String {
|
||||
fn into_cow(self) -> Cow<'static, str> {
|
||||
Cow::Owned(self)
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! into_cow_array {
|
||||
($($number:literal),*) => {$(
|
||||
impl<'c, T: Clone> IntoCow<'c, [T]> for &'c [T; $number] {
|
||||
fn into_cow(self) -> Cow<'c, [T]> {
|
||||
Cow::Borrowed(&self[..])
|
||||
}
|
||||
}
|
||||
)*};
|
||||
}
|
||||
|
||||
into_cow_array!(
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
|
||||
26, 27, 28, 29, 30, 31, 32
|
||||
);
|
||||
@ -12,6 +12,9 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{borrow::Cow, num::NonZeroU32, ops::Range};
|
||||
|
||||
pub use into_cow::IntoCow;
|
||||
mod into_cow;
|
||||
|
||||
/// Integral type used for buffer offsets.
|
||||
pub type BufferAddress = u64;
|
||||
/// Integral type used for buffer slice sizes.
|
||||
@ -1305,6 +1308,42 @@ impl<L> TextureDescriptor<L> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Texture descriptor builder methods
|
||||
impl<'a> TextureDescriptor<Option<Cow<'a, str>>> {
|
||||
pub fn new(
|
||||
size: Extent3d,
|
||||
dimension: TextureDimension,
|
||||
format: TextureFormat,
|
||||
usage: TextureUsage,
|
||||
) -> Self {
|
||||
Self {
|
||||
label: None,
|
||||
size,
|
||||
mip_level_count: 1,
|
||||
sample_count: 1,
|
||||
dimension,
|
||||
format,
|
||||
usage,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn label<L>(&mut self, label: impl IntoCow<'a, str>) -> &mut Self {
|
||||
self.label = Some(label.into_cow());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn mip_level_count(&mut self, count: u32) -> &mut Self {
|
||||
// TODO: validate this size is sane
|
||||
self.mip_level_count = count;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn sample_count(&mut self, count: u32) -> &mut Self {
|
||||
self.sample_count = count;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Kind of data the texture holds.
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user