TYPE3
[iec.git] / src / type3_AndroidCloud / anbox-master / src / anbox / graphics / program_family.h
1 /*
2  * Copyright © 2015 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Daniel van Vugt <daniel.van.vugt@canonical.com>
17  */
18
19 #ifndef ANBOX_GRAPHICS_PROGRAM_FAMILY_H_
20 #define ANBOX_GRAPHICS_PROGRAM_FAMILY_H_
21
22 #include <map>
23 #include <unordered_map>
24 #include <utility>
25
26 #include <GLES2/gl2.h>
27
28 namespace anbox {
29 namespace graphics {
30 /**
31  * ProgramFamily represents a set of GLSL programs that are closely
32  * related. Programs which point to the same shader source strings will be
33  * made to share the same compiled shader objects.
34  *   A secondary intention is that this class may be extended to allow the
35  * different programs within the family to share common patterns of uniform
36  * usage too.
37  */
38 class ProgramFamily {
39  public:
40   ProgramFamily() = default;
41   ProgramFamily(ProgramFamily const&) = delete;
42   ProgramFamily& operator=(ProgramFamily const&) = delete;
43   ~ProgramFamily() noexcept;
44
45   GLuint add_program(const GLchar* const static_vshader_src,
46                      const GLchar* const static_fshader_src);
47
48  private:
49   struct Shader {
50     GLuint id = 0;
51     void init(GLenum type, const GLchar* src);
52   };
53   typedef std::unordered_map<const GLchar*, Shader> ShaderMap;
54   ShaderMap vshader, fshader;
55
56   typedef std::pair<GLuint, GLuint> ShaderPair;
57   struct Program {
58     GLuint id = 0;
59   };
60   std::map<ShaderPair, Program> program;
61 };
62 }  // namespace graphics
63 }  // namespace anbox
64
65 #endif  // MIR_RENDERER_GL_PROGRAM_FAMILY_H_