Struct dzahui::simulation::shader::Shader
source · pub(crate) struct Shader {
pub(crate) id: u32,
}
Expand description
General information
A shader instance stores the id representing a combination of a vertex and fragment shader compiled (OpenGL Shading Language) and attached to an OpenGL program. Later on, an instance of such shader can be attached to an OpenGL context to use in conjunction with a series of vertices to draw to screen.
Fields
id
- An id field setup by OpenGL to uniquely identify shaders being passed.
Fields§
§id: u32
Implementations§
source§impl Shader
impl Shader
sourcepub fn new(
vertex_path: impl AsRef<str>,
fragment_path: impl AsRef<str>
) -> Result<Self, Error>
pub fn new(
vertex_path: impl AsRef<str>,
fragment_path: impl AsRef<str>
) -> Result<Self, Error>
General information
Creates a new shader program composed of both a vertex and a fragment shader. Since it uses gl
crate, it’s necessary that an openGL context has
been initialized. Unsafe part stops rust from caching errors while compiling shaders, therefore print statements will be sent to the terminal containing
a message in case an error has happened. Later use of faulty shaders will stop the program from running, but debbuging becomes hard since little
information is provided by the gl
crate. Should enable logging errors at a later date.
Regarding the steps the function uses: first it opens and read files to strings. Then, shaders are casted to CStrings. After that, each shader is sent
to be compiled and linked to a u32 variable. Finally, the u32 varaibles are linked to an OpenGL program with an id and cache is erased (compiled programs
are already associated to a program, therefore can be safely erased). This last id is returned inside Shader structure.
Parameters
vertex_path
- Path to a vertex shader file.fragment_path
- Path to a fragment shader file.
sourcepub fn use_shader(&self)
pub fn use_shader(&self)
Use a certain pair of shaders identified by id. Program can have multiple shaders at once, but only one can be used at a time.