fn shader_from_source(gl: &gl::Gl, source: &CStr, kind: GLuint) -> Result<GLuint, GlError> {
    let id = unsafe { gl.CreateShader(kind) };

    unsafe {
        gl.ShaderSource(id, 1, &source.as_ptr(), std::ptr::null());
        gl.CompileShader(id);
    }

    let mut success: GLint = 1;
    unsafe {
        gl.GetShaderiv(id, gl::COMPILE_STATUS, &mut success);
    }

    if success == 0 {
        let mut len = 0;
        unsafe {
            gl.GetShaderiv(id, gl::INFO_LOG_LENGTH, &mut len);
        }

        let error = create_whitespace_cstring(len as usize)?;

        unsafe {
            gl.GetShaderInfoLog(id, len, std::ptr::null_mut(), error.as_ptr() as *mut GLchar);
        }

        return Err(GlError::ShaderCompilation {
            message: error.to_string_lossy().to_string(),
        });
    }

    Ok(id)
}
/// Create a new OpenGL shader from glsl source code
Create a new OpenGL shader from glsl source code
Create a new OpenGL shader from glsl source code
fn shader_from_source(gl: &gl::Gl, source: &CStr, kind: GLuint) -> Result<GLuint, GlError> {
    let id = unsafe { gl.CreateShader(kind) };
    unsafe {
        gl.ShaderSource(id, 1, &source.as_ptr(), std::ptr::null());
        gl.CompileShader(id);
    }
    let mut success: GLint = 1;
    unsafe {
        gl.GetShaderiv(id, gl::COMPILE_STATUS, &mut success);
    }
    if success == 0 {
        let mut len = 0;
        unsafe {
            gl.GetShaderiv(id, gl::INFO_LOG_LENGTH, &mut len);
        }
        let error = create_whitespace_cstring(len as usize)?;
        unsafe {
            gl.GetShaderInfoLog(id, len, std::ptr::null_mut(), error.as_ptr() as *mut GLchar);
        }
        return Err(GlError::ShaderCompilation {
            message: error.to_string_lossy().to_string(),
        });
    }
    Ok(id)
}
fn shader_from_source ( gl : & gl :: Gl , source : & CStr , kind : GLuint ) -> Result < GLuint , GlError > { let id = unsafe { gl . CreateShader ( kind ) } ; unsafe { gl . ShaderSource ( id , 1 , & source . as_ptr ( ) , std :: ptr :: null ( ) ) ; gl . CompileShader ( id ) ; } let mut success : GLint = 1 ; unsafe { gl . GetShaderiv ( id , gl :: COMPILE_STATUS , & mut success ) ; } if success == 0 { let mut len = 0 ; unsafe { gl . GetShaderiv ( id , gl :: INFO_LOG_LENGTH , & mut len ) ; } let error = create_whitespace_cstring ( len as usize ) ? ; unsafe { gl . GetShaderInfoLog ( id , len , std :: ptr :: null_mut ( ) , error . as_ptr ( ) as * mut GLchar ) ; } return Err ( GlError :: ShaderCompilation { message : error . to_string_lossy ( ) . to_string ( ) , } ) ; } Ok ( id ) }
Create a new OpenGL shader from glsl source code
Create a new OpenGL shader from glsl source code
gl
&gl::Gl
source
&CStr
kind
GLuint
gl
&gl::Gl
source
&CStr
kind
GLuint