Easy3D 2.6.1
Loading...
Searching...
No Matches
shader_manager.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_RENDERER_SHADER_MANAGER_H
28#define EASY3D_RENDERER_SHADER_MANAGER_H
29
30#include <string>
31#include <unordered_map>
32
33#include <easy3d/renderer/shader_program.h>
34
35
36namespace easy3d {
37
38 class ShaderProgram;
39
46 {
47 public:
53 static ShaderProgram* get_program(const std::string& shader_name);
54
64 const std::string& file_base_name,
65 const std::vector<ShaderProgram::Attribute>& attributes = std::vector<ShaderProgram::Attribute>(),
66 const std::vector<std::string>& outputs = std::vector<std::string>(),
67 bool geom_shader = false
68 );
69
83 const std::string& vert_file_name,
84 const std::string& frag_file_name,
85 const std::string& geom_file_name = "",
86 const std::string& extra_vert_code = "",
87 const std::string& extra_frag_code = "",
88 const std::string& extra_geom_code = "",
89 const std::vector<ShaderProgram::Attribute>& attributes = std::vector<ShaderProgram::Attribute>(),
90 const std::vector<std::string>& outputs = std::vector<std::string>()
91 );
92
103 const std::string& vert_code,
104 const std::string& frag_code,
105 const std::string& geom_code = "",
106 const std::vector<ShaderProgram::Attribute>& attributes = std::vector<ShaderProgram::Attribute>(),
107 const std::vector<std::string>& outputs = std::vector<std::string>()
108 );
109
114 static std::vector<ShaderProgram*> all_programs();
115
119 static void terminate();
120
124 static void reload();
125
126 private:
127 // maps of std::string can be super slow when calling find with a string literal or const char*
128 // as find forces construction/copy/destruction of a std::sting copy of the const char*.
129 static std::unordered_map<std::string, ShaderProgram*> programs_;
130 static std::unordered_map<std::string, bool> attempt_load_program_; // avoid multiple attempt
131 };
132
133}
134
135
136#endif // EASY3D_RENDERER_SHADER_MANAGER_H
Management of shader programs.
Definition shader_manager.h:46
static void terminate()
Destroy all shader programs.
Definition shader_manager.cpp:271
static std::vector< ShaderProgram * > all_programs()
Get all shader programs.
Definition shader_manager.cpp:263
static ShaderProgram * create_program_from_files(const std::string &file_base_name, const std::vector< ShaderProgram::Attribute > &attributes=std::vector< ShaderProgram::Attribute >(), const std::vector< std::string > &outputs=std::vector< std::string >(), bool geom_shader=false)
Create a shader program from shader source files specified by the shader file's base name.
Definition shader_manager.cpp:49
static ShaderProgram * get_program(const std::string &shader_name)
Get the shader program if it exists and is working.
Definition shader_manager.cpp:41
static ShaderProgram * create_program_from_codes(const std::string &vert_code, const std::string &frag_code, const std::string &geom_code="", const std::vector< ShaderProgram::Attribute > &attributes=std::vector< ShaderProgram::Attribute >(), const std::vector< std::string > &outputs=std::vector< std::string >())
Create a shader program from completed shader source codes.
Definition shader_manager.cpp:212
static void reload()
Reload all shader programs.
Definition shader_manager.cpp:282
OpenGL Shader Compilation.
Definition shader_program.h:75
Definition collider.cpp:182