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