]> git.tdb.fi Git - libs/gl.git/blob - source/backends/opengl/program_backend.h
2a223ff5ae1b50ffc46fc343c4a45996a04208cc
[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 <msp/core/noncopyable.h>
8 #include "reflectdata.h"
9
10 namespace Msp {
11 namespace GL {
12
13 class OpenGLProgram: public NonCopyable
14 {
15         friend class OpenGLPipelineState;
16
17 protected:
18         enum Stage
19         {
20                 VERTEX,
21                 GEOMETRY,
22                 FRAGMENT,
23                 MAX_STAGES
24         };
25
26         struct TransientData
27         {
28                 std::map<std::string, unsigned> textures;
29                 std::map<std::string, unsigned> blocks;
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(OpenGLProgram &&);
51         ~OpenGLProgram();
52
53         bool has_stages() const;
54         unsigned add_stage(Stage);
55         void add_glsl_stages(const GlslModule &, const std::map<std::string, int> &, TransientData &);
56         void compile_glsl_stage(const GlslModule &, unsigned);
57         void add_spirv_stages(const SpirVModule &, const std::map<std::string, int> &);
58
59         void finalize(const Module &, TransientData &);
60         void query_uniforms();
61         void query_uniform_blocks(const std::vector<ReflectData::UniformInfo *> &);
62         void query_attributes();
63         void apply_bindings(const TransientData &);
64         void finalize_uniforms();
65
66         void set_debug_name(const std::string &);
67         void set_stage_debug_name(unsigned, Stage);
68 };
69
70 using ProgramBackend = OpenGLProgram;
71
72 } // namespace GL
73 } // namespace Msp
74
75 #endif