2 #include <msp/core/algorithm.h>
3 #include "pipelinestate.h"
10 PipelineState::PipelineState():
16 front_face(COUNTERCLOCKWISE),
18 enabled_clip_planes(0),
26 void PipelineState::set(T &target, T value, unsigned flag)
35 void PipelineState::set_framebuffer(const Framebuffer *f)
37 set(framebuffer, f, FRAMEBUFFER);
40 void PipelineState::set_viewport(const Rect *v)
42 set(viewport, v, VIEWPORT);
45 void PipelineState::set_scissor(const Rect *s)
47 set(scissor, s, SCISSOR);
50 void PipelineState::set_shader_program(const Program *p)
52 set(shprog, p, SHPROG);
55 void PipelineState::set_vertex_setup(const VertexSetup *s)
57 set(vertex_setup, s, VERTEX_SETUP);
60 void PipelineState::set_front_face(FaceWinding w)
62 set(front_face, w, FACE_CULL);
65 void PipelineState::set_face_cull(CullMode c)
67 set(face_cull, c, FACE_CULL);
70 void PipelineState::set_enabled_clip_planes(unsigned p)
72 set(enabled_clip_planes, p, CLIP_PLANES);
75 void PipelineState::set_texture(unsigned binding, const Texture *tex, const Sampler *samp)
77 if((tex!=0)!=(samp!=0))
78 throw invalid_argument("PipelineState::set_texture");
80 auto i = lower_bound_member(textures, binding, &BoundTexture::binding);
81 if(i==textures.end() || i->binding!=binding)
82 i = textures.insert(i, BoundTexture(binding));
83 if(tex!=i->texture || samp!=i->sampler)
92 void PipelineState::set_uniform_block(int binding, const UniformBlock *block)
94 auto i = lower_bound_member(uniform_blocks, binding, &BoundUniformBlock::binding);
95 if(i==uniform_blocks.end() || i->binding!=binding)
96 i = uniform_blocks.insert(i, BoundUniformBlock(binding));
97 if(block!=i->block || binding<0)
105 void PipelineState::set_depth_test(const DepthTest *dt)
107 set(depth_test, dt, DEPTH_TEST);
110 void PipelineState::set_stencil_test(const StencilTest *st)
112 set(stencil_test, st, STENCIL_TEST);
115 void PipelineState::set_blend(const Blend *b)
117 set(blend, b, BLEND);
121 PipelineState::BoundTexture::BoundTexture(unsigned b):
129 PipelineState::BoundUniformBlock::BoundUniformBlock(int b):