]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.h
Initial implementation of Vulkan backend
[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 #include "primitivetype.h"
9
10 namespace Msp {
11 namespace GL {
12
13 class Blend;
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
24 /**
25 Stores state for the entire GPU pipeline.
26
27 Applications normally use the higher-level Renderer class rather than this.
28 */
29 class PipelineState: public PipelineStateBackend
30 {
31         friend PipelineStateBackend;
32
33 private:
34         struct BoundTexture
35         {
36                 unsigned binding;
37                 mutable bool changed;
38                 const Texture *texture;
39                 const Sampler *sampler;
40
41                 BoundTexture(unsigned);
42         };
43
44         struct BoundUniformBlock
45         {
46                 int binding;
47                 mutable bool changed;
48                 const UniformBlock *block;
49
50                 BoundUniformBlock(int);
51         };
52
53         enum ChangeMask
54         {
55                 FRAMEBUFFER = 1,
56                 VIEWPORT = 2,
57                 SCISSOR = 4,
58                 SHPROG = 8,
59                 UNIFORMS = 16,
60                 TEXTURES = 32,
61                 VERTEX_SETUP = 64,
62                 FACE_CULL = 128,
63                 DEPTH_TEST = 256,
64                 STENCIL_TEST = 512,
65                 BLEND = 1024,
66                 PRIMITIVE_TYPE = 2048
67         };
68
69         const Framebuffer *framebuffer = 0;
70         const Rect *viewport = 0;
71         const Rect *scissor = 0;
72         const Program *shprog = 0;
73         std::vector<BoundUniformBlock> uniform_blocks;
74         std::vector<BoundTexture> textures;
75         const VertexSetup *vertex_setup = 0;
76         PrimitiveType primitive_type = TRIANGLES;
77         FaceWinding front_face = COUNTERCLOCKWISE;
78         CullMode face_cull = NO_CULL;
79         const DepthTest *depth_test = 0;
80         const StencilTest *stencil_test = 0;
81         const Blend *blend = 0;
82
83         template<typename T>
84         void set(T &, T, unsigned);
85 public:
86         void set_framebuffer(const Framebuffer *);
87         void set_viewport(const Rect *);
88         void set_scissor(const Rect *);
89         void set_shader_program(const Program *);
90         void set_uniform_block(int, const UniformBlock *);
91         void set_texture(unsigned, const Texture *, const Sampler *);
92         void set_vertex_setup(const VertexSetup *);
93         void set_primitive_type(PrimitiveType);
94         void set_front_face(FaceWinding);
95         void set_face_cull(CullMode);
96         void set_depth_test(const DepthTest *);
97         void set_stencil_test(const StencilTest *);
98         void set_blend(const Blend *);
99
100         const Framebuffer *get_framebuffer() const { return framebuffer; }
101         const Rect *get_viewport() const { return viewport; }
102         const Program *get_shader_program() const { return shprog; }
103         const VertexSetup *get_vertex_setup() const { return vertex_setup; }
104         FaceWinding get_front_face() const { return front_face; }
105         CullMode get_face_cull() const { return face_cull; }
106 };
107
108 } // namespace GL
109 } // namespace Msp
110
111 #endif