1 #include <msp/strings/format.h>
2 #include <msp/strings/utils.h>
15 constant(0.0f, 0.0f, 0.0f, 0.0f),
19 Blend::Blend(BlendFactor sf, BlendFactor df):
24 constant(0.0f, 0.0f, 0.0f, 0.0f),
28 Blend::Blend(BlendEquation e, BlendFactor sf, BlendFactor df):
33 constant(0.0f, 0.0f, 0.0f, 0.0f),
38 Blend::Loader::Loader(Blend &b):
39 ObjectLoader<Blend>(b)
41 add("equation", &Loader::equation);
42 add("factors", &Loader::factors);
43 add("constant", &Loader::constant);
46 void Blend::Loader::constant(float r, float g, float b, float a)
48 obj.constant = Color(r, g, b, a);
51 void Blend::Loader::equation(BlendEquation eq)
57 void Blend::Loader::factors(BlendFactor sf, BlendFactor df)
65 void operator>>(const LexicalConverter &conv, BlendEquation &eq)
67 const string &str = conv.get();
70 else if(str=="SUBTRACT")
72 else if(str=="REVERSE_SUBTRACT")
73 eq = REVERSE_SUBTRACT;
79 throw lexical_error(format("conversion of '%s' to BlendEquation", str));
82 void operator<<(LexicalConverter &conv, BlendEquation eq)
86 case ADD: conv.result("ADD"); break;
87 case SUBTRACT: conv.result("SUBTRACT"); break;
88 case REVERSE_SUBTRACT: conv.result("REVERSE_SUBTRACT"); break;
89 case MIN: conv.result("MIN"); break;
90 case MAX: conv.result("MAX"); break;
91 default: conv.result(format("BlendEquation(%#x)", static_cast<int>(eq)));
95 void operator>>(const LexicalConverter &conv, BlendFactor &factor)
97 const string &str = conv.get();
102 else if(str=="SRC_COLOR")
104 else if(str=="ONE_MINUS_SRC_COLOR")
105 factor = ONE_MINUS_SRC_COLOR;
106 else if(str=="SRC_ALPHA")
108 else if(str=="ONE_MINUS_SRC_ALPHA")
109 factor = ONE_MINUS_SRC_ALPHA;
110 else if(str=="DST_COLOR")
112 else if(str=="ONE_MINUS_DST_COLOR")
113 factor = ONE_MINUS_DST_COLOR;
114 else if(str=="DST_ALPHA")
116 else if(str=="ONE_MINUS_DST_ALPHA")
117 factor = ONE_MINUS_DST_ALPHA;
118 else if(str=="CONSTANT_COLOR")
119 factor = CONSTANT_COLOR;
120 else if(str=="ONE_MINUS_CONSTANT_COLOR")
121 factor = ONE_MINUS_CONSTANT_COLOR;
122 else if(str=="CONSTANT_ALPHA")
123 factor = CONSTANT_ALPHA;
124 else if(str=="ONE_MINUS_CONSTANT_ALPHA")
125 factor = ONE_MINUS_CONSTANT_ALPHA;
127 throw lexical_error(format("conversion of '%s' to BlendFactor", str));
130 void operator<<(LexicalConverter &conv, BlendFactor factor)
134 case ZERO: conv.result("ZERO"); break;
135 case ONE: conv.result("ONE"); break;
136 case SRC_COLOR: conv.result("SRC_COLOR"); break;
137 case ONE_MINUS_SRC_COLOR: conv.result("ONE_MINUS_SRC_COLOR"); break;
138 case SRC_ALPHA: conv.result("SRC_ALPHA"); break;
139 case ONE_MINUS_SRC_ALPHA: conv.result("ONE_MINUS_SRC_ALPHA"); break;
140 case DST_COLOR: conv.result("DST_COLOR"); break;
141 case ONE_MINUS_DST_COLOR: conv.result("ONE_MINUS_DST_COLOR"); break;
142 case DST_ALPHA: conv.result("DST_ALPHA"); break;
143 case ONE_MINUS_DST_ALPHA: conv.result("ONE_MINUS_DST_ALPHA"); break;
144 case CONSTANT_COLOR: conv.result("CONSTANT_COLOR"); break;
145 case ONE_MINUS_CONSTANT_COLOR: conv.result("ONE_MINUS_CONSTANT_COLOR"); break;
146 case CONSTANT_ALPHA: conv.result("CONSTANT_ALPHA"); break;
147 case ONE_MINUS_CONSTANT_ALPHA: conv.result("ONE_MINUS_CONSTANT_ALPHA"); break;
148 default: conv.result(format("BlendFactor(%#x)", static_cast<int>(factor)));
152 void operator>>(const LexicalConverter &conv, ColorWriteMask &mask)
154 ColorWriteMask result = WRITE_NONE;
155 for(const string &p: split(conv.get(), '_'))
158 result = result|WRITE_ALL;
160 result = result|WRITE_RED;
162 result = result|WRITE_GREEN;
164 result = result|WRITE_BLUE;
166 result = result|WRITE_ALPHA;
168 throw lexical_error(format("conversion of '%s' to ColorWriteMask", conv.get()));
173 void operator<<(LexicalConverter &conv, ColorWriteMask mask)
177 else if(mask&~WRITE_ALL)
178 conv.result(format("ColorWriteMask(%#x)", static_cast<int>(mask)));
185 append(result, "_", "GREEN");
187 append(result, "_", "BLUE");
189 append(result, "_", "ALPHA");