summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt5
-rw-r--r--source/dw/app/getshdprg.rs65
-rw-r--r--source/dw/app/shader/main.frag.glsl (renamed from shader/main.frag.glsl)2
-rw-r--r--source/dw/app/shader/main.vert.glsl (renamed from shader/main.vert.glsl)2
-rwxr-xr-xvalidateShaders.py6
5 files changed, 56 insertions, 24 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 81de880..e13cf56 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,8 @@
+# 0.2.0
+
+* Embed shaders;
+* Update shader validation script;
+
# 0.1.0
* Bump minor version;
diff --git a/source/dw/app/getshdprg.rs b/source/dw/app/getshdprg.rs
index 2e02ff8..76eb5cf 100644
--- a/source/dw/app/getshdprg.rs
+++ b/source/dw/app/getshdprg.rs
@@ -4,39 +4,50 @@ use crate::dw::{app::App,datpth};
extern crate gl;
-use gl::{AttachShader,COMPILE_STATUS,CompileShader,CreateProgram,CreateShader,DeleteShader,FALSE,FRAGMENT_SHADER,GetShaderiv,LinkProgram,ShaderSource,VERTEX_SHADER};
-use gl::types::{GLchar,GLenum,GLint,GLuint};
-use std::fs::read;
+use gl::{AttachShader,COMPILE_STATUS,CompileShader,COMPUTE_SHADER,CreateProgram,CreateShader,DeleteShader,FALSE,FRAGMENT_SHADER,GEOMETRY_SHADER,GetShaderInfoLog,GetShaderiv,INFO_LOG_LENGTH,LinkProgram,ShaderSource,TESS_CONTROL_SHADER,TESS_EVALUATION_SHADER,VERTEX_SHADER};
+use gl::types::{GLchar,GLenum,GLint,GLsizei,GLuint};
+use libc::{STDERR_FILENO,write};
+use std::alloc::{alloc,dealloc,Layout};
+use std::ffi::c_void;
use std::ptr::{addr_of,null};
impl App {
pub fn getshdprg(&mut self) -> GLuint {
eprintln!("compiling shaders");
- let cmpshd = |nam: & str,typ:GLenum| -> GLuint {
+ let cmpshd = |nam: & str| -> GLuint {
+ let extoff = nam.find('.').expect("unable to find file extension seperator")+0x1;
+ let filext = &nam[extoff..];
+ let typ = match filext {
+ "comp" => COMPUTE_SHADER,
+ "frag" => FRAGMENT_SHADER,
+ "geom" => GEOMETRY_SHADER,
+ "tesc" => TESS_CONTROL_SHADER,
+ "tese" => TESS_EVALUATION_SHADER,
+ "vert" => VERTEX_SHADER,
+ _ => panic!("invalid shader file extension \"{}\"",filext),
+ };
+
let typstr = match typ {
FRAGMENT_SHADER => "fragment",
VERTEX_SHADER => "vertex",
- _ => panic!("invalid shader type {}",typ),
+ _ => unreachable!(),
};
let filext = match typ {
FRAGMENT_SHADER => "frag",
VERTEX_SHADER => "vert",
- _ => panic!("invalid shader type {}",typ),
+ _ => unreachable!(),
};
- let mut pth = String::new();
- pth.push_str(datpth());
- pth.push_str("/shader/");
- pth.push_str(nam);
- pth.push( '.');
- pth.push_str(filext);
- pth.push_str(".glsl");
+ eprintln!("compiling {} shader \"{}\"",typstr,nam);
- eprintln!("compiling {} shader at \"{}\"",typstr,pth);
-
- let src = read(pth).expect("unable to read shader at");
+ //let src = read(pth).expect("unable to read shader at");
+ let src = match nam {
+ "main.frag" => include_bytes!("shader/main.frag.glsl").to_vec(),
+ "main.vert" => include_bytes!("shader/main.vert.glsl").to_vec(),
+ _ => panic!("shader not found"),
+ };
unsafe {
let shd = CreateShader(typ);
@@ -47,14 +58,30 @@ impl App {
let mut sts:GLint = 0x0;
GetShaderiv(shd,COMPILE_STATUS,&mut sts);
- if sts == FALSE as GLint {panic!("unable to compile shader");}
+ if sts == FALSE as GLint {
+ let mut len: GLint = 0x0;
+ GetShaderiv(shd,INFO_LOG_LENGTH,&mut len);
+
+ let lay = Layout::from_size_align(len as usize,0x1).unwrap();
+
+ let log = alloc(lay);
+ GetShaderInfoLog(shd,len,null::<GLsizei>() as *mut GLsizei,log as *mut GLchar);
+
+ eprint!("unable able to compile shader:\n");
+ write(STDERR_FILENO,log as *const c_void,len as usize);
+ eprintln!();
+
+ dealloc(log,lay);
+
+ panic!("unable to compile shader");
+ }
return shd;
}
};
- let frgshd = cmpshd("main",FRAGMENT_SHADER);
- let vtxshd = cmpshd("main",VERTEX_SHADER);
+ let frgshd = cmpshd("main.frag");
+ let vtxshd = cmpshd("main.vert");
unsafe {
let prg = CreateProgram();
diff --git a/shader/main.frag.glsl b/source/dw/app/shader/main.frag.glsl
index e81d967..201ce9f 100644
--- a/shader/main.frag.glsl
+++ b/source/dw/app/shader/main.frag.glsl
@@ -3,5 +3,5 @@
out vec4 col;
void main() {
- col = vec4(0.7137f,0.0941f,0.2000f,1.0f);
+ col = vec4(0.7137f,0.0941f,0.2000f,1.0f);
}
diff --git a/shader/main.vert.glsl b/source/dw/app/shader/main.vert.glsl
index d6c02c9..fb6999c 100644
--- a/shader/main.vert.glsl
+++ b/source/dw/app/shader/main.vert.glsl
@@ -3,5 +3,5 @@
in vec3 pos;
void main() {
- gl_Position = vec4(pos.x,pos.y,pos.z,1.0f);
+ gl_Position = vec4(pos.x,pos.y,pos.z,1.0f);
}
diff --git a/validateShaders.py b/validateShaders.py
index 64d91bf..39bf4e2 100755
--- a/validateShaders.py
+++ b/validateShaders.py
@@ -5,10 +5,10 @@ from subprocess import PIPE,run
def validate(path:str):
print("validating \"",path,"\"... ",end='',sep='')
- path = "shader/" + path + ".glsl"
- prog = "glslangValidator"
+ path = "source/dw/app/shader/" + path + ".glsl"
+ program = "glslangValidator"
- status = run([prog,path],stdout=PIPE)
+ status = run([program,path],stdout=PIPE)
result = status.returncode
if result != 0x0: