cgv
Loading...
Searching...
No Matches
shader_library.cxx
1#include "shader_library.h"
2
3namespace cgv {
4namespace render {
5
6shader_library::shader_library() {
7
8 shaders.clear();
9}
10
11shader_library::~shader_library() {
12
13 shaders.clear();
14}
15
16void shader_library::clear(context& ctx) {
17
18 shaders.clear();
19}
20
21bool shader_library::add(const std::string& name, const std::string& file, const shader_define_map& defines) {
22
23 if(shaders.find(name) == shaders.end()) {
24 shader_info elem;
25 elem.filename = file;
26 elem.defines = defines;
27 shaders.insert({ name, elem });
28 return true;
29 }
30 return false;
31}
32
33bool shader_library::load_all(context& ctx, const std::string& where) {
34
35 bool success = true;
36 for(auto& elem : shaders) {
37 shader_info& si = elem.second;
38 success &= load(ctx, si.prog, si.filename, si.defines, true, where);
39 }
40
41 return success;
42}
43
44bool shader_library::reload(context& ctx, const std::string& name, const shader_define_map& defines, const std::string& where) {
45
46 auto it = shaders.find(name);
47 if(it != shaders.end()) {
48 shader_info& si = (*it).second;
49 si.defines = defines;
50 return load(ctx, si.prog, si.filename, si.defines, true, where);
51 }
52 return false;
53}
54
55bool shader_library::reload_all(context& ctx, const std::string& where) {
56
57 bool success = true;
58 for(auto& elem : shaders) {
59 shader_info& si = elem.second;
60 success &= load(ctx, si.prog, si.filename, si.defines, true, where);
61 }
62
63 return success;
64}
65
66}
67}
std::map< std::string, std::string > shader_define_map
typedef for shader define map data structure
Definition shader_code.h:52
the cgv namespace
Definition print.h:11