Get rid of unwraps
This commit is contained in:
1 parent
8cfc82d668
commit
6f0eef7cf8
2 files changed
+9
-7
No files matched your search
+4
-2
@@ -1,3 +1,5 @@
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
use ahash::HashMap;
|
||||
|
||||
use crate::{
|
||||
@@ -37,12 +39,12 @@ impl BatchBuilder {
|
||||
///
|
||||
/// Returns slot_index into textures array if texture can be assigned.
|
||||
/// Returns `None` if maximum amount of texture slots is reached.
|
||||
fn try_assign(&mut self, id: TextureId, max_slots: u32) -> Option<u32> {
|
||||
fn try_assign(&mut self, id: TextureId, max_slots: NonZeroU32) -> Option<u32> {
|
||||
if let Some(&slot) = self.texture_mapping.get(&id) {
|
||||
return Some(slot);
|
||||
}
|
||||
|
||||
if self.textures.len() as u32 >= max_slots {
|
||||
if self.textures.len() as u32 >= max_slots.get() {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -21,7 +21,7 @@ pub mod image;
|
||||
mod mipmap;
|
||||
pub mod textures;
|
||||
|
||||
pub const BATCH_TEX_SLOTS: u32 = 32;
|
||||
pub const BATCH_TEX_SLOTS: NonZeroU32 = NonZeroU32::new(32).expect("32 is non-zero");
|
||||
const DUMMY_TEXTURE_ID: TextureId = 0;
|
||||
|
||||
#[repr(C)]
|
||||
@@ -162,13 +162,13 @@ impl Renderer {
|
||||
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
||||
view_dimension: wgpu::TextureViewDimension::D2Array,
|
||||
},
|
||||
count: Some(NonZeroU32::new(BATCH_TEX_SLOTS).unwrap()),
|
||||
count: Some(BATCH_TEX_SLOTS),
|
||||
},
|
||||
wgpu::BindGroupLayoutEntry {
|
||||
binding: 1,
|
||||
visibility: wgpu::ShaderStages::FRAGMENT,
|
||||
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
|
||||
count: Some(NonZeroU32::new(BATCH_TEX_SLOTS).unwrap()),
|
||||
count: Some(BATCH_TEX_SLOTS),
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -497,8 +497,8 @@ impl Renderer {
|
||||
// so we pad to up MAX_SLOTS with a dummy view/sampler
|
||||
let dummy = &self.textures[&DUMMY_TEXTURE_ID];
|
||||
let dummy_sampler = self.samplers.get(&dummy.options).unwrap();
|
||||
views.resize(BATCH_TEX_SLOTS as usize, &dummy.view);
|
||||
samplers.resize(BATCH_TEX_SLOTS as usize, dummy_sampler);
|
||||
views.resize(BATCH_TEX_SLOTS.get() as usize, &dummy.view);
|
||||
samplers.resize(BATCH_TEX_SLOTS.get() as usize, dummy_sampler);
|
||||
|
||||
device.create_bind_group(&wgpu::BindGroupDescriptor {
|
||||
label: Some("batch_textures_bind_group"),
|
||||
|
||||
Reference in new issue
Block a user