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("alpha_to_coverage", &Blend::alpha_to_coverage);
28 add("equation", &Loader::equation);
29 add("factors", &Loader::factors);
30 add("constant", &Loader::constant);
33 void Blend::Loader::constant(float r, float g, float b, float a)
35 obj.constant = Color(r, g, b, a);
38 void Blend::Loader::equation(BlendEquation eq)
44 void Blend::Loader::factors(BlendFactor sf, BlendFactor df)
52 void operator>>(const LexicalConverter &conv, BlendEquation &eq)
54 const string &str = conv.get();
57 else if(str=="SUBTRACT")
59 else if(str=="REVERSE_SUBTRACT")
60 eq = REVERSE_SUBTRACT;
66 throw lexical_error(format("conversion of '%s' to BlendEquation", str));
69 void operator<<(LexicalConverter &conv, BlendEquation eq)
73 case ADD: conv.result("ADD"); break;
74 case SUBTRACT: conv.result("SUBTRACT"); break;
75 case REVERSE_SUBTRACT: conv.result("REVERSE_SUBTRACT"); break;
76 case MIN: conv.result("MIN"); break;
77 case MAX: conv.result("MAX"); break;
78 default: conv.result(format("BlendEquation(%#x)", static_cast<int>(eq)));
82 void operator>>(const LexicalConverter &conv, BlendFactor &factor)
84 const string &str = conv.get();
89 else if(str=="SRC_COLOR")
91 else if(str=="ONE_MINUS_SRC_COLOR")
92 factor = ONE_MINUS_SRC_COLOR;
93 else if(str=="SRC_ALPHA")
95 else if(str=="ONE_MINUS_SRC_ALPHA")
96 factor = ONE_MINUS_SRC_ALPHA;
97 else if(str=="DST_COLOR")
99 else if(str=="ONE_MINUS_DST_COLOR")
100 factor = ONE_MINUS_DST_COLOR;
101 else if(str=="DST_ALPHA")
103 else if(str=="ONE_MINUS_DST_ALPHA")
104 factor = ONE_MINUS_DST_ALPHA;
105 else if(str=="CONSTANT_COLOR")
106 factor = CONSTANT_COLOR;
107 else if(str=="ONE_MINUS_CONSTANT_COLOR")
108 factor = ONE_MINUS_CONSTANT_COLOR;
109 else if(str=="CONSTANT_ALPHA")
110 factor = CONSTANT_ALPHA;
111 else if(str=="ONE_MINUS_CONSTANT_ALPHA")
112 factor = ONE_MINUS_CONSTANT_ALPHA;
114 throw lexical_error(format("conversion of '%s' to BlendFactor", str));
117 void operator<<(LexicalConverter &conv, BlendFactor factor)
121 case ZERO: conv.result("ZERO"); break;
122 case ONE: conv.result("ONE"); break;
123 case SRC_COLOR: conv.result("SRC_COLOR"); break;
124 case ONE_MINUS_SRC_COLOR: conv.result("ONE_MINUS_SRC_COLOR"); break;
125 case SRC_ALPHA: conv.result("SRC_ALPHA"); break;
126 case ONE_MINUS_SRC_ALPHA: conv.result("ONE_MINUS_SRC_ALPHA"); break;
127 case DST_COLOR: conv.result("DST_COLOR"); break;
128 case ONE_MINUS_DST_COLOR: conv.result("ONE_MINUS_DST_COLOR"); break;
129 case DST_ALPHA: conv.result("DST_ALPHA"); break;
130 case ONE_MINUS_DST_ALPHA: conv.result("ONE_MINUS_DST_ALPHA"); break;
131 case CONSTANT_COLOR: conv.result("CONSTANT_COLOR"); break;
132 case ONE_MINUS_CONSTANT_COLOR: conv.result("ONE_MINUS_CONSTANT_COLOR"); break;
133 case CONSTANT_ALPHA: conv.result("CONSTANT_ALPHA"); break;
134 case ONE_MINUS_CONSTANT_ALPHA: conv.result("ONE_MINUS_CONSTANT_ALPHA"); break;
135 default: conv.result(format("BlendFactor(%#x)", static_cast<int>(factor)));
139 void operator>>(const LexicalConverter &conv, ColorWriteMask &mask)
141 ColorWriteMask result = WRITE_NONE;
142 for(const string &p: split(conv.get(), '_'))
145 result = result|WRITE_ALL;
147 result = result|WRITE_RED;
149 result = result|WRITE_GREEN;
151 result = result|WRITE_BLUE;
153 result = result|WRITE_ALPHA;
155 throw lexical_error(format("conversion of '%s' to ColorWriteMask", conv.get()));
160 void operator<<(LexicalConverter &conv, ColorWriteMask mask)
164 else if(mask&~WRITE_ALL)
165 conv.result(format("ColorWriteMask(%#x)", static_cast<int>(mask)));
172 append(result, "_", "GREEN");
174 append(result, "_", "BLUE");
176 append(result, "_", "ALPHA");