summaryrefslogtreecommitdiff
path: root/engine/src/shader.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/shader.rs')
-rw-r--r--engine/src/shader.rs34
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,
},