diff options
Diffstat (limited to 'source/dw/app/getshdprg.rs')
-rw-r--r-- | source/dw/app/getshdprg.rs | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/source/dw/app/getshdprg.rs b/source/dw/app/getshdprg.rs index 76eb5cf..2da6095 100644 --- a/source/dw/app/getshdprg.rs +++ b/source/dw/app/getshdprg.rs @@ -1,15 +1,15 @@ // Copyright 2023 Gabriel Jensen. -use crate::dw::{app::App,datpth}; +use crate::dw::app::App; extern crate gl; -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 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, 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}; +use std::ptr::{addr_of, null}; impl App { pub fn getshdprg(&mut self) -> GLuint { @@ -25,7 +25,7 @@ impl App { "tesc" => TESS_CONTROL_SHADER, "tese" => TESS_EVALUATION_SHADER, "vert" => VERTEX_SHADER, - _ => panic!("invalid shader file extension \"{}\"",filext), + _ => panic!("invalid shader file extension \"{}\"", filext), }; let typstr = match typ { @@ -34,13 +34,7 @@ impl App { _ => unreachable!(), }; - let filext = match typ { - FRAGMENT_SHADER => "frag", - VERTEX_SHADER => "vert", - _ => unreachable!(), - }; - - eprintln!("compiling {} shader \"{}\"",typstr,nam); + eprintln!("compiling {} shader \"{}\"", typstr, nam); //let src = read(pth).expect("unable to read shader at"); let src = match nam { @@ -52,26 +46,26 @@ impl App { unsafe { let shd = CreateShader(typ); let srcptr = src.as_ptr(); - ShaderSource(shd,0x1,addr_of!(srcptr) as *const *const GLchar,null::<GLint>()); + ShaderSource(shd, 0x1, addr_of!(srcptr) as *const *const GLchar, null::<GLint>()); CompileShader(shd); - let mut sts:GLint = 0x0; - GetShaderiv(shd,COMPILE_STATUS,&mut sts); + let mut sts: GLint = 0x0; + GetShaderiv(shd, COMPILE_STATUS, &mut sts); if sts == FALSE as GLint { let mut len: GLint = 0x0; - GetShaderiv(shd,INFO_LOG_LENGTH,&mut len); + GetShaderiv(shd, INFO_LOG_LENGTH, &mut len); - let lay = Layout::from_size_align(len as usize,0x1).unwrap(); + 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); + 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); + write(STDERR_FILENO, log as *const c_void, len as usize); eprintln!(); - dealloc(log,lay); + dealloc(log, lay); panic!("unable to compile shader"); } @@ -85,8 +79,8 @@ impl App { unsafe { let prg = CreateProgram(); - AttachShader(prg,frgshd); - AttachShader(prg,vtxshd); + AttachShader(prg, frgshd); + AttachShader(prg, vtxshd); LinkProgram(prg); DeleteShader(frgshd); |