]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.cpp
Always set uniform array size to at least one
[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_vertex_setup(const VertexSetup *s)
41 {
42         set(vertex_setup, s, VERTEX_SETUP);
43 }
44
45 void PipelineState::set_front_face(FaceWinding w)
46 {
47         set(front_face, w, FACE_CULL);
48 }
49
50 void PipelineState::set_face_cull(CullMode c)
51 {
52         set(face_cull, c, FACE_CULL);
53 }
54
55 void PipelineState::set_texture(unsigned binding, const Texture *tex, const Sampler *samp)
56 {
57         if((tex!=0)!=(samp!=0))
58                 throw invalid_argument("PipelineState::set_texture");
59
60         auto i = lower_bound_member(textures, binding, &BoundTexture::binding);
61         if(i==textures.end() || i->binding!=binding)
62                 i = textures.insert(i, BoundTexture(binding));
63         if(tex!=i->texture || samp!=i->sampler)
64         {
65                 i->texture = tex;
66                 i->sampler = samp;
67                 i->changed = true;
68                 changes |= TEXTURES;
69         }
70 }
71
72 void PipelineState::set_uniform_block(int binding, const UniformBlock *block)
73 {
74         auto i = lower_bound_member(uniform_blocks, binding, &BoundUniformBlock::binding);
75         if(i==uniform_blocks.end() || i->binding!=binding)
76                 i = uniform_blocks.insert(i, BoundUniformBlock(binding));
77         if(block!=i->block || binding<0)
78         {
79                 i->block = block;
80                 i->changed = true;
81                 changes |= UNIFORMS;
82         }
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