fn link_program(vert_shader: GLuint, 
                frag_shader: GLuint, 
                geom_shader: Option<GLuint>) 
                -> Result<GLuint, EngineError> {
    
    let program: GLuint;
    unsafe {
        // Create and link the program
        program = gl::CreateProgram();
        gl::AttachShader(program, vert_shader);
        gl::AttachShader(program, frag_shader);
        if let Some(shader) = geom_shader {
            gl::AttachShader(program, shader);
        }
        gl::LinkProgram(program);

        // Check for linking errors
        let mut link_success: GLint = 1;
        gl::GetProgramiv(program, gl::LINK_STATUS, &mut link_success);
        
        // If failed, get the log
        if link_success == 0 {
        
            let mut log_len: GLint = 0;
            gl::GetProgramiv(program, gl::INFO_LOG_LENGTH, &mut log_len);
            let mut log_buffer: Vec<u8> = Vec::with_capacity(log_len as usize + 1);
            // Fill the buffer with spaces
            log_buffer.extend([b' '].iter().cycle().take(log_len as usize));
            let error_log: CString = CString::from_vec_unchecked(log_buffer);
            
            // Load the log into CString
            gl::GetProgramInfoLog(program, log_len, 
                                  std::ptr::null_mut(),
                                  error_log.as_ptr() as *mut GLchar);

            // Convert CString to String
            let error = error_log.to_string_lossy().into_owned();
            // Return as linking error
            println!("=====Linking=====\n{}", error);
            return Err(EngineError::ShaderLink(error));
        }
        
        // Detach shader files from the program
        gl::DetachShader(program, vert_shader);
        gl::DetachShader(program, frag_shader);
        if let Some(shader) = geom_shader {
            gl::DetachShader(program, shader);
        }
    }
    Ok(program)
}
/// Creates a shader program and links shaders to it.
///
/// Shaders are detached after successful linking.
Creates a shader program and links shaders to it.
Shaders are detached after successful linking.
Creates a shader program and links shaders to it . Shaders are detached after successful linking .
fn link_program(vert_shader: GLuint, 
                frag_shader: GLuint, 
                geom_shader: Option<GLuint>) 
                -> Result<GLuint, EngineError> {
    let program: GLuint;
    unsafe {
        // Create and link the program
        program = gl::CreateProgram();
        gl::AttachShader(program, vert_shader);
        gl::AttachShader(program, frag_shader);
        if let Some(shader) = geom_shader {
            gl::AttachShader(program, shader);
        }
        gl::LinkProgram(program);
        // Check for linking errors
        let mut link_success: GLint = 1;
        gl::GetProgramiv(program, gl::LINK_STATUS, &mut link_success);
        // If failed, get the log
        if link_success == 0 {
            let mut log_len: GLint = 0;
            gl::GetProgramiv(program, gl::INFO_LOG_LENGTH, &mut log_len);
            let mut log_buffer: Vec<u8> = Vec::with_capacity(log_len as usize + 1);
            // Fill the buffer with spaces
            log_buffer.extend([b' '].iter().cycle().take(log_len as usize));
            let error_log: CString = CString::from_vec_unchecked(log_buffer);
            // Load the log into CString
            gl::GetProgramInfoLog(program, log_len, 
                                  std::ptr::null_mut(),
                                  error_log.as_ptr() as *mut GLchar);
            // Convert CString to String
            let error = error_log.to_string_lossy().into_owned();
            // Return as linking error
            println!("=====Linking=====\n{}", error);
            return Err(EngineError::ShaderLink(error));
        }
        // Detach shader files from the program
        gl::DetachShader(program, vert_shader);
        gl::DetachShader(program, frag_shader);
        if let Some(shader) = geom_shader {
            gl::DetachShader(program, shader);
        }
    }
    Ok(program)
}
fn link_program ( vert_shader : GLuint , frag_shader : GLuint , geom_shader : Option < GLuint > ) -> Result < GLuint , EngineError > { let program : GLuint ; unsafe { // Create and link the program program = gl :: CreateProgram ( ) ; gl :: AttachShader ( program , vert_shader ) ; gl :: AttachShader ( program , frag_shader ) ; if let Some ( shader ) = geom_shader { gl :: AttachShader ( program , shader ) ; } gl :: LinkProgram ( program ) ; // Check for linking errors let mut link_success : GLint = 1 ; gl :: GetProgramiv ( program , gl :: LINK_STATUS , & mut link_success ) ; // If failed, get the log if link_success == 0 { let mut log_len : GLint = 0 ; gl :: GetProgramiv ( program , gl :: INFO_LOG_LENGTH , & mut log_len ) ; let mut log_buffer : Vec < u8 > = Vec :: with_capacity ( log_len as usize + 1 ) ; // Fill the buffer with spaces log_buffer . extend ( [ b' ' ] . iter ( ) . cycle ( ) . take ( log_len as usize ) ) ; let error_log : CString = CString :: from_vec_unchecked ( log_buffer ) ; // Load the log into CString gl :: GetProgramInfoLog ( program , log_len , std :: ptr :: null_mut ( ) , error_log . as_ptr ( ) as * mut GLchar ) ; // Convert CString to String let error = error_log . to_string_lossy ( ) . into_owned ( ) ; // Return as linking error println ! ( " \n " error ) ; return Err ( EngineError :: ShaderLink ( error ) ) ; } // Detach shader files from the program gl :: DetachShader ( program , vert_shader ) ; gl :: DetachShader ( program , frag_shader ) ; if let Some ( shader ) = geom_shader { gl :: DetachShader ( program , shader ) ; } } Ok ( program ) }
Creates a shader program and links shaders to it.
Creates a shader program and links shaders to it .
vert_shader
GLuint
frag_shader
GLuint
geom_shader
Option<GLuint>
vert_shader
GLuint
frag_shader
GLuint
geom_shader
Option<GLuint>