relative include

master
Tom Gowan 6 years ago
parent 203f0c8074
commit 0f9f2658dc

@ -3,7 +3,7 @@ use shaderc::{IncludeType, ResolvedInclude};
use shaderc::{ShaderKind, CompileOptions}; use shaderc::{ShaderKind, CompileOptions};
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::path::Path; use std::path::{Path, PathBuf};
pub fn compile<T>(path: T, shader_kind: ShaderKind) -> Result<Vec<u32>, CompileError> pub fn compile<T>(path: T, shader_kind: ShaderKind) -> Result<Vec<u32>, CompileError>
where where
@ -34,15 +34,20 @@ where
fn get_include( fn get_include(
path: &str, path: &str,
include_type: IncludeType, include_type: IncludeType,
_folder_path: &str, folder_path: &str,
_depth: usize, depth: usize,
) -> Result<ResolvedInclude, String> { ) -> Result<ResolvedInclude, String> {
match include_type { match include_type {
IncludeType::Relative => { IncludeType::Relative => {
let p = Path::new(path); let p = Path::new(path);
let mut folder = PathBuf::from(folder_path);
folder.pop();
folder.push(p);
let p = folder;
if !p.is_file() { if !p.is_file() {
return Err("Include doesn't point to file".to_string()); return Err("Include doesn't point to file".to_string());
} }
let resolved_name = p let resolved_name = p
.to_str() .to_str()
.ok_or("Path has invalid characters".to_string())? .ok_or("Path has invalid characters".to_string())?

Loading…
Cancel
Save