]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.h
Create specialized versions of SPIR-V modules with default spec values
[libs/gl.git] / source / core / pipelinestate.h
1 #ifndef MSP_GL_PIPELINESTATE_H_
2 #define MSP_GL_PIPELINESTATE_H_
3
4 #include <vector>
5 #include <msp/core/noncopyable.h>
6 #include "blend.h"
7 #include "cullface.h"
8 #include "depthtest.h"
9 #include "pipelinestate_backend.h"
10 #include "primitivetype.h"
11 #include "rect.h"
12 #include "stenciltest.h"
13
14 namespace Msp {
15 namespace GL {
16
17 class Buffer;
18 class Framebuffer;
19 class Program;
20 class Sampler;
21 class Texture;
22 class UniformBlock;
23 class VertexSetup;
24
25 /**
26 Stores state for the entire GPU pipeline.
27
28 Applications normally use the higher-level Renderer class rather than this.
29 */
30 class PipelineState: public PipelineStateBackend
31 {
32         friend PipelineStateBackend;
33
34 private:
35         struct BoundTexture
36         {
37                 unsigned binding = 0;
38                 mutable bool changed = false;
39                 mutable bool used = false;
40                 const Texture *texture = 0;
41                 const Sampler *sampler = 0;
42                 int level = -1;
43
44                 BoundTexture(unsigned b): binding(b) { }
45         };
46
47         struct BoundUniformBlock
48         {
49                 int binding = 0;
50                 mutable bool changed = false;
51                 mutable bool used = false;
52                 const UniformBlock *block = 0;
53                 const Buffer *buffer = 0;
54
55                 BoundUniformBlock(int b): binding(b) { }
56         };
57
58         enum ChangeMask
59         {
60                 FRAMEBUFFER = 1,
61                 VIEWPORT = 2,
62                 SCISSOR = 4,
63                 SHPROG = 8,
64                 UNIFORMS = 16,
65                 TEXTURES = 32,
66                 VERTEX_SETUP = 64,
67                 FACE_CULL = 128,
68                 DEPTH_TEST = 256,
69                 STENCIL_TEST = 512,
70                 BLEND = 1024,
71                 PRIMITIVE_TYPE = 2048
72         };
73
74         const Framebuffer *framebuffer = 0;
75         Rect viewport = Rect::max();
76         Rect scissor = Rect::max();
77         const Program *shprog = 0;
78         std::vector<BoundUniformBlock> uniform_blocks;
79         std::vector<BoundTexture> textures;
80         const VertexSetup *vertex_setup = 0;
81         PrimitiveType primitive_type = TRIANGLES;
82         FaceWinding front_face = COUNTERCLOCKWISE;
83         CullMode face_cull = NO_CULL;
84         DepthTest depth_test;
85         StencilTest stencil_test;
86         Blend blend;
87
88         template<typename T>
89         void set(T &, const T &, unsigned);
90 public:
91         void set_framebuffer(const Framebuffer *);
92         void set_viewport(const Rect &);
93         void set_scissor(const Rect &);
94         void set_shader_program(const Program *);
95         void set_uniform_block(int, const UniformBlock *);
96         void set_texture(unsigned, const Texture *, const Sampler *);
97         void set_texture(unsigned, const Texture *, int, const Sampler *);
98         void set_vertex_setup(const VertexSetup *);
99         void set_primitive_type(PrimitiveType);
100         void set_front_face(FaceWinding);
101         void set_face_cull(CullMode);
102         void set_depth_test(const DepthTest &);
103         void set_stencil_test(const StencilTest &);
104         void set_blend(const Blend &);
105
106         const Framebuffer *get_framebuffer() const { return framebuffer; }
107         const Rect &get_viewport() const { return viewport; }
108         const Program *get_shader_program() const { return shprog; }
109         const VertexSetup *get_vertex_setup() const { return vertex_setup; }
110         FaceWinding get_front_face() const { return front_face; }
111         CullMode get_face_cull() const { return face_cull; }
112 };
113
114 } // namespace GL
115 } // namespace Msp
116
117 #endif