]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.h
Support binding individual mipmap levels of textures
[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 = 0;
37                 mutable bool changed = false;
38                 mutable bool used = false;
39                 const Texture *texture = 0;
40                 const Sampler *sampler = 0;
41                 int level = -1;
42
43                 BoundTexture(unsigned b): binding(b) { }
44         };
45
46         struct BoundUniformBlock
47         {
48                 int binding = 0;
49                 mutable bool changed = false;
50                 mutable bool used = false;
51                 const UniformBlock *block = 0;
52
53                 BoundUniformBlock(int b): binding(b) { }
54         };
55
56         enum ChangeMask
57         {
58                 FRAMEBUFFER = 1,
59                 VIEWPORT = 2,
60                 SCISSOR = 4,
61                 SHPROG = 8,
62                 UNIFORMS = 16,
63                 TEXTURES = 32,
64                 VERTEX_SETUP = 64,
65                 FACE_CULL = 128,
66                 DEPTH_TEST = 256,
67                 STENCIL_TEST = 512,
68                 BLEND = 1024,
69                 PRIMITIVE_TYPE = 2048
70         };
71
72         const Framebuffer *framebuffer = 0;
73         const Rect *viewport = 0;
74         const Rect *scissor = 0;
75         const Program *shprog = 0;
76         std::vector<BoundUniformBlock> uniform_blocks;
77         std::vector<BoundTexture> textures;
78         const VertexSetup *vertex_setup = 0;
79         PrimitiveType primitive_type = TRIANGLES;
80         FaceWinding front_face = COUNTERCLOCKWISE;
81         CullMode face_cull = NO_CULL;
82         const DepthTest *depth_test = 0;
83         const StencilTest *stencil_test = 0;
84         const Blend *blend = 0;
85
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_uniform_block(int, const UniformBlock *);
94         void set_texture(unsigned, const Texture *, const Sampler *);
95         void set_texture(unsigned, const Texture *, int, const Sampler *);
96         void set_vertex_setup(const VertexSetup *);
97         void set_primitive_type(PrimitiveType);
98         void set_front_face(FaceWinding);
99         void set_face_cull(CullMode);
100         void set_depth_test(const DepthTest *);
101         void set_stencil_test(const StencilTest *);
102         void set_blend(const Blend *);
103
104         const Framebuffer *get_framebuffer() const { return framebuffer; }
105         const Rect *get_viewport() const { return viewport; }
106         const Program *get_shader_program() const { return shprog; }
107         const VertexSetup *get_vertex_setup() const { return vertex_setup; }
108         FaceWinding get_front_face() const { return front_face; }
109         CullMode get_face_cull() const { return face_cull; }
110 };
111
112 } // namespace GL
113 } // namespace Msp
114
115 #endif