1 #include <msp/strings/format.h>
2 #include <msp/strings/utils.h>
10 Blend::Blend(BlendFactor sf, BlendFactor df):
16 Blend::Blend(BlendEquation e, BlendFactor sf, BlendFactor df):
24 Blend::Loader::Loader(Blend &b):
25 ObjectLoader<Blend>(b)
27 add("equation", &Loader::equation);
28 add("factors", &Loader::factors);
29 add("constant", &Loader::constant);
32 void Blend::Loader::constant(float r, float g, float b, float a)
34 obj.constant = Color(r, g, b, a);
37 void Blend::Loader::equation(BlendEquation eq)
43 void Blend::Loader::factors(BlendFactor sf, BlendFactor df)
51 void operator>>(const LexicalConverter &conv, BlendEquation &eq)
53 const string &str = conv.get();
56 else if(str=="SUBTRACT")
58 else if(str=="REVERSE_SUBTRACT")
59 eq = REVERSE_SUBTRACT;
65 throw lexical_error(format("conversion of '%s' to BlendEquation", str));
68 void operator<<(LexicalConverter &conv, BlendEquation eq)
72 case ADD: conv.result("ADD"); break;
73 case SUBTRACT: conv.result("SUBTRACT"); break;
74 case REVERSE_SUBTRACT: conv.result("REVERSE_SUBTRACT"); break;
75 case MIN: conv.result("MIN"); break;
76 case MAX: conv.result("MAX"); break;
77 default: conv.result(format("BlendEquation(%#x)", static_cast<int>(eq)));
81 void operator>>(const LexicalConverter &conv, BlendFactor &factor)
83 const string &str = conv.get();
88 else if(str=="SRC_COLOR")
90 else if(str=="ONE_MINUS_SRC_COLOR")
91 factor = ONE_MINUS_SRC_COLOR;
92 else if(str=="SRC_ALPHA")
94 else if(str=="ONE_MINUS_SRC_ALPHA")
95 factor = ONE_MINUS_SRC_ALPHA;
96 else if(str=="DST_COLOR")
98 else if(str=="ONE_MINUS_DST_COLOR")
99 factor = ONE_MINUS_DST_COLOR;
100 else if(str=="DST_ALPHA")
102 else if(str=="ONE_MINUS_DST_ALPHA")
103 factor = ONE_MINUS_DST_ALPHA;
104 else if(str=="CONSTANT_COLOR")
105 factor = CONSTANT_COLOR;
106 else if(str=="ONE_MINUS_CONSTANT_COLOR")
107 factor = ONE_MINUS_CONSTANT_COLOR;
108 else if(str=="CONSTANT_ALPHA")
109 factor = CONSTANT_ALPHA;
110 else if(str=="ONE_MINUS_CONSTANT_ALPHA")
111 factor = ONE_MINUS_CONSTANT_ALPHA;
113 throw lexical_error(format("conversion of '%s' to BlendFactor", str));
116 void operator<<(LexicalConverter &conv, BlendFactor factor)
120 case ZERO: conv.result("ZERO"); break;
121 case ONE: conv.result("ONE"); break;
122 case SRC_COLOR: conv.result("SRC_COLOR"); break;
123 case ONE_MINUS_SRC_COLOR: conv.result("ONE_MINUS_SRC_COLOR"); break;
124 case SRC_ALPHA: conv.result("SRC_ALPHA"); break;
125 case ONE_MINUS_SRC_ALPHA: conv.result("ONE_MINUS_SRC_ALPHA"); break;
126 case DST_COLOR: conv.result("DST_COLOR"); break;
127 case ONE_MINUS_DST_COLOR: conv.result("ONE_MINUS_DST_COLOR"); break;
128 case DST_ALPHA: conv.result("DST_ALPHA"); break;
129 case ONE_MINUS_DST_ALPHA: conv.result("ONE_MINUS_DST_ALPHA"); break;
130 case CONSTANT_COLOR: conv.result("CONSTANT_COLOR"); break;
131 case ONE_MINUS_CONSTANT_COLOR: conv.result("ONE_MINUS_CONSTANT_COLOR"); break;
132 case CONSTANT_ALPHA: conv.result("CONSTANT_ALPHA"); break;
133 case ONE_MINUS_CONSTANT_ALPHA: conv.result("ONE_MINUS_CONSTANT_ALPHA"); break;
134 default: conv.result(format("BlendFactor(%#x)", static_cast<int>(factor)));
138 void operator>>(const LexicalConverter &conv, ColorWriteMask &mask)
140 ColorWriteMask result = WRITE_NONE;
141 for(const string &p: split(conv.get(), '_'))
144 result = result|WRITE_ALL;
146 result = result|WRITE_RED;
148 result = result|WRITE_GREEN;
150 result = result|WRITE_BLUE;
152 result = result|WRITE_ALPHA;
154 throw lexical_error(format("conversion of '%s' to ColorWriteMask", conv.get()));
159 void operator<<(LexicalConverter &conv, ColorWriteMask mask)
163 else if(mask&~WRITE_ALL)
164 conv.result(format("ColorWriteMask(%#x)", static_cast<int>(mask)));
171 append(result, "_", "GREEN");
173 append(result, "_", "BLUE");
175 append(result, "_", "ALPHA");