]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.h
Refactor winding-based culling
[libs/gl.git] / source / core / pipelinestate.h
1 #ifndef PIPELINESTATE_H_
2 #define 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 BufferBackedUniformBlock;
12 class DefaultUniformBlock;
13 class Program;
14 class Sampler;
15 class Texture;
16 class UniformBlock;
17 class VertexSetup;
18 class WindingTest;
19
20 class PipelineState: public NonCopyable
21 {
22 private:
23         struct BoundTexture
24         {
25                 unsigned binding;
26                 mutable bool changed;
27                 const Texture *texture;
28                 const Sampler *sampler;
29
30                 BoundTexture(unsigned);
31         };
32
33         struct BoundUniformBlock
34         {
35                 int binding;
36                 mutable bool changed;
37                 const UniformBlock *block;
38
39                 BoundUniformBlock(int);
40         };
41
42         enum ChangeMask
43         {
44                 SHPROG = 1,
45                 VERTEX_SETUP = 2,
46                 FACE_CULL = 4,
47                 CLIP_PLANES = 8,
48                 TEXTURES = 16,
49                 UNIFORMS = 32
50         };
51
52         const Program *shprog;
53         const VertexSetup *vertex_setup;
54         FaceWinding front_face;
55         CullMode face_cull;
56         unsigned enabled_clip_planes;
57         std::vector<BoundTexture> textures;
58         std::vector<BoundUniformBlock> uniform_blocks;
59         mutable unsigned changes;
60
61         static const PipelineState *last_applied;
62         static std::vector<int> bound_tex_targets;
63
64 public:
65         PipelineState();
66         ~PipelineState();
67
68         void set_shader_program(const Program *);
69         void set_vertex_setup(const VertexSetup *);
70         void set_front_face(FaceWinding);
71         void set_face_cull(CullMode);
72         void set_enabled_clip_planes(unsigned);
73         void set_texture(unsigned, const Texture *, const Sampler *);
74         void set_uniforms(const DefaultUniformBlock *);
75         void set_uniform_block(unsigned, const BufferBackedUniformBlock *);
76 private:
77         void set_uniform_block_(int, const UniformBlock *);
78 public:
79
80         const Program *get_shader_program() const { return shprog; }
81         const VertexSetup *get_vertex_setup() const { return vertex_setup; }
82         FaceWinding get_front_face() const { return front_face; }
83         CullMode get_face_cull() const { return face_cull; }
84
85         void apply() const;
86 private:
87         void apply(unsigned) const;
88 public:
89         static void clear();
90 };
91
92 } // namespace GL
93 } // namespace Msp
94
95 #endif