emilib
Public Member Functions | List of all members
emilib::ShaderMngr Class Reference

#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::Programget_ff (int flags)
 Construct shader from source. More...
 
gl::Programget_file (const std::string &name)
 Construct shader from shader_dir/name.shader. Memoizes.
 
void reload_all ()
 

Detailed Description

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.

Member Function Documentation

◆ get_ff()

gl::Program* emilib::ShaderMngr::get_ff ( int  flags)

Construct shader from source.

Construct shader from source. Fixed function emulation using gl::FF combinations. Memoizes.

◆ reload_all()

void emilib::ShaderMngr::reload_all ( )

Reload all .shader files. You shouldn't need to call this if you are using update(). update() will hot-reload any changed files on-the-fly.


The documentation for this class was generated from the following file: