emilib
shader_mngr.hpp
1 // By Emil Ernerfeldt 2014-2016
2 // LICENSE:
3 // This software is dual-licensed to the public domain and under the following
4 // license: you are granted a perpetual, irrevocable license to copy, modify,
5 // publish, and distribute this file as you see fit.
6 // HISTORY:
7 // Created in 2014 for Ghostel
8 // Moved into emilib in 2016
9 
10 #pragma once
11 
12 #include <memory>
13 #include <string>
14 #include <unordered_map>
15 
16 #include <emilib/gl_lib_fwd.hpp>
17 
18 namespace emilib {
19 
20 class DelayedDirWatcher;
21 using DelayedDirWatcher_UP = std::unique_ptr<DelayedDirWatcher>;
22 
24 gl::ProgramSource load_shader_file(const std::string& shader_dir, const std::string& name);
25 
75 {
76 public:
78  explicit ShaderMngr(const std::string& shader_dir);
79  ~ShaderMngr();
80 
82  void update();
83 
85  // gl::Program* get(const gl::ProgramSource& program_source);
86 
88  // gl::Program* get_source(const std::string& name, const std::string& vs, const std::string& fs) const;
89 
91  gl::Program* get_ff(int flags);
92 
94  gl::Program* get_file(const std::string& name);
95 
98  void reload_all();
99 
100 private:
101  // using SourceMap = std::unordered_map<gl::ProgramSource, gl::Program_UP>;
102  using FFMap = std::unordered_map<int, gl::Program_UP>;
103  using FileMap = std::unordered_map<std::string, gl::Program_UP>;
104 
105  std::string _shader_dir;
106  DelayedDirWatcher_UP _dir_watcher;
107  // SourceMap _source_map;
108  FFMap _ff_map;
109  FileMap _file_map;
110 };
111 
112 } // namespace emilib
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.
ShaderMngr(const std::string &shader_dir)
Look for .shader files in shader_dir.
Definition: gl_lib.hpp:137
Definition: shader_mngr.hpp:74
gl::Program * get_file(const std::string &name)
Construct shader from shader_dir/name.shader. Memoizes.
Definition: gl_lib_fwd.hpp:48
Definition: coroutine.hpp:18