]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.h
Move all OpenGL-specific code to a separate directory
[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                 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 public:
79         PipelineState();
80
81 private:
82         template<typename T>
83         void set(T &, T, unsigned);
84 public:
85         void set_framebuffer(const Framebuffer *);
86         void set_viewport(const Rect *);
87         void set_scissor(const Rect *);
88         void set_shader_program(const Program *);
89         void set_vertex_setup(const VertexSetup *);
90         void set_front_face(FaceWinding);
91         void set_face_cull(CullMode);
92         void set_enabled_clip_planes(unsigned);
93         void set_texture(unsigned, const Texture *, const Sampler *);
94         void set_uniform_block(int, const UniformBlock *);
95         void set_depth_test(const DepthTest *);
96         void set_stencil_test(const StencilTest *);
97         void set_blend(const Blend *);
98
99         const Framebuffer *get_framebuffer() const { return framebuffer; }
100         const Program *get_shader_program() const { return shprog; }
101         const VertexSetup *get_vertex_setup() const { return vertex_setup; }
102         FaceWinding get_front_face() const { return front_face; }
103         CullMode get_face_cull() const { return face_cull; }
104 };
105
106 } // namespace GL
107 } // namespace Msp
108
109 #endif