]> git.tdb.fi Git - libs/gl.git/blob - source/backends/opengl/program_backend.h
Support compute shaders and compute operations
[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                 COMPUTE,
24                 MAX_STAGES
25         };
26
27         struct UniformCall
28         {
29                 using FuncPtr = void (*)(unsigned, unsigned, const void *);
30
31                 unsigned location;
32                 unsigned size;
33                 FuncPtr func;
34
35                 UniformCall(unsigned l, unsigned s, FuncPtr f): location(l), size(s), func(f) { }
36         };
37
38         unsigned id = 0;
39         unsigned stage_ids[MAX_STAGES] = { };
40         bool linked = false;
41         std::vector<UniformCall> uniform_calls;
42         std::string debug_name;
43
44         OpenGLProgram();
45         OpenGLProgram(OpenGLProgram &&);
46         ~OpenGLProgram();
47
48         bool has_stages() const;
49         unsigned add_stage(Stage);
50         void add_glsl_stages(const GlslModule &, const std::map<std::string, int> &);
51         void compile_glsl_stage(const GlslModule &, unsigned);
52         void add_spirv_stages(const SpirVModule &, const std::map<std::string, int> &);
53
54         void link(const Module &);
55         void query_uniforms();
56         void query_uniform_blocks(const std::vector<ReflectData::UniformInfo *> &);
57         void query_attributes();
58         void finalize_uniforms();
59
60         bool is_compute() const { return stage_ids[COMPUTE]; }
61
62         void set_debug_name(const std::string &);
63         void set_stage_debug_name(unsigned, Stage);
64 };
65
66 using ProgramBackend = OpenGLProgram;
67
68 } // namespace GL
69 } // namespace Msp
70
71 #endif