]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.h
6d4d2f6441099a2565fc2d245e57f475bacd49f6
[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 #include "pipelinestate_backend.h"
8
9 namespace Msp {
10 namespace GL {
11
12 class Blend;
13 class DepthTest;
14 class Framebuffer;
15 class Program;
16 class Rect;
17 class Sampler;
18 class StencilTest;
19 class Texture;
20 class UniformBlock;
21 class VertexSetup;
22
23 class PipelineState: public PipelineStateBackend
24 {
25         friend PipelineStateBackend;
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                 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 = 0;
63         const Rect *viewport = 0;
64         const Rect *scissor = 0;
65         const Program *shprog = 0;
66         const VertexSetup *vertex_setup = 0;
67         FaceWinding front_face = COUNTERCLOCKWISE;
68         CullMode face_cull = NO_CULL;
69         std::vector<BoundTexture> textures;
70         std::vector<BoundUniformBlock> uniform_blocks;
71         const DepthTest *depth_test = 0;
72         const StencilTest *stencil_test = 0;
73         const Blend *blend = 0;
74         mutable unsigned changes = 0;
75
76         template<typename T>
77         void set(T &, T, unsigned);
78 public:
79         void set_framebuffer(const Framebuffer *);
80         void set_viewport(const Rect *);
81         void set_scissor(const Rect *);
82         void set_shader_program(const Program *);
83         void set_vertex_setup(const VertexSetup *);
84         void set_front_face(FaceWinding);
85         void set_face_cull(CullMode);
86         void set_texture(unsigned, const Texture *, const Sampler *);
87         void set_uniform_block(int, const UniformBlock *);
88         void set_depth_test(const DepthTest *);
89         void set_stencil_test(const StencilTest *);
90         void set_blend(const Blend *);
91
92         const Framebuffer *get_framebuffer() const { return framebuffer; }
93         const Program *get_shader_program() const { return shprog; }
94         const VertexSetup *get_vertex_setup() const { return vertex_setup; }
95         FaceWinding get_front_face() const { return front_face; }
96         CullMode get_face_cull() const { return face_cull; }
97 };
98
99 } // namespace GL
100 } // namespace Msp
101
102 #endif