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, 31 insertions, 3 deletions
diff --git a/engine/src/shader.rs b/engine/src/shader.rs
index a0066f1..89f7b7c 100644
--- a/engine/src/shader.rs
+++ b/engine/src/shader.rs
@@ -7,6 +7,11 @@ use ecs::Component;
use crate::shader_preprocessor::{Error as ShaderPreprocessorError, ShaderPreprocessor};
+const VERTEX_SHADER_FILE: &str = "vertex.glsl";
+const FRAGMENT_SHADER_FILE: &str = "fragment.glsl";
+
+const SHADER_DIR: &str = "engine";
+
/// Shader program
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default, Component)]
pub struct Program
@@ -16,10 +21,33 @@ pub struct Program
impl Program
{
- #[must_use]
- pub fn new() -> Self
+ /// Creates a new shader program with the default shaders.
+ ///
+ /// # Errors
+ /// Returns `Err` if:
+ /// - Reading a default shader file Fails
+ /// - Preprocessing a shader fails.
+ pub fn new() -> Result<Self, Error>
{
- Self { shaders: Vec::new() }
+ let mut program = Self { shaders: Vec::new() };
+
+ program.push_shader(
+ Shader::read_shader_file(
+ Kind::Vertex,
+ &Path::new(SHADER_DIR).join(VERTEX_SHADER_FILE),
+ )?
+ .preprocess()?,
+ );
+
+ program.push_shader(
+ Shader::read_shader_file(
+ Kind::Fragment,
+ &Path::new(SHADER_DIR).join(FRAGMENT_SHADER_FILE),
+ )?
+ .preprocess()?,
+ );
+
+ Ok(program)
}
pub fn push_shader(&mut self, shader: Shader)