]> git.tdb.fi Git - libs/gl.git/blob - source/backends/opengl/program_backend.h
Use default member initializers for simple types
[libs/gl.git] / source / backends / opengl / program_backend.h
1 #ifndef MSP_GL_PROGRAM_BACKEND_H_
2 #define MSP_GL_PROGRAM_BACKEND_H_
3
4 #include <map>
5 #include <string>
6 #include <vector>
7 #include "reflectdata.h"
8
9 namespace Msp {
10 namespace GL {
11
12 class OpenGLProgram
13 {
14         friend class OpenGLPipelineState;
15
16 protected:
17         enum Stage
18         {
19                 VERTEX,
20                 GEOMETRY,
21                 FRAGMENT,
22                 MAX_STAGES
23         };
24
25         struct TransientData
26         {
27                 std::map<std::string, unsigned> textures;
28                 std::map<std::string, unsigned> blocks;
29                 std::map<unsigned, int> spec_values;
30         };
31
32         struct UniformCall
33         {
34                 using FuncPtr = void (*)(unsigned, unsigned, const void *);
35
36                 unsigned location;
37                 unsigned size;
38                 FuncPtr func;
39
40                 UniformCall(unsigned l, unsigned s, FuncPtr f): location(l), size(s), func(f) { }
41         };
42
43         unsigned id = 0;
44         unsigned stage_ids[MAX_STAGES] = { };
45         bool linked = false;
46         std::vector<UniformCall> uniform_calls;
47         std::string debug_name;
48
49         OpenGLProgram();
50         ~OpenGLProgram();
51
52         bool has_stages() const;
53         unsigned add_stage(Stage);
54         void add_glsl_stages(const GlslModule &, const std::map<std::string, int> &, TransientData &);
55         void compile_glsl_stage(const GlslModule &, unsigned);
56         void add_spirv_stages(const SpirVModule &, const std::map<std::string, int> &, TransientData &);
57
58         void finalize(const Module &);
59         void query_uniforms();
60         void query_uniform_blocks(const std::vector<ReflectData::UniformInfo *> &);
61         void query_attributes();
62         void apply_bindings(const TransientData &);
63
64         void set_debug_name(const std::string &);
65         void set_stage_debug_name(unsigned, Stage);
66 };
67
68 using ProgramBackend = OpenGLProgram;
69
70 } // namespace GL
71 } // namespace Msp
72
73 #endif