Detect wrong image path

This commit is contained in:
Piotr 2020-10-15 17:36:20 +02:00
parent adda49fa15
commit 649c42ddc4
1 changed files with 9 additions and 1 deletions

View File

@ -1,9 +1,14 @@
use gl; use gl;
use image2::image::Image; use image2::image::Image;
use image2::{io, ImagePtr, Rgb, Rgba}; use image2::{io, ImagePtr, Rgb, Rgba};
use log::info; use log::{info,error};
use std::os::raw::c_void; use std::os::raw::c_void;
pub fn path_exists(path: &std::path::Path) -> bool {
let meta = std::fs::metadata(path);
meta.is_ok()
}
pub unsafe fn load_texture(path: &str, file_format: &str) -> u32 { pub unsafe fn load_texture(path: &str, file_format: &str) -> u32 {
info!("Loading texture: {}", path); info!("Loading texture: {}", path);
let mut id = 0; let mut id = 0;
@ -75,6 +80,9 @@ pub unsafe fn load_cubemap(faces: &[&str]) -> u32 {
gl::BindTexture(gl::TEXTURE_CUBE_MAP, texture_id); gl::BindTexture(gl::TEXTURE_CUBE_MAP, texture_id);
for (i, face) in faces.iter().enumerate() { for (i, face) in faces.iter().enumerate() {
if !path_exists(std::path::Path::new(&face)) {
error!("There is no file {}", face);
}
let (data, dim) = { let (data, dim) = {
let img: ImagePtr<u8, Rgb> = io::read_u8(face).unwrap(); let img: ImagePtr<u8, Rgb> = io::read_u8(face).unwrap();
let img_data = img.data().to_vec(); let img_data = img.data().to_vec();