]> git.tdb.fi Git - libs/gl.git/blobdiff - source/core/windingtest.cpp
Rearrange soucre files into subdirectories
[libs/gl.git] / source / core / windingtest.cpp
diff --git a/source/core/windingtest.cpp b/source/core/windingtest.cpp
new file mode 100644 (file)
index 0000000..0b8218a
--- /dev/null
@@ -0,0 +1,61 @@
+#include <msp/strings/format.h>
+#include "windingtest.h"
+
+namespace Msp {
+namespace GL {
+
+void operator>>(const LexicalConverter &conv, FaceWinding &winding)
+{
+       if(conv.get()=="CLOCKWISE")
+               winding = CLOCKWISE;
+       else if(conv.get()=="COUNTERCLOCKWISE")
+               winding = COUNTERCLOCKWISE;
+       else
+               throw lexical_error(format("conversion of '%s' to FaceWinding", conv.get()));
+}
+
+WindingTest::WindingTest():
+       winding(COUNTERCLOCKWISE)
+{ }
+
+WindingTest::WindingTest(FaceWinding w):
+       winding(w)
+{ }
+
+void WindingTest::bind() const
+{
+       if(set_current(this))
+       {
+               glEnable(GL_CULL_FACE);
+               glFrontFace(winding);
+       }
+}
+
+void WindingTest::unbind()
+{
+       if(set_current(0))
+               glDisable(GL_CULL_FACE);
+}
+
+const WindingTest &WindingTest::get_reverse() const
+{
+       if(winding==CLOCKWISE)
+               return counterclockwise();
+       else
+               return clockwise();
+}
+
+const WindingTest &WindingTest::clockwise()
+{
+       static WindingTest test(CLOCKWISE);
+       return test;
+}
+
+const WindingTest &WindingTest::counterclockwise()
+{
+       static WindingTest test(COUNTERCLOCKWISE);
+       return test;
+}
+
+} // namespace GL
+} // namespace Msp