]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.h
Clean up includes and forward declarations for the core classes
[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 DepthTest;
13 class Framebuffer;
14 class Program;
15 class Rect;
16 class Sampler;
17 class StencilTest;
18 class Texture;
19 class UniformBlock;
20 class VertexSetup;
21
22 class PipelineState: public NonCopyable
23 {
24 private:
25         struct BoundTexture
26         {
27                 unsigned binding;
28                 mutable bool changed;
29                 const Texture *texture;
30                 const Sampler *sampler;
31
32                 BoundTexture(unsigned);
33         };
34
35         struct BoundUniformBlock
36         {
37                 int binding;
38                 mutable bool changed;
39                 const UniformBlock *block;
40
41                 BoundUniformBlock(int);
42         };
43
44         enum ChangeMask
45         {
46                 SHPROG = 1,
47                 VERTEX_SETUP = 2,
48                 FACE_CULL = 4,
49                 CLIP_PLANES = 8,
50                 TEXTURES = 16,
51                 UNIFORMS = 32,
52                 DEPTH_TEST = 64,
53                 STENCIL_TEST = 128,
54                 BLEND = 256,
55                 FRAMEBUFFER = 512,
56                 VIEWPORT = 1024,
57                 SCISSOR = 2048
58         };
59
60         const Framebuffer *framebuffer;
61         const Rect *viewport;
62         const Rect *scissor;
63         const Program *shprog;
64         const VertexSetup *vertex_setup;
65         FaceWinding front_face;
66         CullMode face_cull;
67         unsigned enabled_clip_planes;
68         std::vector<BoundTexture> textures;
69         std::vector<BoundUniformBlock> uniform_blocks;
70         const DepthTest *depth_test;
71         const StencilTest *stencil_test;
72         const Blend *blend;
73         mutable unsigned changes;
74
75         static const PipelineState *last_applied;
76         static std::vector<int> bound_tex_targets;
77         static std::vector<char> bound_uniform_blocks;
78         static unsigned restart_index;
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_uniform_block(int, const UniformBlock *);
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 Program *get_shader_program() const { return shprog; }
104         const VertexSetup *get_vertex_setup() const { return vertex_setup; }
105         FaceWinding get_front_face() const { return front_face; }
106         CullMode get_face_cull() const { return face_cull; }
107
108         void apply() const;
109 private:
110         void apply(unsigned) const;
111 public:
112         static void clear();
113 };
114
115 } // namespace GL
116 } // namespace Msp
117
118 #endif