diff options
author | HampusM <hampus@hampusmat.com> | 2024-11-23 20:20:24 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-11-23 20:57:27 +0100 |
commit | 999264a46f9a545771c6710b0893ca32cf6e7ee3 (patch) | |
tree | 44d1a0787e8670fbf645c9eca22fcffceec0f96d /engine/src/shader.rs | |
parent | af121c3a3aebdd1e10c768530ee0fbab5c8d6677 (diff) |
refactor(engine): move & improve glsl preprocessing
Diffstat (limited to 'engine/src/shader.rs')
-rw-r--r-- | engine/src/shader.rs | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/engine/src/shader.rs b/engine/src/shader.rs index 89f7b7c..b43d538 100644 --- a/engine/src/shader.rs +++ b/engine/src/shader.rs @@ -5,7 +5,10 @@ use std::path::{Path, PathBuf}; use ecs::Component; -use crate::shader_preprocessor::{Error as ShaderPreprocessorError, ShaderPreprocessor}; +use crate::opengl::glsl::{ + preprocess as glsl_preprocess, + PreprocessingError as GlslPreprocessingError, +}; const VERTEX_SHADER_FILE: &str = "vertex.glsl"; const FRAGMENT_SHADER_FILE: &str = "fragment.glsl"; @@ -116,23 +119,22 @@ impl Shader /// Returns `Err` if preprocessing fails. pub fn preprocess(self) -> Result<Self, Error> { - let shader_preprocessor = ShaderPreprocessor::new( - self.file - .parent() - .ok_or(Error::SourcePathHasNoParent)? - .to_path_buf(), - ); - - let source_preprocessed = shader_preprocessor - .preprocess(self.source, &self.file) - .map_err(|err| Error::PreprocessFailed { - source: err, - shader_file: self.file.clone(), - })?; + let parent_dir = self + .file + .parent() + .ok_or(Error::SourcePathHasNoParent)? + .to_path_buf(); + + let source_preprocessed = + glsl_preprocess(self.source, &|path| std::fs::read(parent_dir.join(path))) + .map_err(|err| Error::PreprocessFailed { + source: err, + shader_file: self.file.clone(), + })?; Ok(Self { kind: self.kind, - source: source_preprocessed, + source: source_preprocessed.into_owned(), file: self.file.clone(), }) } @@ -177,7 +179,7 @@ pub enum Error PreprocessFailed { #[source] - source: ShaderPreprocessorError, + source: GlslPreprocessingError, shader_file: PathBuf, }, |