]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.h
Redesign depth and stencil test and blend state management
[libs/gl.git] / source / core / pipelinestate.h
1 #ifndef PIPELINESTATE_H_
2 #define 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 Program;
16 class Sampler;
17 class StencilTest;
18 class Texture;
19 class UniformBlock;
20 class VertexSetup;
21 class WindingTest;
22
23 class PipelineState: public NonCopyable
24 {
25 private:
26         struct BoundTexture
27         {
28                 unsigned binding;
29                 mutable bool changed;
30                 const Texture *texture;
31                 const Sampler *sampler;
32
33                 BoundTexture(unsigned);
34         };
35
36         struct BoundUniformBlock
37         {
38                 int binding;
39                 mutable bool changed;
40                 const UniformBlock *block;
41
42                 BoundUniformBlock(int);
43         };
44
45         enum ChangeMask
46         {
47                 SHPROG = 1,
48                 VERTEX_SETUP = 2,
49                 FACE_CULL = 4,
50                 CLIP_PLANES = 8,
51                 TEXTURES = 16,
52                 UNIFORMS = 32,
53                 DEPTH_TEST = 64,
54                 STENCIL_TEST = 128,
55                 BLEND = 256
56         };
57
58         const Program *shprog;
59         const VertexSetup *vertex_setup;
60         FaceWinding front_face;
61         CullMode face_cull;
62         unsigned enabled_clip_planes;
63         std::vector<BoundTexture> textures;
64         std::vector<BoundUniformBlock> uniform_blocks;
65         const DepthTest *depth_test;
66         const StencilTest *stencil_test;
67         const Blend *blend;
68         mutable unsigned changes;
69
70         static const PipelineState *last_applied;
71         static std::vector<int> bound_tex_targets;
72
73 public:
74         PipelineState();
75         ~PipelineState();
76
77 private:
78         template<typename T>
79         void set(T &, T, unsigned);
80 public:
81         void set_shader_program(const Program *);
82         void set_vertex_setup(const VertexSetup *);
83         void set_front_face(FaceWinding);
84         void set_face_cull(CullMode);
85         void set_enabled_clip_planes(unsigned);
86         void set_texture(unsigned, const Texture *, const Sampler *);
87         void set_uniforms(const DefaultUniformBlock *);
88         void set_uniform_block(unsigned, const BufferBackedUniformBlock *);
89 private:
90         void set_uniform_block_(int, const UniformBlock *);
91 public:
92         void set_depth_test(const DepthTest *);
93         void set_stencil_test(const StencilTest *);
94         void set_blend(const Blend *);
95
96         const Program *get_shader_program() const { return shprog; }
97         const VertexSetup *get_vertex_setup() const { return vertex_setup; }
98         FaceWinding get_front_face() const { return front_face; }
99         CullMode get_face_cull() const { return face_cull; }
100
101         void apply() const;
102 private:
103         void apply(unsigned) const;
104 public:
105         static void clear();
106 };
107
108 } // namespace GL
109 } // namespace Msp
110
111 #endif