2 #include <msp/core/algorithm.h>
4 #include "pipelinestate.h"
5 #include "uniformblock.h"
13 void PipelineState::set(T &target, const T &value, unsigned flag)
22 void PipelineState::set_framebuffer(const Framebuffer *f)
24 set(framebuffer, f, FRAMEBUFFER);
27 void PipelineState::set_viewport(const Rect &v)
29 set(viewport, v, VIEWPORT);
32 void PipelineState::set_scissor(const Rect &s)
34 set(scissor, s, SCISSOR);
37 void PipelineState::set_shader_program(const Program *p)
39 set(shprog, p, SHPROG);
42 void PipelineState::set_uniform_block(int binding, const UniformBlock *block)
44 auto i = lower_bound_member(resources, binding, &BoundResource::binding);
45 if(i==resources.end() || i->binding!=binding)
46 i = resources.insert(i, BoundResource(binding));
48 ResourceType type = (block ? UNIFORM_BLOCK : NO_RESOURCE);
49 const Buffer *buffer = (block ? block->get_buffer() : 0);
50 if(i->type!=type || block!=i->block || buffer!=i->buffer || binding<0)
61 void PipelineState::set_texture(unsigned binding, const Texture *tex, const Sampler *samp)
63 set_texture(binding, tex, -1, samp);
66 void PipelineState::set_texture(unsigned binding, const Texture *tex, int level, const Sampler *samp)
68 if((tex!=0)!=(samp!=0))
69 throw invalid_argument("PipelineState::set_texture");
70 if(level>=0 && !can_bind_tex_level(level))
71 throw invalid_operation("PipelineState::set_texture");
73 auto i = lower_bound_member(resources, static_cast<int>(binding), &BoundResource::binding);
74 if(i==resources.end() || i->binding!=static_cast<int>(binding))
75 i = resources.insert(i, BoundResource(binding));
77 ResourceType type = (tex ? TEXTURE : NO_RESOURCE);
78 if(i->type!=type || tex!=i->texture || level!=i->mip_level || samp!=i->sampler)
85 i->used = (tex && samp);
90 void PipelineState::set_vertex_setup(const VertexSetup *s)
92 set(vertex_setup, s, VERTEX_SETUP);
95 void PipelineState::set_primitive_type(PrimitiveType t)
97 set(primitive_type, t, PRIMITIVE_TYPE);
100 void PipelineState::set_front_face(FaceWinding w)
102 set(front_face, w, FACE_CULL);
105 void PipelineState::set_face_cull(CullMode c)
107 set(face_cull, c, FACE_CULL);
110 void PipelineState::set_depth_test(const DepthTest &dt)
112 set(depth_test, dt, DEPTH_TEST);
115 void PipelineState::set_stencil_test(const StencilTest &st)
117 set(stencil_test, st, STENCIL_TEST);
120 void PipelineState::set_blend(const Blend &b)
122 set(blend, b, BLEND);