]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.h
Make it possible to query if a framebuffer can be presented
[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         enum ResourceType: std::uint8_t
36         {
37                 NO_RESOURCE,
38                 UNIFORM_BLOCK,
39                 SAMPLED_TEXTURE,
40                 STORAGE_TEXTURE
41         };
42
43         struct BoundResource
44         {
45                 int binding = 0;
46                 ResourceType type = NO_RESOURCE;
47                 mutable bool changed = false;
48                 mutable bool used = false;
49                 union
50                 {
51                         const UniformBlock *block;
52                         const Texture *texture;
53                 };
54                 union
55                 {
56                         const Buffer *buffer;
57                         const Sampler *sampler;
58                 };
59                 int mip_level = -1;
60
61                 BoundResource(int b): binding(b), texture(0), sampler(0) { }
62         };
63
64         enum ChangeMask
65         {
66                 FRAMEBUFFER = 1,
67                 VIEWPORT = 2,
68                 SCISSOR = 4,
69                 SHPROG = 8,
70                 RESOURCES = 16,
71                 VERTEX_SETUP = 64,
72                 FACE_CULL = 128,
73                 DEPTH_TEST = 256,
74                 STENCIL_TEST = 512,
75                 BLEND = 1024,
76                 PRIMITIVE_TYPE = 2048
77         };
78
79         const Framebuffer *framebuffer = 0;
80         Rect viewport = Rect::max();
81         Rect scissor = Rect::max();
82         const Program *shprog = 0;
83         std::vector<BoundResource> resources;
84         const VertexSetup *vertex_setup = 0;
85         PrimitiveType primitive_type = TRIANGLES;
86         FaceWinding front_face = COUNTERCLOCKWISE;
87         CullMode face_cull = NO_CULL;
88         DepthTest depth_test;
89         StencilTest stencil_test;
90         Blend blend;
91
92         template<typename T>
93         void set(T &, const T &, unsigned);
94 public:
95         void set_framebuffer(const Framebuffer *);
96         void set_viewport(const Rect &);
97         void set_scissor(const Rect &);
98         void set_shader_program(const Program *);
99         void set_uniform_block(int, const UniformBlock *);
100         void set_texture(unsigned, const Texture *, const Sampler *);
101         void set_texture(unsigned, const Texture *, int, const Sampler *);
102         void set_storage_texture(unsigned, const Texture *);
103 private:
104         void set_texture_resource(unsigned, const Texture *, int, const Sampler *);
105 public:
106         void set_vertex_setup(const VertexSetup *);
107         void set_primitive_type(PrimitiveType);
108         void set_front_face(FaceWinding);
109         void set_face_cull(CullMode);
110         void set_depth_test(const DepthTest &);
111         void set_stencil_test(const StencilTest &);
112         void set_blend(const Blend &);
113
114         const Framebuffer *get_framebuffer() const { return framebuffer; }
115         const Rect &get_viewport() const { return viewport; }
116         const Program *get_shader_program() const { return shprog; }
117         const VertexSetup *get_vertex_setup() const { return vertex_setup; }
118         FaceWinding get_front_face() const { return front_face; }
119         CullMode get_face_cull() const { return face_cull; }
120 };
121
122 } // namespace GL
123 } // namespace Msp
124
125 #endif