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