/// Builds an OpenGL shader program using GLSL sources.
///
/// The shader program is created, compiled and linked. If no geometry shader
/// is provided it will be omitted from the linking. 
/// Each shader's source code must be free of null bytes or there will errors
/// upon conversion to CStrings (a requirement of OpenGL C bindings).
///
/// Shaders are detached and deleted after program is linked.
Builds an OpenGL shader program using GLSL sources.
The shader program is created, compiled and linked. If no geometry shader
is provided it will be omitted from the linking.
Each shader's source code must be free of null bytes or there will errors
upon conversion to CStrings (a requirement of OpenGL C bindings).

Shaders are detached and deleted after program is linked.
Builds an OpenGL shader program using GLSL sources . The shader program is created compiled and linked . If no geometry shader is provided it will be omitted from the linking . Each shader ' s source code must be free of null bytes or there will errors upon conversion to CStrings ( a requirement of OpenGL C bindings ) . Shaders are detached and deleted after program is linked .
pub fn program_from_sources(vert_source: String, 
                            frag_source: String, 
                            geom_source: Option<String>)
                            -> Result<GLuint, EngineError> {
    // Compile mandatory shaders
    let vert_shader = compile_source(vert_source, ShaderType::VertexShader)?;
    let frag_shader = compile_source(frag_source, ShaderType::FragmentShader)?;
    // Optionally compile the geometry shader
    let geom_shader = match geom_source {
        Some(source) => {
            // Wrap the result in Some, otherwise return the error
            match compile_source(source, ShaderType::GeometryShader) {
                Ok(shader) => Some(shader),
                Err(err) => return Err(err),
            }
        },
        // Forward the None value to linking
        None => None,
    };
    // Link the program and save the Result
    let program = link_program(vert_shader, frag_shader, geom_shader);
    // Cleanup OpenGL objects
    unsafe {
        gl::DeleteShader(vert_shader);
        gl::DeleteShader(frag_shader);
        if let Some(shader) = geom_shader {
            gl::DeleteShader(shader);
        }
    }
    // Forward the linking Result
    program
}
pub fn program_from_sources ( vert_source : String , frag_source : String , geom_source : Option < String > ) -> Result < GLuint , EngineError > { // Compile mandatory shaders let vert_shader = compile_source ( vert_source , ShaderType :: VertexShader ) ? ; let frag_shader = compile_source ( frag_source , ShaderType :: FragmentShader ) ? ; // Optionally compile the geometry shader let geom_shader = match geom_source { Some ( source ) => { // Wrap the result in Some, otherwise return the error match compile_source ( source , ShaderType :: GeometryShader ) { Ok ( shader ) => Some ( shader ) , Err ( err ) => return Err ( err ) , } } , // Forward the None value to linking None => None , } ; // Link the program and save the Result let program = link_program ( vert_shader , frag_shader , geom_shader ) ; // Cleanup OpenGL objects unsafe { gl :: DeleteShader ( vert_shader ) ; gl :: DeleteShader ( frag_shader ) ; if let Some ( shader ) = geom_shader { gl :: DeleteShader ( shader ) ; } } // Forward the linking Result program }
Builds an OpenGL shader program using GLSL sources.
Builds an OpenGL shader program using GLSL sources .
vert_source
String
frag_source
String
geom_source
Option<String>