]> git.tdb.fi Git - libs/gl.git/commitdiff
Add lexical conversions for BlendFactor and Predicate
authorMikko Rasa <tdb@tdb.fi>
Tue, 19 Dec 2017 09:12:48 +0000 (11:12 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 19 Dec 2017 09:12:48 +0000 (11:12 +0200)
source/blend.cpp
source/blend.h
source/predicate.cpp [new file with mode: 0644]
source/predicate.h

index df4043e29fcfc228a557a7a5f54238d1f302f5e2..3327885c74c1ef34b7a5c1d111f22935a8639de0 100644 (file)
@@ -1,7 +1,10 @@
 #include <msp/gl/extensions/ext_blend_minmax.h>
 #include <msp/gl/extensions/ext_blend_subtract.h>
+#include <msp/strings/format.h>
 #include "blend.h"
 
+using namespace std;
+
 namespace Msp {
 namespace GL {
 
@@ -63,5 +66,62 @@ const Blend &Blend::additive_alpha()
        return blend;
 }
 
+void operator>>(const LexicalConverter &conv, BlendFactor &factor)
+{
+       const string &str = conv.get();
+       if(str=="ZERO")
+               factor = ZERO;
+       else if(str=="ONE")
+               factor = ONE;
+       else if(str=="SRC_COLOR")
+               factor = SRC_COLOR;
+       else if(str=="ONE_MINUS_SRC_COLOR")
+               factor = ONE_MINUS_SRC_COLOR;
+       else if(str=="SRC_ALPHA")
+               factor = SRC_ALPHA;
+       else if(str=="ONE_MINUS_SRC_ALPHA")
+               factor = ONE_MINUS_SRC_ALPHA;
+       else if(str=="DST_COLOR")
+               factor = DST_COLOR;
+       else if(str=="ONE_MINUS_DST_COLOR")
+               factor = ONE_MINUS_DST_COLOR;
+       else if(str=="DST_ALPHA")
+               factor = DST_ALPHA;
+       else if(str=="ONE_MINUS_DST_ALPHA")
+               factor = ONE_MINUS_DST_ALPHA;
+       else if(str=="CONSTANT_COLOR")
+               factor = CONSTANT_COLOR;
+       else if(str=="ONE_MINUS_CONSTANT_COLOR")
+               factor = ONE_MINUS_CONSTANT_COLOR;
+       else if(str=="CONSTANT_ALPHA")
+               factor = CONSTANT_ALPHA;
+       else if(str=="ONE_MINUS_CONSTANT_ALPHA")
+               factor = ONE_MINUS_CONSTANT_ALPHA;
+       else
+               throw lexical_error(format("conversion of '%s' to BlendFactor", str));
+}
+
+void operator<<(LexicalConverter &conv, BlendFactor factor)
+{
+       switch(factor)
+       {
+       case ZERO: conv.result("ZERO"); break;
+       case ONE: conv.result("ONE"); break;
+       case SRC_COLOR: conv.result("SRC_COLOR"); break;
+       case ONE_MINUS_SRC_COLOR: conv.result("ONE_MINUS_SRC_COLOR"); break;
+       case SRC_ALPHA: conv.result("SRC_ALPHA"); break;
+       case ONE_MINUS_SRC_ALPHA: conv.result("ONE_MINUS_SRC_ALPHA"); break;
+       case DST_COLOR: conv.result("DST_COLOR"); break;
+       case ONE_MINUS_DST_COLOR: conv.result("ONE_MINUS_DST_COLOR"); break;
+       case DST_ALPHA: conv.result("DST_ALPHA"); break;
+       case ONE_MINUS_DST_ALPHA: conv.result("ONE_MINUS_DST_ALPHA"); break;
+       case CONSTANT_COLOR: conv.result("CONSTANT_COLOR"); break;
+       case ONE_MINUS_CONSTANT_COLOR: conv.result("ONE_MINUS_CONSTANT_COLOR"); break;
+       case CONSTANT_ALPHA: conv.result("CONSTANT_ALPHA"); break;
+       case ONE_MINUS_CONSTANT_ALPHA: conv.result("ONE_MINUS_CONSTANT_ALPHA"); break;
+       default: conv.result(format("BlendFactor(%#x)", static_cast<int>(factor)));
+       }
+}
+
 } // namespace GL
 } // namespace Msp
index 41567c5377266a741e112584ae373dbd0678a6c4..e7b291e617dab5c2044e787c99ee7a09a7dfcac5 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_GL_BLEND_H_
 #define MSP_GL_BLEND_H_
 
+#include <msp/strings/lexicalcast.h>
 #include "bindable.h"
 #include "gl.h"
 #include <msp/gl/extensions/ext_blend_minmax.h>
@@ -59,6 +60,9 @@ public:
        static const Blend &additive_alpha();
 };
 
+void operator>>(const LexicalConverter &, BlendFactor &);
+void operator<<(LexicalConverter &, BlendFactor);
+
 } // namespace GL
 } // namespace Msp
 
diff --git a/source/predicate.cpp b/source/predicate.cpp
new file mode 100644 (file)
index 0000000..a195373
--- /dev/null
@@ -0,0 +1,49 @@
+#include <msp/strings/format.h>
+#include "predicate.h"
+
+using namespace std;
+
+namespace Msp {
+namespace GL {
+
+void operator>>(const LexicalConverter &conv, Predicate &pred)
+{
+       const string &str = conv.get();
+       if(str=="NEVER")
+               pred = NEVER;
+       else if(str=="ALWAYS")
+               pred = ALWAYS;
+       else if(str=="LESS")
+               pred = LESS;
+       else if(str=="LEQUAL")
+               pred = LEQUAL;
+       else if(str=="EQUAL")
+               pred = EQUAL;
+       else if(str=="GREATER")
+               pred = GREATER;
+       else if(str=="GEQUAL")
+               pred = GEQUAL;
+       else if(str=="NOTEQUAL")
+               pred = NOTEQUAL;
+       else
+               throw lexical_error(format("conversion of '%s' to Predicate", str));
+}
+
+void operator<<(LexicalConverter &conv, Predicate pred)
+{
+       switch(pred)
+       {
+       case NEVER: conv.result("NEVER"); break;
+       case ALWAYS: conv.result("ALWAYS"); break;
+       case LESS: conv.result("LESS"); break;
+       case LEQUAL: conv.result("LEQUAL"); break;
+       case EQUAL: conv.result("EQUAL"); break;
+       case GREATER: conv.result("GREATER"); break;
+       case GEQUAL: conv.result("GEQUAL"); break;
+       case NOTEQUAL: conv.result("NOTEQUAL"); break;
+       default: conv.result(format("Predicate(%#x)", static_cast<int>(pred))); break;
+       }
+}
+
+} // namespace GL
+} // namespace Msp
index f7bb40d01152038e4013669c471407487fb40d64..13c22e84dc0b4300ad98bd268179aebaa8937e1d 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef MSP_GL_PREDICATE_H_
 #define MSP_GL_PREDICATE_H_
 
+#include <msp/strings/lexicalcast.h>
 #include "gl.h"
 
 namespace Msp {
@@ -18,6 +19,9 @@ enum Predicate
        NOTEQUAL = GL_NOTEQUAL
 };
 
+void operator>>(const LexicalConverter &, Predicate &);
+void operator<<(LexicalConverter &, Predicate);
+
 } // namespace GL
 } // namespace Msp