]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.h
8d1d1aaa974c85f89637bf3bd5df8ccfc9511615
[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
7 namespace Msp {
8 namespace GL {
9
10 class BufferBackedUniformBlock;
11 class DefaultUniformBlock;
12 class Program;
13 class Sampler;
14 class Texture;
15 class UniformBlock;
16 class VertexSetup;
17 class WindingTest;
18
19 class PipelineState: public NonCopyable
20 {
21 private:
22         struct BoundTexture
23         {
24                 unsigned binding;
25                 mutable bool changed;
26                 const Texture *texture;
27                 const Sampler *sampler;
28
29                 BoundTexture(unsigned);
30         };
31
32         struct BoundUniformBlock
33         {
34                 int binding;
35                 mutable bool changed;
36                 const UniformBlock *block;
37
38                 BoundUniformBlock(int);
39         };
40
41         enum ChangeMask
42         {
43                 SHPROG = 1,
44                 VERTEX_SETUP = 2,
45                 WINDING_TEST = 4,
46                 CLIP_PLANES = 8,
47                 TEXTURES = 16,
48                 UNIFORMS = 32
49         };
50
51         const Program *shprog;
52         const VertexSetup *vertex_setup;
53         const WindingTest *winding_test;
54         unsigned enabled_clip_planes;
55         std::vector<BoundTexture> textures;
56         std::vector<BoundUniformBlock> uniform_blocks;
57         mutable unsigned changes;
58
59         static const PipelineState *last_applied;
60         static std::vector<int> bound_tex_targets;
61
62 public:
63         PipelineState();
64         ~PipelineState();
65
66         void set_shader_program(const Program *);
67         void set_vertex_setup(const VertexSetup *);
68         void set_winding_test(const WindingTest *);
69         void set_enabled_clip_planes(unsigned);
70         void set_texture(unsigned, const Texture *, const Sampler *);
71         void set_uniforms(const DefaultUniformBlock *);
72         void set_uniform_block(unsigned, const BufferBackedUniformBlock *);
73 private:
74         void set_uniform_block_(int, const UniformBlock *);
75 public:
76
77         const Program *get_shader_program() const { return shprog; }
78         const VertexSetup *get_vertex_setup() const { return vertex_setup; }
79         const WindingTest *get_winding_test() const { return winding_test; }
80
81         void apply() const;
82 private:
83         void apply(unsigned) const;
84 public:
85         static void clear();
86 };
87
88 } // namespace GL
89 } // namespace Msp
90
91 #endif