]> git.tdb.fi Git - libs/gl.git/blob - source/core/pipelinestate.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / core / pipelinestate.cpp
1 #include <stdexcept>
2 #include <msp/core/algorithm.h>
3 #include "error.h"
4 #include "pipelinestate.h"
5 #include "uniformblock.h"
6
7 using namespace std;
8
9 namespace Msp {
10 namespace GL {
11
12 template<typename T>
13 void PipelineState::set(T &target, const T &value, unsigned flag)
14 {
15         if(value!=target)
16         {
17                 target = value;
18                 changes |= flag;
19         }
20 }
21
22 void PipelineState::set_framebuffer(const Framebuffer *f)
23 {
24         set(framebuffer, f, FRAMEBUFFER);
25 }
26
27 void PipelineState::set_viewport(const Rect &v)
28 {
29         set(viewport, v, VIEWPORT);
30 }
31
32 void PipelineState::set_scissor(const Rect &s)
33 {
34         set(scissor, s, SCISSOR);
35 }
36
37 void PipelineState::set_shader_program(const Program *p)
38 {
39         set(shprog, p, SHPROG);
40 }
41
42 void PipelineState::set_uniform_block(int binding, const UniformBlock *block)
43 {
44         auto i = lower_bound_member(uniform_blocks, binding, &BoundUniformBlock::binding);
45         if(i==uniform_blocks.end() || i->binding!=binding)
46                 i = uniform_blocks.insert(i, BoundUniformBlock(binding));
47         const Buffer *buffer = (block ? block->get_buffer() : 0);
48         if(block!=i->block || buffer!=i->buffer || binding<0)
49         {
50                 i->block = block;
51                 i->buffer = buffer;
52                 i->changed = true;
53                 i->used = block;
54                 changes |= UNIFORMS;
55         }
56 }
57
58 void PipelineState::set_texture(unsigned binding, const Texture *tex, const Sampler *samp)
59 {
60         set_texture(binding, tex, -1, samp);
61 }
62
63 void PipelineState::set_texture(unsigned binding, const Texture *tex, int level, const Sampler *samp)
64 {
65         if((tex!=0)!=(samp!=0))
66                 throw invalid_argument("PipelineState::set_texture");
67         if(level>=0 && !can_bind_tex_level(level))
68                 throw invalid_operation("PipelineState::set_texture");
69
70         auto i = lower_bound_member(textures, binding, &BoundTexture::binding);
71         if(i==textures.end() || i->binding!=binding)
72                 i = textures.insert(i, BoundTexture(binding));
73         if(tex!=i->texture || level!=i->level || samp!=i->sampler)
74         {
75                 i->texture = tex;
76                 i->sampler = samp;
77                 i->level = level;
78                 i->changed = true;
79                 i->used = (tex && samp);
80                 changes |= TEXTURES;
81         }
82 }
83
84 void PipelineState::set_vertex_setup(const VertexSetup *s)
85 {
86         set(vertex_setup, s, VERTEX_SETUP);
87 }
88
89 void PipelineState::set_primitive_type(PrimitiveType t)
90 {
91         set(primitive_type, t, PRIMITIVE_TYPE);
92 }
93
94 void PipelineState::set_front_face(FaceWinding w)
95 {
96         set(front_face, w, FACE_CULL);
97 }
98
99 void PipelineState::set_face_cull(CullMode c)
100 {
101         set(face_cull, c, FACE_CULL);
102 }
103
104 void PipelineState::set_depth_test(const DepthTest &dt)
105 {
106         set(depth_test, dt, DEPTH_TEST);
107 }
108
109 void PipelineState::set_stencil_test(const StencilTest &st)
110 {
111         set(stencil_test, st, STENCIL_TEST);
112 }
113
114 void PipelineState::set_blend(const Blend &b)
115 {
116         set(blend, b, BLEND);
117 }
118
119 } // namespace GL
120 } // namespace Msp