]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.cpp
Use default member initializers for simple types
[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_enabled_clip_planes(unsigned p)
56 {
57         set(enabled_clip_planes, p, CLIP_PLANES);
58 }
59
60 void PipelineState::set_texture(unsigned binding, const Texture *tex, const Sampler *samp)
61 {
62         if((tex!=0)!=(samp!=0))
63                 throw invalid_argument("PipelineState::set_texture");
64
65         auto i = lower_bound_member(textures, binding, &BoundTexture::binding);
66         if(i==textures.end() || i->binding!=binding)
67                 i = textures.insert(i, BoundTexture(binding));
68         if(tex!=i->texture || samp!=i->sampler)
69         {
70                 i->texture = tex;
71                 i->sampler = samp;
72                 i->changed = true;
73                 changes |= TEXTURES;
74         }
75 }
76
77 void PipelineState::set_uniform_block(int binding, const UniformBlock *block)
78 {
79         auto i = lower_bound_member(uniform_blocks, binding, &BoundUniformBlock::binding);
80         if(i==uniform_blocks.end() || i->binding!=binding)
81                 i = uniform_blocks.insert(i, BoundUniformBlock(binding));
82         if(block!=i->block || binding<0)
83         {
84                 i->block = block;
85                 i->changed = true;
86                 changes |= UNIFORMS;
87         }
88 }
89
90 void PipelineState::set_depth_test(const DepthTest *dt)
91 {
92         set(depth_test, dt, DEPTH_TEST);
93 }
94
95 void PipelineState::set_stencil_test(const StencilTest *st)
96 {
97         set(stencil_test, st, STENCIL_TEST);
98 }
99
100 void PipelineState::set_blend(const Blend *b)
101 {
102         set(blend, b, BLEND);
103 }
104
105
106 PipelineState::BoundTexture::BoundTexture(unsigned b):
107         binding(b),
108         changed(false),
109         texture(0),
110         sampler(0)
111 { }
112
113
114 PipelineState::BoundUniformBlock::BoundUniformBlock(int b):
115         binding(b),
116         changed(false),
117         block(0)
118 { }
119
120 } // namespace GL
121 } // namespace Msp