]> git.tdb.fi Git - libs/gl.git/blob - source/backends/opengl/program_backend.h
b08b70fae968e5992e1e7e026aaa5f7004c78430
[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         };
30
31         struct UniformCall
32         {
33                 using FuncPtr = void (*)(unsigned, unsigned, const void *);
34
35                 unsigned location;
36                 unsigned size;
37                 FuncPtr func;
38
39                 UniformCall(unsigned l, unsigned s, FuncPtr f): location(l), size(s), func(f) { }
40         };
41
42         unsigned id = 0;
43         unsigned stage_ids[MAX_STAGES] = { };
44         bool linked = false;
45         std::vector<UniformCall> uniform_calls;
46         std::string debug_name;
47
48         OpenGLProgram();
49         ~OpenGLProgram();
50
51         bool has_stages() const;
52         unsigned add_stage(Stage);
53         void add_glsl_stages(const GlslModule &, const std::map<std::string, int> &, TransientData &);
54         void compile_glsl_stage(const GlslModule &, unsigned);
55         void add_spirv_stages(const SpirVModule &, const std::map<std::string, int> &);
56
57         void finalize(const Module &, TransientData &);
58         void query_uniforms();
59         void query_uniform_blocks(const std::vector<ReflectData::UniformInfo *> &);
60         void query_attributes();
61         void apply_bindings(const TransientData &);
62         void finalize_uniforms();
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