emilib
|
#include <shader_mngr.hpp>
Public Member Functions | |
ShaderMngr (const std::string &shader_dir) | |
Look for .shader files in shader_dir. | |
void | update () |
call this periodically (e.g. every frame) to detect and reload modified shader files. | |
gl::Program * | get_ff (int flags) |
Construct shader from source. More... | |
gl::Program * | get_file (const std::string &name) |
Construct shader from shader_dir/name.shader. Memoizes. | |
void | reload_all () |
ShaderMngr is a high-level library of emilib, meaning it is NOT a stand-alone library. Instead, it depends on many other parts of emilib.
ShaderMngr's job is to encapsulate loading, memoization and reloading of shader files.
In particular, you can put your gl shaders in .shader files which ShaderMngr can load. If you modify the .shader file, ShaderMngr can detect it and automatically reload it for you. This is very useful for quickly trying new things without having to restart your app.
Example of a simple .shader file: vertex_shader: """ vs_in vec2 a_pos; vs_in vec2 a_tc;
vs_out vec2 v_tc;
uniform mat4 u_mvp;
void main() { gl_Position = u_mvp * vec4(a_pos, 0.0, 1.0); v_tc = a_tc; } """
fragment_shader: """ fs_in vec2 v_tc;
uniform sampler2D u_sampler; uniform mediump vec4 u_color;
void main() { lowp vec4 color = texture2D(u_sampler, v_tc); color *= u_color; out_FragColor = color; } """
Additionally, a .shader file can include raw GLSL code with this (on top of the .shader file):
includes: [ "first.glsl", "second.glsl" ]
This will inject the contents of the files "first.glsl" and "second.glsl" into the top of both the fragment and vertex shader code. This is useful for including a library of GLSL functions. All includes are relative to the shader_dir given to ShaderMngr.
gl::Program* emilib::ShaderMngr::get_ff | ( | int | flags | ) |
Construct shader from source.
Construct shader from source. Fixed function emulation using gl::FF combinations. Memoizes.
void emilib::ShaderMngr::reload_all | ( | ) |