2 #include <msp/core/algorithm.h>
4 #include "pipelinestate.h"
12 void PipelineState::set(T &target, T value, unsigned flag)
21 void PipelineState::set_framebuffer(const Framebuffer *f)
23 set(framebuffer, f, FRAMEBUFFER);
26 void PipelineState::set_viewport(const Rect *v)
28 set(viewport, v, VIEWPORT);
31 void PipelineState::set_scissor(const Rect *s)
33 set(scissor, s, SCISSOR);
36 void PipelineState::set_shader_program(const Program *p)
38 set(shprog, p, SHPROG);
41 void PipelineState::set_uniform_block(int binding, const UniformBlock *block)
43 auto i = lower_bound_member(uniform_blocks, binding, &BoundUniformBlock::binding);
44 if(i==uniform_blocks.end() || i->binding!=binding)
45 i = uniform_blocks.insert(i, BoundUniformBlock(binding));
47 if(block!=i->block || binding<0)
55 void PipelineState::set_texture(unsigned binding, const Texture *tex, const Sampler *samp)
57 set_texture(binding, tex, -1, samp);
60 void PipelineState::set_texture(unsigned binding, const Texture *tex, int level, const Sampler *samp)
62 if((tex!=0)!=(samp!=0))
63 throw invalid_argument("PipelineState::set_texture");
64 if(level>=0 && !can_bind_tex_level(level))
65 throw invalid_operation("PipelineState::set_texture");
67 auto i = lower_bound_member(textures, binding, &BoundTexture::binding);
68 if(i==textures.end() || i->binding!=binding)
69 i = textures.insert(i, BoundTexture(binding));
70 i->used = (tex && samp);
71 if(tex!=i->texture || level!=i->level || samp!=i->sampler)
81 void PipelineState::set_vertex_setup(const VertexSetup *s)
83 set(vertex_setup, s, VERTEX_SETUP);
86 void PipelineState::set_primitive_type(PrimitiveType t)
88 set(primitive_type, t, PRIMITIVE_TYPE);
91 void PipelineState::set_front_face(FaceWinding w)
93 set(front_face, w, FACE_CULL);
96 void PipelineState::set_face_cull(CullMode c)
98 set(face_cull, c, FACE_CULL);
101 void PipelineState::set_depth_test(const DepthTest *dt)
103 set(depth_test, dt, DEPTH_TEST);
106 void PipelineState::set_stencil_test(const StencilTest *st)
108 set(stencil_test, st, STENCIL_TEST);
111 void PipelineState::set_blend(const Blend *b)
113 set(blend, b, BLEND);