]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.h
Miscellaneous cleanup
[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
8 namespace Msp {
9 namespace GL {
10
11 class Blend;
12 class BufferBackedUniformBlock;
13 class DefaultUniformBlock;
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 class PipelineState: public NonCopyable
25 {
26 private:
27         struct BoundTexture
28         {
29                 unsigned binding;
30                 mutable bool changed;
31                 const Texture *texture;
32                 const Sampler *sampler;
33
34                 BoundTexture(unsigned);
35         };
36
37         struct BoundUniformBlock
38         {
39                 int binding;
40                 mutable bool changed;
41                 const UniformBlock *block;
42
43                 BoundUniformBlock(int);
44         };
45
46         enum ChangeMask
47         {
48                 SHPROG = 1,
49                 VERTEX_SETUP = 2,
50                 FACE_CULL = 4,
51                 CLIP_PLANES = 8,
52                 TEXTURES = 16,
53                 UNIFORMS = 32,
54                 DEPTH_TEST = 64,
55                 STENCIL_TEST = 128,
56                 BLEND = 256,
57                 FRAMEBUFFER = 512,
58                 VIEWPORT = 1024,
59                 SCISSOR = 2048
60         };
61
62         const Framebuffer *framebuffer;
63         const Rect *viewport;
64         const Rect *scissor;
65         const Program *shprog;
66         const VertexSetup *vertex_setup;
67         FaceWinding front_face;
68         CullMode face_cull;
69         unsigned enabled_clip_planes;
70         std::vector<BoundTexture> textures;
71         std::vector<BoundUniformBlock> uniform_blocks;
72         const DepthTest *depth_test;
73         const StencilTest *stencil_test;
74         const Blend *blend;
75         mutable unsigned changes;
76
77         static const PipelineState *last_applied;
78         static std::vector<int> bound_tex_targets;
79
80 public:
81         PipelineState();
82         ~PipelineState();
83
84 private:
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_vertex_setup(const VertexSetup *);
93         void set_front_face(FaceWinding);
94         void set_face_cull(CullMode);
95         void set_enabled_clip_planes(unsigned);
96         void set_texture(unsigned, const Texture *, const Sampler *);
97         void set_uniforms(const DefaultUniformBlock *);
98         void set_uniform_block(unsigned, const BufferBackedUniformBlock *);
99 private:
100         void set_uniform_block_(int, const UniformBlock *);
101 public:
102         void set_depth_test(const DepthTest *);
103         void set_stencil_test(const StencilTest *);
104         void set_blend(const Blend *);
105
106         const Program *get_shader_program() const { return shprog; }
107         const VertexSetup *get_vertex_setup() const { return vertex_setup; }
108         FaceWinding get_front_face() const { return front_face; }
109         CullMode get_face_cull() const { return face_cull; }
110
111         void apply() const;
112 private:
113         void apply(unsigned) const;
114 public:
115         static void clear();
116 };
117
118 } // namespace GL
119 } // namespace Msp
120
121 #endif