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 set_texture_resource(binding, tex, level, samp);
76 void PipelineState::set_storage_texture(unsigned binding, const Texture *tex)
78 set_texture_resource(binding, tex, 0, 0);
81 void PipelineState::set_texture_resource(unsigned binding, const Texture *tex, int level, const Sampler *samp)
83 auto i = lower_bound_member(resources, static_cast<int>(binding), &BoundResource::binding);
84 if(i==resources.end() || i->binding!=static_cast<int>(binding))
85 i = resources.insert(i, BoundResource(binding));
87 ResourceType type = (tex ? samp ? SAMPLED_TEXTURE : STORAGE_TEXTURE : NO_RESOURCE);
88 if(i->type!=type || tex!=i->texture || level!=i->mip_level || samp!=i->sampler)
100 void PipelineState::set_vertex_setup(const VertexSetup *s)
102 set(vertex_setup, s, VERTEX_SETUP);
105 void PipelineState::set_primitive_type(PrimitiveType t)
107 set(primitive_type, t, PRIMITIVE_TYPE);
110 void PipelineState::set_patch_size(unsigned s)
112 set(patch_size, s, PATCH_SIZE);
115 void PipelineState::set_front_face(FaceWinding w)
117 set(front_face, w, FACE_CULL);
120 void PipelineState::set_face_cull(CullMode c)
122 set(face_cull, c, FACE_CULL);
125 void PipelineState::set_depth_test(const DepthTest &dt)
127 set(depth_test, dt, DEPTH_TEST);
130 void PipelineState::set_stencil_test(const StencilTest &st)
132 set(stencil_test, st, STENCIL_TEST);
135 void PipelineState::set_blend(const Blend &b)
137 set(blend, b, BLEND);