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