1 #include <msp/gl/extensions/ext_blend_minmax.h>
2 #include <msp/gl/extensions/ext_blend_subtract.h>
3 #include <msp/strings/format.h>
17 Blend::Blend(BlendFactor sf, BlendFactor df):
23 Blend::Blend(BlendEquation e, BlendFactor sf, BlendFactor df):
28 if(eq==MIN || eq==MAX)
29 static Require _req(EXT_blend_minmax);
30 else if(eq==SUBTRACT || eq==REVERSE_SUBTRACT)
31 static Require _req(EXT_blend_subtract);
34 void Blend::bind() const
41 glBlendFunc(src_factor, dst_factor);
51 const Blend &Blend::alpha()
53 static Blend blend(SRC_ALPHA, ONE_MINUS_SRC_ALPHA);
57 const Blend &Blend::additive()
59 static Blend blend(ONE, ONE);
63 const Blend &Blend::additive_alpha()
65 static Blend blend(SRC_ALPHA, ONE);
69 void operator>>(const LexicalConverter &conv, BlendFactor &factor)
71 const string &str = conv.get();
76 else if(str=="SRC_COLOR")
78 else if(str=="ONE_MINUS_SRC_COLOR")
79 factor = ONE_MINUS_SRC_COLOR;
80 else if(str=="SRC_ALPHA")
82 else if(str=="ONE_MINUS_SRC_ALPHA")
83 factor = ONE_MINUS_SRC_ALPHA;
84 else if(str=="DST_COLOR")
86 else if(str=="ONE_MINUS_DST_COLOR")
87 factor = ONE_MINUS_DST_COLOR;
88 else if(str=="DST_ALPHA")
90 else if(str=="ONE_MINUS_DST_ALPHA")
91 factor = ONE_MINUS_DST_ALPHA;
92 else if(str=="CONSTANT_COLOR")
93 factor = CONSTANT_COLOR;
94 else if(str=="ONE_MINUS_CONSTANT_COLOR")
95 factor = ONE_MINUS_CONSTANT_COLOR;
96 else if(str=="CONSTANT_ALPHA")
97 factor = CONSTANT_ALPHA;
98 else if(str=="ONE_MINUS_CONSTANT_ALPHA")
99 factor = ONE_MINUS_CONSTANT_ALPHA;
101 throw lexical_error(format("conversion of '%s' to BlendFactor", str));
104 void operator<<(LexicalConverter &conv, BlendFactor factor)
108 case ZERO: conv.result("ZERO"); break;
109 case ONE: conv.result("ONE"); break;
110 case SRC_COLOR: conv.result("SRC_COLOR"); break;
111 case ONE_MINUS_SRC_COLOR: conv.result("ONE_MINUS_SRC_COLOR"); break;
112 case SRC_ALPHA: conv.result("SRC_ALPHA"); break;
113 case ONE_MINUS_SRC_ALPHA: conv.result("ONE_MINUS_SRC_ALPHA"); break;
114 case DST_COLOR: conv.result("DST_COLOR"); break;
115 case ONE_MINUS_DST_COLOR: conv.result("ONE_MINUS_DST_COLOR"); break;
116 case DST_ALPHA: conv.result("DST_ALPHA"); break;
117 case ONE_MINUS_DST_ALPHA: conv.result("ONE_MINUS_DST_ALPHA"); break;
118 case CONSTANT_COLOR: conv.result("CONSTANT_COLOR"); break;
119 case ONE_MINUS_CONSTANT_COLOR: conv.result("ONE_MINUS_CONSTANT_COLOR"); break;
120 case CONSTANT_ALPHA: conv.result("CONSTANT_ALPHA"); break;
121 case ONE_MINUS_CONSTANT_ALPHA: conv.result("ONE_MINUS_CONSTANT_ALPHA"); break;
122 default: conv.result(format("BlendFactor(%#x)", static_cast<int>(factor)));