presets: properly trim shader name if given through pragma

This commit is contained in:
chyyran 2024-09-17 18:24:01 -04:00 committed by Ronny Chan
parent e0c97f77b4
commit 87e0405675
2 changed files with 3 additions and 2 deletions

View file

@ -81,6 +81,7 @@ impl SourceOutput for String {
pub(crate) fn load_shader_source(path: impl AsRef<Path>) -> Result<ShaderSource, PreprocessError> { pub(crate) fn load_shader_source(path: impl AsRef<Path>) -> Result<ShaderSource, PreprocessError> {
let source = read_source(path)?; let source = read_source(path)?;
let meta = pragma::parse_pragma_meta(&source)?; let meta = pragma::parse_pragma_meta(&source)?;
let text = stage::process_stages(&source)?; let text = stage::process_stages(&source)?;
let parameters = FastHashMap::from_iter(meta.parameters.into_iter().map(|p| (p.id.clone(), p))); let parameters = FastHashMap::from_iter(meta.parameters.into_iter().map(|p| (p.id.clone(), p)));

View file

@ -110,12 +110,12 @@ pub(crate) fn parse_pragma_meta(source: impl AsRef<str>) -> Result<ShaderMeta, P
} }
} }
if line.starts_with("#pragma name ") { if let Some(pragma_name) = line.strip_prefix("#pragma name ") {
if name.is_some() { if name.is_some() {
return Err(PreprocessError::DuplicatePragmaError(line.into())); return Err(PreprocessError::DuplicatePragmaError(line.into()));
} }
name = Some(ShortString::from(line.trim())) name = Some(ShortString::from(pragma_name.trim()))
} }
} }