Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add load_texture_with_sampler method #177

Merged
merged 1 commit into from
Feb 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/factory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,8 @@ impl Factory {
fn request_texture<P: AsRef<Path>>(
&mut self,
path: P,
sampler: Sampler,
) -> Texture<[f32; 4]> {
let sampler = self.default_sampler();
match self.texture_cache.entry(path.as_ref().to_owned()) {
Entry::Occupied(e) => e.get().clone(),
Entry::Vacant(e) => {
Expand Down Expand Up @@ -745,7 +745,10 @@ impl Factory {
} => material::Basic {
color: cf2u(color),
map: match (has_uv, map_kd) {
(true, &Some(ref name)) => Some(self.request_texture(&concat_path(obj_dir, name))),
(true, &Some(ref name)) => {
let sampler = self.default_sampler();
Some(self.request_texture(&concat_path(obj_dir, name), sampler))
},
_ => None,
},
}.into(),
Expand Down Expand Up @@ -774,13 +777,24 @@ impl Factory {
Texture::new(view, sampler.0, [width as u32, height as u32])
}

/// Load texture from file.
/// Load texture from file, with default `Sampler`.
/// Supported file formats are: PNG, JPEG, GIF, WEBP, PPM, TIFF, TGA, BMP, ICO, HDR.
pub fn load_texture<P: AsRef<Path>>(
&mut self,
path_str: P,
) -> Texture<[f32; 4]> {
self.request_texture(path_str)
let sampler = self.default_sampler();
self.request_texture(path_str, sampler)
}

/// Load texture from file, with custom `Sampler`.
/// Supported file formats are: PNG, JPEG, GIF, WEBP, PPM, TIFF, TGA, BMP, ICO, HDR.
pub fn load_texture_with_sampler<P: AsRef<Path>>(
&mut self,
path_str: P,
sampler: Sampler,
) -> Texture<[f32; 4]> {
self.request_texture(path_str, sampler)
}

/// Load cubemap from files.
Expand Down