-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Davidster/optimization
Optimization
- Loading branch information
Showing
22 changed files
with
1,680 additions
and
1,378 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use super::*; | ||
use std::collections::hash_map::Entry; | ||
use std::collections::HashMap; | ||
use std::rc::Rc; | ||
|
||
pub struct DefaultTextures { | ||
textures: HashMap<DefaultTextureType, Rc<Texture>>, | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | ||
pub enum DefaultTextureType { | ||
BaseColor, | ||
Normal, | ||
MetallicRoughness, | ||
MetallicRoughnessGLTF, | ||
Emissive, | ||
EmissiveGLTF, | ||
AmbientOcclusion, | ||
} | ||
|
||
impl DefaultTextures { | ||
pub fn new() -> Self { | ||
Self { | ||
textures: HashMap::new(), | ||
} | ||
} | ||
|
||
pub fn get_default_texture( | ||
&mut self, | ||
device: &wgpu::Device, | ||
queue: &wgpu::Queue, | ||
default_texture_type: DefaultTextureType, | ||
) -> anyhow::Result<Rc<Texture>> { | ||
match self.textures.entry(default_texture_type) { | ||
Entry::Occupied(texture) => Ok(texture.get().clone()), | ||
Entry::Vacant(entry) => { | ||
let color: [u8; 4] = match default_texture_type { | ||
DefaultTextureType::BaseColor => [255, 255, 255, 255], | ||
DefaultTextureType::Normal => [127, 127, 255, 255], | ||
DefaultTextureType::MetallicRoughness => [255, 255, 255, 255], | ||
DefaultTextureType::MetallicRoughnessGLTF => [255, 127, 0, 255], | ||
DefaultTextureType::Emissive => [0, 0, 0, 255], | ||
DefaultTextureType::EmissiveGLTF => [255, 255, 255, 255], | ||
DefaultTextureType::AmbientOcclusion => [255, 255, 255, 255], | ||
}; | ||
let texture = Rc::new(Texture::from_color(device, queue, color)?); | ||
Ok(entry.insert(texture).clone()) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.