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