]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.cpp
Fix reflection of image types from Spir-V modules
[libs/gl.git] / source / core / pipelinestate.cpp
1 #include <stdexcept>
2 #include <msp/core/algorithm.h>
3 #include "pipelinestate.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace GL {
9
10 template<typename T>
11 void PipelineState::set(T &target, T value, unsigned flag)
12 {
13         if(value!=target)
14         {
15                 target = value;
16                 changes |= flag;
17         }
18 }
19
20 void PipelineState::set_framebuffer(const Framebuffer *f)
21 {
22         set(framebuffer, f, FRAMEBUFFER);
23 }
24
25 void PipelineState::set_viewport(const Rect *v)
26 {
27         set(viewport, v, VIEWPORT);
28 }
29
30 void PipelineState::set_scissor(const Rect *s)
31 {
32         set(scissor, s, SCISSOR);
33 }
34
35 void PipelineState::set_shader_program(const Program *p)
36 {
37         set(shprog, p, SHPROG);
38 }
39
40 void PipelineState::set_uniform_block(int binding, const UniformBlock *block)
41 {
42         auto i = lower_bound_member(uniform_blocks, binding, &BoundUniformBlock::binding);
43         if(i==uniform_blocks.end() || i->binding!=binding)
44                 i = uniform_blocks.insert(i, BoundUniformBlock(binding));
45         if(block!=i->block || binding<0)
46         {
47                 i->block = block;
48                 i->changed = true;
49                 changes |= UNIFORMS;
50         }
51 }
52
53 void PipelineState::set_texture(unsigned binding, const Texture *tex, const Sampler *samp)
54 {
55         if((tex!=0)!=(samp!=0))
56                 throw invalid_argument("PipelineState::set_texture");
57
58         auto i = lower_bound_member(textures, binding, &BoundTexture::binding);
59         if(i==textures.end() || i->binding!=binding)
60                 i = textures.insert(i, BoundTexture(binding));
61         if(tex!=i->texture || samp!=i->sampler)
62         {
63                 i->texture = tex;
64                 i->sampler = samp;
65                 i->changed = true;
66                 changes |= TEXTURES;
67         }
68 }
69
70 void PipelineState::set_vertex_setup(const VertexSetup *s)
71 {
72         set(vertex_setup, s, VERTEX_SETUP);
73 }
74
75 void PipelineState::set_front_face(FaceWinding w)
76 {
77         set(front_face, w, FACE_CULL);
78 }
79
80 void PipelineState::set_face_cull(CullMode c)
81 {
82         set(face_cull, c, FACE_CULL);
83 }
84
85 void PipelineState::set_depth_test(const DepthTest *dt)
86 {
87         set(depth_test, dt, DEPTH_TEST);
88 }
89
90 void PipelineState::set_stencil_test(const StencilTest *st)
91 {
92         set(stencil_test, st, STENCIL_TEST);
93 }
94
95 void PipelineState::set_blend(const Blend *b)
96 {
97         set(blend, b, BLEND);
98 }
99
100
101 PipelineState::BoundTexture::BoundTexture(unsigned b):
102         binding(b),
103         changed(false),
104         texture(0),
105         sampler(0)
106 { }
107
108
109 PipelineState::BoundUniformBlock::BoundUniformBlock(int b):
110         binding(b),
111         changed(false),
112         block(0)
113 { }
114
115 } // namespace GL
116 } // namespace Msp